Skip to content

Commit 662008c

Browse files
author
Ali Beyad
committed
Improves snapshot logging and snapshoth deletion error handling (#25264)
This commit does two things: 1. Adds logging at the DEBUG level for when the index-N blob is updated. 2. When attempting to delete a snapshot, if the snapshot was not found in the repository data, an exception is now thrown instead of silently ignoring the lack of presence of the snapshot in the repository data.
1 parent ca5ad31 commit 662008c

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

core/src/main/java/org/elasticsearch/repositories/RepositoryData.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.repositories;
2121

2222
import org.elasticsearch.ElasticsearchParseException;
23+
import org.elasticsearch.ResourceNotFoundException;
2324
import org.elasticsearch.common.Nullable;
2425
import org.elasticsearch.common.UUIDs;
2526
import org.elasticsearch.common.xcontent.ToXContent;
@@ -190,8 +191,11 @@ public RepositoryData addSnapshot(final SnapshotId snapshotId,
190191
*/
191192
public RepositoryData removeSnapshot(final SnapshotId snapshotId) {
192193
Map<String, SnapshotId> newSnapshotIds = snapshotIds.values().stream()
193-
.filter(id -> snapshotId.equals(id) == false)
194+
.filter(id -> !snapshotId.equals(id))
194195
.collect(Collectors.toMap(SnapshotId::getUUID, Function.identity()));
196+
if (newSnapshotIds.size() == snapshotIds.size()) {
197+
throw new ResourceNotFoundException("Attempting to remove non-existent snapshot [{}] from repository data", snapshotId);
198+
}
195199
Map<String, SnapshotState> newSnapshotStates = new HashMap<>(snapshotStates);
196200
newSnapshotStates.remove(snapshotId.getUUID());
197201
Map<IndexId, Set<SnapshotId>> indexSnapshots = new HashMap<>();

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.lucene.util.IOUtils;
3939
import org.elasticsearch.ElasticsearchParseException;
4040
import org.elasticsearch.ExceptionsHelper;
41+
import org.elasticsearch.ResourceNotFoundException;
4142
import org.elasticsearch.Version;
4243
import org.elasticsearch.cluster.SnapshotsInProgress;
4344
import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -489,8 +490,8 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) {
489490
"its index folder.", metadata.name(), indexId), ioe);
490491
}
491492
}
492-
} catch (IOException ex) {
493-
throw new RepositoryException(metadata.name(), "failed to update snapshot in repository", ex);
493+
} catch (IOException | ResourceNotFoundException ex) {
494+
throw new RepositoryException(metadata.name(), "failed to delete snapshot [" + snapshotId + "]", ex);
494495
}
495496
}
496497

@@ -836,7 +837,9 @@ protected void writeIndexGen(final RepositoryData repositoryData, final long rep
836837
snapshotsBytes = bStream.bytes();
837838
}
838839
// write the index file
839-
writeAtomic(INDEX_FILE_PREFIX + Long.toString(newGen), snapshotsBytes);
840+
final String indexBlob = INDEX_FILE_PREFIX + Long.toString(newGen);
841+
logger.debug("Repository [{}] writing new index generational blob [{}]", metadata.name(), indexBlob);
842+
writeAtomic(indexBlob, snapshotsBytes);
840843
// delete the N-2 index file if it exists, keep the previous one around as a backup
841844
if (isReadOnly() == false && newGen - 2 >= 0) {
842845
final String oldSnapshotIndexFile = INDEX_FILE_PREFIX + Long.toString(newGen - 2);
@@ -854,6 +857,7 @@ protected void writeIndexGen(final RepositoryData repositoryData, final long rep
854857
if (snapshotsBlobContainer.blobExists(INDEX_LATEST_BLOB)) {
855858
snapshotsBlobContainer.deleteBlob(INDEX_LATEST_BLOB);
856859
}
860+
logger.debug("Repository [{}] updating index.latest with generation [{}]", metadata.name(), newGen);
857861
writeAtomic(INDEX_LATEST_BLOB, genBytes);
858862
}
859863

core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
11801180
@Override
11811181
public void onSnapshotCompletion(Snapshot completedSnapshot, SnapshotInfo snapshotInfo) {
11821182
if (completedSnapshot.equals(snapshot)) {
1183-
logger.trace("deleted snapshot completed - deleting files");
1183+
logger.debug("deleted snapshot completed - deleting files");
11841184
removeListener(this);
11851185
threadPool.executor(ThreadPool.Names.SNAPSHOT).execute(() ->
11861186
deleteSnapshot(completedSnapshot.getRepository(), completedSnapshot.getSnapshotId().getName(),
@@ -1214,7 +1214,7 @@ public void onSnapshotFailure(Snapshot failedSnapshot, Exception e) {
12141214
}
12151215
});
12161216
} else {
1217-
logger.trace("deleted snapshot is not running - deleting files");
1217+
logger.debug("deleted snapshot is not running - deleting files");
12181218
deleteSnapshotFromRepository(snapshot, listener, repositoryStateId);
12191219
}
12201220
}

0 commit comments

Comments
 (0)