Skip to content

Commit 4d210dd

Browse files
Remove index-N Rebuild in Shard Snapshot Updates (#45740)
* 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 b864590 commit 4d210dd

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
@@ -843,7 +843,7 @@ public void snapshotShard(Store store, MapperService mapperService, SnapshotId s
843843
final BlobContainer shardContainer = shardContainer(indexId, shardId);
844844
final Map<String, BlobMetaData> blobs;
845845
try {
846-
blobs = shardContainer.listBlobs();
846+
blobs = shardContainer.listBlobsByPrefix(INDEX_FILE_PREFIX);
847847
} catch (IOException e) {
848848
throw new IndexShardSnapshotFailedException(shardId, "failed to list blobs", e);
849849
}
@@ -888,7 +888,7 @@ public void snapshotShard(Store store, MapperService mapperService, SnapshotId s
888888
List<BlobStoreIndexShardSnapshot.FileInfo> filesInfo = snapshots.findPhysicalIndexFiles(fileName);
889889
if (filesInfo != null) {
890890
for (BlobStoreIndexShardSnapshot.FileInfo fileInfo : filesInfo) {
891-
if (fileInfo.isSame(md) && snapshotFileExistsInBlobs(fileInfo, blobs)) {
891+
if (fileInfo.isSame(md)) {
892892
// a commit point file with the same name, size and checksum was already copied to repository
893893
// we will reuse it for this snapshot
894894
existingFileInfo = fileInfo;
@@ -1159,23 +1159,7 @@ private Tuple<BlobStoreIndexShardSnapshots, Long> buildBlobStoreIndexShardSnapsh
11591159
} else if (blobKeys.isEmpty() == false) {
11601160
logger.warn("Could not find a readable index-N file in a non-empty shard snapshot directory [{}]", shardContainer.path());
11611161
}
1162-
1163-
// We couldn't load the index file - falling back to loading individual snapshots
1164-
List<SnapshotFiles> snapshots = new ArrayList<>();
1165-
for (String name : blobKeys) {
1166-
try {
1167-
BlobStoreIndexShardSnapshot snapshot = null;
1168-
if (name.startsWith(SNAPSHOT_PREFIX)) {
1169-
snapshot = indexShardSnapshotFormat.readBlob(shardContainer, name);
1170-
}
1171-
if (snapshot != null) {
1172-
snapshots.add(new SnapshotFiles(snapshot.snapshot(), snapshot.indexFiles()));
1173-
}
1174-
} catch (IOException e) {
1175-
logger.warn(() -> new ParameterizedMessage("Failed to read blob [{}]", name), e);
1176-
}
1177-
}
1178-
return new Tuple<>(new BlobStoreIndexShardSnapshots(snapshots), latest);
1162+
return new Tuple<>(BlobStoreIndexShardSnapshots.EMPTY, latest);
11791163
}
11801164

11811165
/**

0 commit comments

Comments
 (0)