Skip to content

Commit 32d0bb8

Browse files
Retry in SnapshotIT Snapshot Abort (#54195) (#54249)
Retry here to work around the possible race between snapshot finalization and deletion. Closes #53509
1 parent ff26916 commit 32d0bb8

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
@@ -148,7 +148,7 @@ public void testCleanupRepository() throws IOException {
148148
assertThat(response.result().blobs(), equalTo(0L));
149149
}
150150

151-
public void testCreateSnapshot() throws IOException {
151+
public void testCreateSnapshot() throws Exception {
152152
String repository = "test_repository";
153153
assertTrue(createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
154154

@@ -165,12 +165,23 @@ public void testCreateSnapshot() throws IOException {
165165
CreateSnapshotResponse response = createTestSnapshot(request);
166166
assertEquals(waitForCompletion ? RestStatus.OK : RestStatus.ACCEPTED, response.status());
167167
if (waitForCompletion == false) {
168-
// If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
169-
AcknowledgedResponse deleteResponse = execute(
170-
new DeleteSnapshotRequest(repository, snapshot),
171-
highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync
172-
);
173-
assertTrue(deleteResponse.isAcknowledged());
168+
// busy assert on the delete because a known race condition could cause the delete request to not see
169+
// the snapshot if delete and snapshot finalization happen at the same time
170+
// See https://github.com/elastic/elasticsearch/issues/53509#issuecomment-603899620 for details
171+
// TODO: Remove busy assert in 7.x+ once this race is fixed
172+
assertBusy(() -> {
173+
// If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
174+
AcknowledgedResponse deleteResponse;
175+
try {
176+
deleteResponse = execute(
177+
new DeleteSnapshotRequest(repository, snapshot),
178+
highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync
179+
);
180+
} catch (Exception e) {
181+
throw new AssertionError(e);
182+
}
183+
assertTrue(deleteResponse.isAcknowledged());
184+
});
174185
}
175186
}
176187

0 commit comments

Comments
 (0)