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 f5d17eca036..e4ba20e37d0 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -1080,12 +1080,6 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp BlobStoreIndexShardSnapshots snapshots = tuple.v1(); long fileListGeneration = tuple.v2(); - try { - indexShardSnapshotFormat.delete(shardContainer, snapshotId.getUUID()); - } catch (IOException e) { - logger.warn(new ParameterizedMessage("[{}] [{}] failed to delete shard snapshot file", snapshotShardId, snapshotId), e); - } - // Build a list of snapshots that should be preserved List newSnapshotsList = new ArrayList<>(); for (SnapshotFiles point : snapshots) { @@ -1096,6 +1090,12 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp // finalize the snapshot and rewrite the snapshot index with the next sequential snapshot index finalizeShard(newSnapshotsList, fileListGeneration, blobs, "snapshot deletion [" + snapshotId + "]", shardContainer, snapshotShardId, snapshotId); + + try { + shardContainer.deleteBlobIgnoringIfNotExists(indexShardSnapshotFormat.blobName(snapshotId.getUUID())); + } catch (IOException e) { + logger.warn(new ParameterizedMessage("[{}] [{}] failed to delete shard snapshot file", snapshotShardId, snapshotId), e); + } } /**