Skip to content

Commit c72eea5

Browse files
committed
Retry synced-flush in FullClusterRestartIT#testRecovery
Today we examine the response of a synced-flush, then issue another request if the current one is not entirely successful. However, this approach is not correct as method #performRequest throws ResponseException for a partial result. Closes #31530
1 parent e15bedf commit c72eea5

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.Version;
2727
import org.elasticsearch.client.Request;
2828
import org.elasticsearch.client.Response;
29+
import org.elasticsearch.client.ResponseException;
2930
import org.elasticsearch.cluster.metadata.IndexMetaData;
3031
import org.elasticsearch.common.Booleans;
3132
import org.elasticsearch.common.CheckedFunction;
@@ -720,11 +721,14 @@ public void testRecovery() throws Exception {
720721
// We have to spin synced-flush requests here because we fire the global checkpoint sync for the last write operation.
721722
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
722723
assertBusy(() -> {
723-
Response resp = client().performRequest(new Request("POST", index + "/_flush/synced"));
724-
assertOK(resp);
725-
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
726-
assertThat(result.get("successful"), equalTo(result.get("total")));
727-
assertThat(result.get("failed"), equalTo(0));
724+
try {
725+
Response resp = client().performRequest(new Request("POST", index + "/_flush/synced"));
726+
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
727+
assertThat(result.get("successful"), equalTo(result.get("total")));
728+
assertThat(result.get("failed"), equalTo(0));
729+
} catch (ResponseException ex) {
730+
throw new AssertionError(ex); // cause assert busy to retry
731+
}
728732
});
729733
} else {
730734
// Explicitly flush so we're sure to have a bunch of documents in the Lucene index

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.action.support.PlainActionFuture;
2525
import org.elasticsearch.client.Request;
2626
import org.elasticsearch.client.Response;
27+
import org.elasticsearch.client.ResponseException;
2728
import org.elasticsearch.cluster.metadata.IndexMetaData;
2829
import org.elasticsearch.common.settings.Settings;
2930
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
@@ -303,10 +304,14 @@ public void testRecoverSyncedFlushIndex() throws Exception {
303304
// We have to spin synced-flush requests here because we fire the global checkpoint sync for the last write operation.
304305
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
305306
assertBusy(() -> {
306-
Response resp = client().performRequest(new Request("POST", index + "/_flush/synced"));
307-
assertOK(resp);
308-
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
309-
assertThat(result.get("successful"), equalTo(2));
307+
try {
308+
Response resp = client().performRequest(new Request("POST", index + "/_flush/synced"));
309+
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
310+
assertThat(result.get("successful"), equalTo(result.get("total")));
311+
assertThat(result.get("failed"), equalTo(0));
312+
} catch (ResponseException ex) {
313+
throw new AssertionError(ex); // cause assert busy to retry
314+
}
310315
});
311316
}
312317
ensureGreen(index);

0 commit comments

Comments
 (0)