Skip to content

Commit d5e12c6

Browse files
Name Snapshot Data Blobs by UUID (#40652) (#41525)
* 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 460333d commit d5e12c6

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
@@ -1059,41 +1059,6 @@ protected void finalize(final List<SnapshotFiles> snapshots,
10591059
}
10601060
}
10611061

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

1189-
long generation = findLatestFileNameGeneration(blobs);
11901154
Tuple<BlobStoreIndexShardSnapshots, Integer> tuple = buildBlobStoreIndexShardSnapshots(blobs);
11911155
BlobStoreIndexShardSnapshots snapshots = tuple.v1();
11921156
int fileListGeneration = tuple.v2();
@@ -1254,7 +1218,7 @@ public void snapshot(final IndexCommit snapshotIndexCommit) {
12541218
indexIncrementalSize += md.length();
12551219
// create a new FileInfo
12561220
BlobStoreIndexShardSnapshot.FileInfo snapshotFileInfo =
1257-
new BlobStoreIndexShardSnapshot.FileInfo(fileNameFromGeneration(++generation), md, chunkSize());
1221+
new BlobStoreIndexShardSnapshot.FileInfo(DATA_BLOB_PREFIX + UUIDs.randomBase64UUID(), md, chunkSize());
12581222
indexCommitPointFiles.add(snapshotFileInfo);
12591223
filesToSnapshot.add(snapshotFileInfo);
12601224
} else {

0 commit comments

Comments
 (0)