diff --git a/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index fac582903c3..c9c621107ba 100644 --- a/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -323,6 +323,12 @@ public class SnapshotsService extends AbstractLifecycleComponentof()); + } catch (Throwable t2) { + logger.warn("[{}] failed to close snapshot in repository", snapshot.snapshotId()); + } userCreateSnapshotListener.onFailure(t); } @@ -345,28 +351,7 @@ public class SnapshotsService extends AbstractLifecycleComponent entries = ImmutableList.builder(); - for (SnapshotMetaData.Entry entry : snapshots.entries()) { - if (!entry.snapshotId().equals(snapshot.snapshotId())) { - entries.add(entry); - } - } - mdBuilder.putCustom(SnapshotMetaData.TYPE, new SnapshotMetaData(entries.build())); - return ClusterState.builder(currentState).metaData(mdBuilder).build(); - } - - @Override - public void onFailure(String source, Throwable t) { - logger.warn("[{}] failed to delete snapshot", t, snapshot.snapshotId()); - } - }); + removeSnapshotFromClusterState(snapshot.snapshotId(), null, t); if (snapshotCreated) { try { repositoriesService.repository(snapshot.snapshotId().getRepository()).finalizeSnapshot(snapshot.snapshotId(), ExceptionsHelper.detailedMessage(t), 0, ImmutableList.of()); @@ -1046,7 +1031,7 @@ public class SnapshotsService extends AbstractLifecycleComponent creating repository"); + assertAcked(client.admin().cluster().preparePutRepository("test-repo") + .setType("fs").setSettings(ImmutableSettings.settingsBuilder() + .put("location", newTempDir(LifecycleScope.SUITE)))); + + createIndex("test-idx"); + ensureGreen(); + logger.info("--> closing index test-idx"); + assertAcked(client.admin().indices().prepareClose("test-idx")); + + logger.info("--> snapshot"); + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1") + .setWaitForCompletion(true).setIndices("test-idx").get(); + assertThat(createSnapshotResponse.getSnapshotInfo().indices().size(), equalTo(1)); + assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.FAILED)); + } + @Test public void renameOnRestoreTest() throws Exception { Client client = client();