Skip to content

Commit bbdeb65

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 95c073a commit bbdeb65

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.http.util.EntityUtils;
2626
import org.elasticsearch.Version;
2727
import org.elasticsearch.client.Response;
28+
import org.elasticsearch.client.ResponseException;
2829
import org.elasticsearch.cluster.metadata.IndexMetaData;
2930
import org.elasticsearch.common.Booleans;
3031
import org.elasticsearch.common.CheckedFunction;
@@ -699,7 +700,6 @@ public void testEmptyShard() throws IOException {
699700
* Tests recovery of an index with or without a translog and the
700701
* statistics we gather about that.
701702
*/
702-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/31530")
703703
public void testRecovery() throws Exception {
704704
int count;
705705
boolean shouldHaveTranslog;
@@ -719,11 +719,14 @@ public void testRecovery() throws Exception {
719719
// We have to spin synced-flush requests here because we fire the global checkpoint sync for the last write operation.
720720
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
721721
assertBusy(() -> {
722-
Response resp = client().performRequest("POST", index + "/_flush/synced");
723-
assertOK(resp);
724-
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
725-
assertThat(result.get("successful"), equalTo(result.get("total")));
726-
assertThat(result.get("failed"), equalTo(0));
722+
try {
723+
Response resp = client().performRequest("POST", index + "/_flush/synced");
724+
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
725+
assertThat(result.get("successful"), equalTo(result.get("total")));
726+
assertThat(result.get("failed"), equalTo(0));
727+
} catch (ResponseException ex) {
728+
throw new AssertionError(ex); // cause assert busy to retry
729+
}
727730
});
728731
} else {
729732
// 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
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.Version;
2424
import org.elasticsearch.action.support.PlainActionFuture;
2525
import org.elasticsearch.client.Response;
26+
import org.elasticsearch.client.ResponseException;
2627
import org.elasticsearch.cluster.metadata.IndexMetaData;
2728
import org.elasticsearch.common.settings.Settings;
2829
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
@@ -300,10 +301,14 @@ public void testRecoverSyncedFlushIndex() throws Exception {
300301
// We have to spin synced-flush requests here because we fire the global checkpoint sync for the last write operation.
301302
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
302303
assertBusy(() -> {
303-
Response resp = client().performRequest("POST", index + "/_flush/synced");
304-
assertOK(resp);
305-
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
306-
assertThat(result.get("successful"), equalTo(2));
304+
try {
305+
Response resp = client().performRequest("POST", index + "/_flush/synced");
306+
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
307+
assertThat(result.get("successful"), equalTo(result.get("total")));
308+
assertThat(result.get("failed"), equalTo(0));
309+
} catch (ResponseException ex) {
310+
throw new AssertionError(ex); // cause assert busy to retry
311+
}
307312
});
308313
}
309314
ensureGreen(index);

0 commit comments

Comments
 (0)