From f1268f5ee4e911f43c60c447cb429f4f0dcf1baa Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Thu, 5 Mar 2020 22:25:41 +0200 Subject: [PATCH] writeSnapshotIndexLatestBlob --- .../blobstore/BlobStoreRepository.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java index fdb70cffb133f..7123491abbea9 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -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 + "]", @@ -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()); }