Skip to content

Commit d37c512

Browse files
Name Snapshot Data Blobs by UUID (#40652) (#41524)
* Name Snapshot Data Blobs by UUID * There is no functional reason why we need incremental naming for these files but * As explained in #38941 it is a possible source of corrupting the repository * It wastes API calls for the list operation * Is just needless complication * Since we store the exact names of the data blobs in all the metadata anyway, we can make this change without any BwC considerations * Even on the worst case scenario of a downgrade the functionality would continue working since the incremental names wouldn't conflict with the uuids and the number parsing for finding the next incremental name suppresses the exception when encountring a non-numeric value after the double underscore prefix
1 parent 1980b70 commit d37c512

File tree

1 file changed

+1
-37
lines changed

1 file changed

+1
-37
lines changed

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

+1-37
Original file line numberDiff line numberDiff line change
@@ -1064,41 +1064,6 @@ protected void finalize(final List<SnapshotFiles> snapshots,
10641064
}
10651065
}
10661066

1067-
/**
1068-
* Generates blob name
1069-
*
1070-
* @param generation the blob number
1071-
* @return the blob name
1072-
*/
1073-
protected String fileNameFromGeneration(long generation) {
1074-
return DATA_BLOB_PREFIX + Long.toString(generation, Character.MAX_RADIX);
1075-
}
1076-
1077-
/**
1078-
* Finds the next available blob number
1079-
*
1080-
* @param blobs list of blobs in the repository
1081-
* @return next available blob number
1082-
*/
1083-
protected long findLatestFileNameGeneration(Map<String, BlobMetaData> blobs) {
1084-
long generation = -1;
1085-
for (String name : blobs.keySet()) {
1086-
if (!name.startsWith(DATA_BLOB_PREFIX)) {
1087-
continue;
1088-
}
1089-
name = canonicalName(name);
1090-
try {
1091-
long currentGen = Long.parseLong(name.substring(DATA_BLOB_PREFIX.length()), Character.MAX_RADIX);
1092-
if (currentGen > generation) {
1093-
generation = currentGen;
1094-
}
1095-
} catch (NumberFormatException e) {
1096-
logger.warn("file [{}] does not conform to the '{}' schema", name, DATA_BLOB_PREFIX);
1097-
}
1098-
}
1099-
return generation;
1100-
}
1101-
11021067
/**
11031068
* Loads all available snapshots in the repository
11041069
*
@@ -1191,7 +1156,6 @@ public void snapshot(final IndexCommit snapshotIndexCommit) {
11911156
throw new IndexShardSnapshotFailedException(shardId, "failed to list blobs", e);
11921157
}
11931158

1194-
long generation = findLatestFileNameGeneration(blobs);
11951159
Tuple<BlobStoreIndexShardSnapshots, Integer> tuple = buildBlobStoreIndexShardSnapshots(blobs);
11961160
BlobStoreIndexShardSnapshots snapshots = tuple.v1();
11971161
int fileListGeneration = tuple.v2();
@@ -1259,7 +1223,7 @@ public void snapshot(final IndexCommit snapshotIndexCommit) {
12591223
indexIncrementalSize += md.length();
12601224
// create a new FileInfo
12611225
BlobStoreIndexShardSnapshot.FileInfo snapshotFileInfo =
1262-
new BlobStoreIndexShardSnapshot.FileInfo(fileNameFromGeneration(++generation), md, chunkSize());
1226+
new BlobStoreIndexShardSnapshot.FileInfo(DATA_BLOB_PREFIX + UUIDs.randomBase64UUID(), md, chunkSize());
12631227
indexCommitPointFiles.add(snapshotFileInfo);
12641228
filesToSnapshot.add(snapshotFileInfo);
12651229
} else {

0 commit comments

Comments
 (0)