From 1beea3588b29cbf60b1b160fa04316e0e2a01ade Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Thu, 15 Aug 2019 07:07:52 +0200 Subject: [PATCH] Make BlobStoreRepository Validation Read master.dat (#45546) (#45578) * Fixing this for two reasons: 1. Why not verify that the seed we wrote is actually there when we can 2. The AWS S3 SDK started to log a bunch of WARN messages about not fully reading the stream now that we started to abuse the read blob as an `exists` check after removing that method from the blob container --- .../blobstore/BlobStoreRepository.java | 23 +++++++++++-------- 1 file changed, 14 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 58cc94026c4..b585e8feb77 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -1059,15 +1059,20 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp } } else { BlobContainer testBlobContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed))); - try (InputStream ignored = testBlobContainer.readBlob("master.dat")) { - try { - BytesArray bytes = new BytesArray(seed); - try (InputStream stream = bytes.streamInput()) { - testBlobContainer.writeBlob("data-" + localNode.getId() + ".dat", stream, bytes.length(), true); - } - } catch (IOException exp) { - throw new RepositoryVerificationException(metadata.name(), "store location [" + blobStore() + - "] is not accessible on the node [" + localNode + "]", exp); + try { + BytesArray bytes = new BytesArray(seed); + try (InputStream stream = bytes.streamInput()) { + testBlobContainer.writeBlob("data-" + localNode.getId() + ".dat", stream, bytes.length(), true); + } + } catch (IOException exp) { + throw new RepositoryVerificationException(metadata.name(), "store location [" + blobStore() + + "] is not accessible on the node [" + localNode + "]", exp); + } + try (InputStream masterDat = testBlobContainer.readBlob("master.dat")) { + final String seedRead = Streams.readFully(masterDat).utf8ToString(); + if (seedRead.equals(seed) == false) { + throw new RepositoryVerificationException(metadata.name(), "Seed read from master.dat was [" + seedRead + + "] but expected seed [" + seed + "]"); } } catch (NoSuchFileException e) { throw new RepositoryVerificationException(metadata.name(), "a file written by master to the store [" + blobStore() +