Skip to content

Commit cd830b5

Browse files
Name Snapshot Data Blobs by UUID (#40652) (#41523)
* 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 31d5a5a commit cd830b5

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
@@ -1053,41 +1053,6 @@ protected void finalize(final List<SnapshotFiles> snapshots,
10531053
}
10541054
}
10551055

1056-
/**
1057-
* Generates blob name
1058-
*
1059-
* @param generation the blob number
1060-
* @return the blob name
1061-
*/
1062-
protected String fileNameFromGeneration(long generation) {
1063-
return DATA_BLOB_PREFIX + Long.toString(generation, Character.MAX_RADIX);
1064-
}
1065-
1066-
/**
1067-
* Finds the next available blob number
1068-
*
1069-
* @param blobs list of blobs in the repository
1070-
* @return next available blob number
1071-
*/
1072-
protected long findLatestFileNameGeneration(Map<String, BlobMetaData> blobs) {
1073-
long generation = -1;
1074-
for (String name : blobs.keySet()) {
1075-
if (!name.startsWith(DATA_BLOB_PREFIX)) {
1076-
continue;
1077-
}
1078-
name = canonicalName(name);
1079-
try {
1080-
long currentGen = Long.parseLong(name.substring(DATA_BLOB_PREFIX.length()), Character.MAX_RADIX);
1081-
if (currentGen > generation) {
1082-
generation = currentGen;
1083-
}
1084-
} catch (NumberFormatException e) {
1085-
logger.warn("file [{}] does not conform to the '{}' schema", name, DATA_BLOB_PREFIX);
1086-
}
1087-
}
1088-
return generation;
1089-
}
1090-
10911056
/**
10921057
* Loads all available snapshots in the repository
10931058
*
@@ -1180,7 +1145,6 @@ public void snapshot(final IndexCommit snapshotIndexCommit) {
11801145
throw new IndexShardSnapshotFailedException(shardId, "failed to list blobs", e);
11811146
}
11821147

1183-
long generation = findLatestFileNameGeneration(blobs);
11841148
Tuple<BlobStoreIndexShardSnapshots, Integer> tuple = buildBlobStoreIndexShardSnapshots(blobs);
11851149
BlobStoreIndexShardSnapshots snapshots = tuple.v1();
11861150
int fileListGeneration = tuple.v2();
@@ -1248,7 +1212,7 @@ public void snapshot(final IndexCommit snapshotIndexCommit) {
12481212
indexIncrementalSize += md.length();
12491213
// create a new FileInfo
12501214
BlobStoreIndexShardSnapshot.FileInfo snapshotFileInfo =
1251-
new BlobStoreIndexShardSnapshot.FileInfo(fileNameFromGeneration(++generation), md, chunkSize());
1215+
new BlobStoreIndexShardSnapshot.FileInfo(DATA_BLOB_PREFIX + UUIDs.randomBase64UUID(), md, chunkSize());
12521216
indexCommitPointFiles.add(snapshotFileInfo);
12531217
filesToSnapshot.add(snapshotFileInfo);
12541218
} else {

0 commit comments

Comments
 (0)