Skip to content

Commit 2ac0ea8

Browse files
Retry in SnapshotIT Snapshot Abort
Retry here to work around the possible race between snapshot finalization and deletion. Closes elastic#53509
1 parent ddd068a commit 2ac0ea8

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void testCleanupRepository() throws IOException {
146146
assertThat(response.result().blobs(), equalTo(0L));
147147
}
148148

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

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

0 commit comments

Comments
 (0)