Skip to content

Commit 76d2fc8

Browse files
original-brownbearGurkan Kaymak
authored and
Gurkan Kaymak
committed
Name Snapshot Data Blobs by UUID (elastic#40652)
* Name Snapshot Data Blobs by UUID * There is no functional reason why we need incremental naming for these files but * As explained in elastic#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 146cd11 commit 76d2fc8

File tree

1 file changed

+6
-42
lines changed

1 file changed

+6
-42
lines changed

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

+6-42
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@
135135
* |- Ac1342-B_x/ - data for index "foo" which was assigned the unique id of Ac1342-B_x in the repository
136136
* | |- meta-20131010.dat - JSON Serialized IndexMetaData for index "foo"
137137
* | |- 0/ - data for shard "0" of index "foo"
138-
* | | |- __1 \
139-
* | | |- __2 |
140-
* | | |- __3 |- files from different segments see snapshot-* for their mappings to real segment files
141-
* | | |- __4 |
142-
* | | |- __5 /
138+
* | | |- __1 \ (files with numeric names were created by older ES versions)
139+
* | | |- __2 |
140+
* | | |- __VPO5oDMVT5y4Akv8T_AO_A |- files from different segments see snap-* for their mappings to real segment files
141+
* | | |- __1gbJy18wS_2kv1qI7FgKuQ |
142+
* | | |- __R8JvZAHlSMyMXyZc2SS8Zg /
143143
* | | .....
144144
* | | |- snap-20131010.dat - JSON serialized BlobStoreIndexShardSnapshot for snapshot "20131010"
145145
* | | |- snap-20131011.dat - JSON serialized BlobStoreIndexShardSnapshot for snapshot "20131011"
@@ -1065,41 +1065,6 @@ protected void finalize(final List<SnapshotFiles> snapshots,
10651065
}
10661066
}
10671067

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

1195-
long generation = findLatestFileNameGeneration(blobs);
11961160
Tuple<BlobStoreIndexShardSnapshots, Integer> tuple = buildBlobStoreIndexShardSnapshots(blobs);
11971161
BlobStoreIndexShardSnapshots snapshots = tuple.v1();
11981162
int fileListGeneration = tuple.v2();
@@ -1260,7 +1224,7 @@ public void snapshot(final IndexCommit snapshotIndexCommit) {
12601224
indexIncrementalSize += md.length();
12611225
// create a new FileInfo
12621226
BlobStoreIndexShardSnapshot.FileInfo snapshotFileInfo =
1263-
new BlobStoreIndexShardSnapshot.FileInfo(fileNameFromGeneration(++generation), md, chunkSize());
1227+
new BlobStoreIndexShardSnapshot.FileInfo(DATA_BLOB_PREFIX + UUIDs.randomBase64UUID(), md, chunkSize());
12641228
indexCommitPointFiles.add(snapshotFileInfo);
12651229
filesToSnapshot.add(snapshotFileInfo);
12661230
} else {

0 commit comments

Comments
 (0)