Skip to content
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