Skip to content

Commit 88acae4

Browse files
Remove index-N Rebuild in Shard Snapshot Updates (#45740) (#45778)
* There is no point in listing out every shard over and over when the `index-N` blob in the shard contains a list of all the files * Rebuilding the `index-N` from the `snap-${uuid}.dat` blobs does not provide any material benefit. It only would in the corner case of a corrupted `index-N` but otherwise uncorrupted blobs since we neither check the correctness of the content of all segment blobs nor do we do a similar recovery at the root of the repository. * Also, at least in version `6.x` we only mark a shard snapshot as successful after writing out the updated `index-N` blob so all snapshots that would work with `7.x` and newer must have correct `index-N` blobs => Removed the rebuilding of the `index-N` content from `snap-${uuid}.dat` files and moved to only listing `index-N` when taking a snapshot instead of listing all files => Removed check of file existence against physical blob listing => Kept full listing on the delete side to retain full cleanup of blobs that aren't referenced by the `index-N`
1 parent 7512337 commit 88acae4

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

server/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
*/
4545
public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, ToXContentFragment {
4646

47+
public static final BlobStoreIndexShardSnapshots EMPTY = new BlobStoreIndexShardSnapshots(Collections.emptyList());
48+
4749
private final List<SnapshotFiles> shardSnapshots;
4850
private final Map<String, FileInfo> files;
4951
private final Map<String, List<FileInfo>> physicalFiles;

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ public void snapshotShard(Store store, MapperService mapperService, SnapshotId s
920920
final BlobContainer shardContainer = shardContainer(indexId, shardId);
921921
final Map<String, BlobMetaData> blobs;
922922
try {
923-
blobs = shardContainer.listBlobs();
923+
blobs = shardContainer.listBlobsByPrefix(INDEX_FILE_PREFIX);
924924
} catch (IOException e) {
925925
throw new IndexShardSnapshotFailedException(shardId, "failed to list blobs", e);
926926
}
@@ -965,7 +965,7 @@ public void snapshotShard(Store store, MapperService mapperService, SnapshotId s
965965
List<BlobStoreIndexShardSnapshot.FileInfo> filesInfo = snapshots.findPhysicalIndexFiles(fileName);
966966
if (filesInfo != null) {
967967
for (BlobStoreIndexShardSnapshot.FileInfo fileInfo : filesInfo) {
968-
if (fileInfo.isSame(md) && snapshotFileExistsInBlobs(fileInfo, blobs)) {
968+
if (fileInfo.isSame(md)) {
969969
// a commit point file with the same name, size and checksum was already copied to repository
970970
// we will reuse it for this snapshot
971971
existingFileInfo = fileInfo;
@@ -1236,23 +1236,7 @@ private Tuple<BlobStoreIndexShardSnapshots, Long> buildBlobStoreIndexShardSnapsh
12361236
} else if (blobKeys.isEmpty() == false) {
12371237
logger.warn("Could not find a readable index-N file in a non-empty shard snapshot directory [{}]", shardContainer.path());
12381238
}
1239-
1240-
// We couldn't load the index file - falling back to loading individual snapshots
1241-
List<SnapshotFiles> snapshots = new ArrayList<>();
1242-
for (String name : blobKeys) {
1243-
try {
1244-
BlobStoreIndexShardSnapshot snapshot = null;
1245-
if (name.startsWith(SNAPSHOT_PREFIX)) {
1246-
snapshot = indexShardSnapshotFormat.readBlob(shardContainer, name);
1247-
}
1248-
if (snapshot != null) {
1249-
snapshots.add(new SnapshotFiles(snapshot.snapshot(), snapshot.indexFiles()));
1250-
}
1251-
} catch (IOException e) {
1252-
logger.warn(() -> new ParameterizedMessage("Failed to read blob [{}]", name), e);
1253-
}
1254-
}
1255-
return new Tuple<>(new BlobStoreIndexShardSnapshots(snapshots), latest);
1239+
return new Tuple<>(BlobStoreIndexShardSnapshots.EMPTY, latest);
12561240
}
12571241

12581242
/**

0 commit comments

Comments
 (0)