diff --git a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java index 318672fbc934e..6a7a094de9886 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -907,9 +907,6 @@ public void endVerification(String seed) { public RepositoryData getRepositoryData() { try { return getRepositoryData(latestIndexBlobId()); - } catch (NoSuchFileException ex) { - // repository doesn't have an index blob, its a new blank repo - return RepositoryData.EMPTY; } catch (IOException ioe) { throw new RepositoryException(metadata.name(), "Could not determine repository generation from root blobs", ioe); } @@ -922,17 +919,12 @@ private RepositoryData getRepositoryData(long indexGen) { try { final String snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long.toString(indexGen); - RepositoryData repositoryData; // EMPTY is safe here because RepositoryData#fromXContent calls namedObject try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName); XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, blob)) { - repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); + return RepositoryData.snapshotsFromXContent(parser, indexGen); } - return repositoryData; - } catch (NoSuchFileException ex) { - // repository doesn't have an index blob, its a new blank repo - return RepositoryData.EMPTY; } catch (IOException ioe) { throw new RepositoryException(metadata.name(), "could not read repository data from index blob", ioe); } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java index 51ab9e0a7909a..f37a067d3a19c 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java @@ -390,18 +390,24 @@ private void testUnsuccessfulSnapshotRetention(boolean partialSuccess) throws Ex logger.info("--> waiting for {} snapshot [{}] to be deleted", expectedUnsuccessfulState, failedSnapshotName.get()); assertBusy(() -> { try { + try { + GetSnapshotsResponse snapshotsStatusResponse = client().admin().cluster() + .prepareGetSnapshots(REPO).setSnapshots(failedSnapshotName.get()).get(); + assertThat(snapshotsStatusResponse.getSnapshots(), empty()); + } catch (SnapshotMissingException e) { + // This is what we want to happen + } + logger.info("--> {} snapshot [{}] has been deleted, checking successful snapshot [{}] still exists", + expectedUnsuccessfulState, failedSnapshotName.get(), successfulSnapshotName.get()); GetSnapshotsResponse snapshotsStatusResponse = client().admin().cluster() - .prepareGetSnapshots(REPO).setSnapshots(failedSnapshotName.get()).get(); - assertThat(snapshotsStatusResponse.getSnapshots(), empty()); - } catch (SnapshotMissingException e) { - // This is what we want to happen + .prepareGetSnapshots(REPO).setSnapshots(successfulSnapshotName.get()).get(); + SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0); + assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); + } catch (RepositoryException re) { + // Concurrent status calls and write operations may lead to failures in determining the current repository generation + // TODO: Remove this hack once tracking the current repository generation has been made consistent + throw new AssertionError(re); } - logger.info("--> {} snapshot [{}] has been deleted, checking successful snapshot [{}] still exists", - expectedUnsuccessfulState, failedSnapshotName.get(), successfulSnapshotName.get()); - GetSnapshotsResponse snapshotsStatusResponse = client().admin().cluster() - .prepareGetSnapshots(REPO).setSnapshots(successfulSnapshotName.get()).get(); - SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0); - assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); }); } }