Skip to content

Commit a15c4b3

Browse files
committed
Delete temporary blobs before creating index file
1 parent fc870fd commit a15c4b3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,14 +950,28 @@ protected void finalize(final List<SnapshotFiles> snapshots,
950950

951951
final BlobStoreIndexShardSnapshots updatedSnapshots = new BlobStoreIndexShardSnapshots(snapshots);
952952
try {
953+
// Delete temporary index files first, as we might otherwise fail in the next step creating the new index file if an earlier
954+
// attempt to write an index file with this generation failed mid-way after creating the temporary file.
955+
for (final String blobName : blobs.keySet()) {
956+
if (indexShardSnapshotsFormat.isTempBlobName(blobName)) {
957+
try {
958+
blobContainer.deleteBlobIgnoringIfNotExists(blobName);
959+
} catch (IOException e) {
960+
logger.warn(() -> new ParameterizedMessage("[{}][{}] failed to delete index blob [{}] during finalization",
961+
snapshotId, shardId, blobName), e);
962+
throw e;
963+
}
964+
}
965+
}
966+
953967
// If we deleted all snapshots, we don't need to create a new index file
954968
if (snapshots.size() > 0) {
955969
indexShardSnapshotsFormat.writeAtomic(updatedSnapshots, blobContainer, indexGeneration);
956970
}
957971

958972
// Delete old index files
959973
for (final String blobName : blobs.keySet()) {
960-
if (indexShardSnapshotsFormat.isTempBlobName(blobName) || blobName.startsWith(SNAPSHOT_INDEX_PREFIX)) {
974+
if (blobName.startsWith(SNAPSHOT_INDEX_PREFIX)) {
961975
try {
962976
blobContainer.deleteBlobIgnoringIfNotExists(blobName);
963977
} catch (IOException e) {

server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,6 @@ public void testSnapshotCanceledOnRemovedShard() throws Exception {
30943094
assertEquals("IndexShardSnapshotFailedException[Aborted]", snapshotInfo.shardFailures().get(0).reason());
30953095
}
30963096

3097-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/30507")
30983097
public void testSnapshotSucceedsAfterSnapshotFailure() throws Exception {
30993098
logger.info("--> creating repository");
31003099
final Path repoPath = randomRepoPath();

0 commit comments

Comments
 (0)