Skip to content

Commit 4008af3

Browse files
Retry in SnapshotIT Snapshot Abort (#54195) (#54251)
Retry here to work around the possible race between snapshot finalization and deletion. Closes #53509
1 parent a71e80d commit 4008af3

File tree

1 file changed

+18
-7
lines changed
  • client/rest-high-level/src/test/java/org/elasticsearch/client

1 file changed

+18
-7
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotIT.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void testVerifyRepository() throws IOException {
131131
assertThat(response.getNodes().size(), equalTo(1));
132132
}
133133

134-
public void testCreateSnapshot() throws IOException {
134+
public void testCreateSnapshot() throws Exception {
135135
String repository = "test_repository";
136136
assertTrue(createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
137137

@@ -145,12 +145,23 @@ public void testCreateSnapshot() throws IOException {
145145
CreateSnapshotResponse response = createTestSnapshot(request);
146146
assertEquals(waitForCompletion ? RestStatus.OK : RestStatus.ACCEPTED, response.status());
147147
if (waitForCompletion == false) {
148-
// If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
149-
AcknowledgedResponse deleteResponse = execute(
150-
new DeleteSnapshotRequest(repository, snapshot),
151-
highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync
152-
);
153-
assertTrue(deleteResponse.isAcknowledged());
148+
// busy assert on the delete because a known race condition could cause the delete request to not see
149+
// the snapshot if delete and snapshot finalization happen at the same time
150+
// See https://github.com/elastic/elasticsearch/issues/53509#issuecomment-603899620 for details
151+
// TODO: Remove busy assert in 7.x+ once this race is fixed
152+
assertBusy(() -> {
153+
// If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
154+
AcknowledgedResponse deleteResponse;
155+
try {
156+
deleteResponse = execute(
157+
new DeleteSnapshotRequest(repository, snapshot),
158+
highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync
159+
);
160+
} catch (Exception e) {
161+
throw new AssertionError(e);
162+
}
163+
assertTrue(deleteResponse.isAcknowledged());
164+
});
154165
}
155166
}
156167

0 commit comments

Comments
 (0)