Skip to content

Commit 5021410

Browse files
authored
Retry on RepositoryException in SLM tests (#48548)
Due to a bug, GETing a snapshot can cause a RespositoryException to be thrown. This error is transient and should be retried, rather than causing the test to fail. This commit converts those RepositoryExceptions into AssertionErrors so that they will be retried in code wrapped in assertBusy.
1 parent 13ce179 commit 5021410

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ private void assertSnapshotExists(final RestHighLevelClient client, final String
10561056
} catch (Exception e) {
10571057
if (e.getMessage().contains("snapshot_missing_exception")) {
10581058
fail("snapshot does not exist: " + snapshotName);
1059+
} else if (e.getMessage().contains("repository_exception")) {
1060+
fail("got a respository_exception, retrying. original message: " + e.getMessage());
10591061
}
10601062
throw e;
10611063
}

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.index.query.QueryBuilders;
2222
import org.elasticsearch.plugins.Plugin;
2323
import org.elasticsearch.repositories.RepositoriesService;
24+
import org.elasticsearch.repositories.RepositoryException;
2425
import org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException;
2526
import org.elasticsearch.snapshots.SnapshotInfo;
2627
import org.elasticsearch.snapshots.SnapshotMissingException;
@@ -176,8 +177,7 @@ public void testRetentionWhileSnapshotInProgress() throws Exception {
176177
logger.info("--> kicked off snapshot {}", completedSnapshotName);
177178
assertBusy(() -> {
178179
try {
179-
SnapshotsStatusResponse s =
180-
client().admin().cluster().prepareSnapshotStatus(REPO).setSnapshots(completedSnapshotName).get();
180+
SnapshotsStatusResponse s = getSnapshotStatus(completedSnapshotName);
181181
assertThat("expected a snapshot but none were returned", s.getSnapshots().size(), equalTo(1));
182182
SnapshotStatus status = s.getSnapshots().get(0);
183183
logger.info("--> waiting for snapshot {} to be completed, got: {}", completedSnapshotName, status.getState());
@@ -245,8 +245,7 @@ public void testRetentionWhileSnapshotInProgress() throws Exception {
245245
client().admin().cluster().prepareReroute().get();
246246
logger.info("--> waiting for snapshot to be deleted");
247247
try {
248-
SnapshotsStatusResponse s =
249-
client().admin().cluster().prepareSnapshotStatus(REPO).setSnapshots(completedSnapshotName).get();
248+
SnapshotsStatusResponse s = getSnapshotStatus(completedSnapshotName);
250249
assertNull("expected no snapshot but one was returned", s.getSnapshots().get(0));
251250
} catch (SnapshotMissingException e) {
252251
// Great, we wanted it to be deleted!
@@ -406,6 +405,18 @@ private void testUnsuccessfulSnapshotRetention(boolean partialSuccess) throws Ex
406405
}
407406
}
408407

408+
private SnapshotsStatusResponse getSnapshotStatus(String snapshotName) {
409+
try {
410+
return client().admin().cluster().prepareSnapshotStatus(REPO).setSnapshots(snapshotName).get();
411+
} catch (RepositoryException e) {
412+
// Convert this to an AssertionError so that it can be retried in an assertBusy - this is often a transient error because
413+
// concurrent status calls and write operations may lead to failures in determining the current repository generation
414+
// TODO: Remove this hack once tracking the current repository generation has been made consistent
415+
logger.warn(e);
416+
throw new AssertionError(e);
417+
}
418+
}
419+
409420
private void createAndPopulateIndex(String indexName) throws InterruptedException {
410421
logger.info("--> creating and populating index [{}]", indexName);
411422
assertAcked(prepareCreate(indexName, 0, Settings.builder()

0 commit comments

Comments
 (0)