Skip to content

Add BlobStoreRepository#writeSnapshotIndexLatestBlob method #53189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,8 @@ public void onFailure(Exception e) {
writeAtomic(indexBlob,
BytesReference.bytes(filteredRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(), writeShardGens)), true);
// write the current generation to the index-latest file
final BytesReference genBytes;
try (BytesStreamOutput bStream = new BytesStreamOutput()) {
bStream.writeLong(newGen);
genBytes = bStream.bytes();
}
logger.debug("Repository [{}] updating index.latest with generation [{}]", metadata.name(), newGen);

writeAtomic(INDEX_LATEST_BLOB, genBytes, false);
writeSnapshotIndexLatestBlob(newGen);

// Step 3: Update CS to reflect new repository generation.
clusterService.submitStateUpdateTask("set safe repository generation [" + metadata.name() + "][" + newGen + "]",
Expand Down Expand Up @@ -1499,11 +1493,19 @@ long latestIndexBlobId() throws IOException {
}
}

// package private for testing
long readSnapshotIndexLatestBlob() throws IOException {
protected long readSnapshotIndexLatestBlob() throws IOException {
return Numbers.bytesToLong(Streams.readFully(blobContainer().readBlob(INDEX_LATEST_BLOB)).toBytesRef());
}

protected void writeSnapshotIndexLatestBlob(long newGen) throws IOException {
final BytesReference genBytes;
try (BytesStreamOutput baos = new BytesStreamOutput()) {
baos.writeLong(newGen);
genBytes = baos.bytes();
}
writeAtomic(INDEX_LATEST_BLOB, genBytes, false);
}

private long listBlobsToGetLatestIndexId() throws IOException {
return latestGeneration(blobContainer().listBlobsByPrefix(INDEX_FILE_PREFIX).keySet());
}
Expand Down