From 2201d70ae08c7936789c5df5d629568f35e96216 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 24 Feb 2022 17:05:08 +0000 Subject: [PATCH] Simplify Store$MetadataSnapshot and friends `TransportNodesListShardStoreMetadata$StoreFilesMetadata` and `Store$MetadataSnapshot` are both morally-speaking records, and `LoadedMetadata` is really the same as `MetadataSnapshot`. This commit turns them into real records, gets rid of the unnecessary extra class, and renames some of the accessors. Spotted while working on #84034 --- .../indices/recovery/IndexRecoveryIT.java | 4 +- .../elasticsearch/index/shard/IndexShard.java | 2 +- .../org/elasticsearch/index/store/Store.java | 141 +++++++----------- .../recovery/PeerRecoveryTargetService.java | 2 +- .../recovery/RecoverySourceHandler.java | 26 ++-- .../TransportNodesListShardStoreMetadata.java | 20 +-- .../index/shard/IndexShardTests.java | 2 +- .../elasticsearch/index/store/StoreTests.java | 24 +-- .../PeerRecoveryTargetServiceTests.java | 2 +- .../recovery/StartRecoveryRequestTests.java | 2 +- .../BlobStoreRepositoryRestoreTests.java | 4 +- .../SearchableSnapshotDirectoryTests.java | 18 ++- 12 files changed, 106 insertions(+), 141 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java index a04c6d32f8f95..a114949a45ac2 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -1072,10 +1072,10 @@ public void testRecoverLocallyUpToGlobalCheckpoint() throws Exception { logger.info( "--> start recovery request: starting seq_no {}, commit {}", startRecoveryRequest.startingSeqNo(), - startRecoveryRequest.metadataSnapshot().getCommitUserData() + startRecoveryRequest.metadataSnapshot().commitUserData() ); SequenceNumbers.CommitInfo commitInfoAfterLocalRecovery = SequenceNumbers.loadSeqNoInfoFromLuceneCommit( - startRecoveryRequest.metadataSnapshot().getCommitUserData().entrySet() + startRecoveryRequest.metadataSnapshot().commitUserData().entrySet() ); assertThat(commitInfoAfterLocalRecovery.localCheckpoint, equalTo(lastSyncedGlobalCheckpoint)); assertThat(commitInfoAfterLocalRecovery.maxSeqNo, equalTo(lastSyncedGlobalCheckpoint)); diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 59f390375cb53..4913a6ba32965 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -2913,7 +2913,7 @@ private void doCheckIndex() throws IOException { throw e; } final List checkedFiles = new ArrayList<>(metadata.size()); - for (Map.Entry entry : metadata.asMap().entrySet()) { + for (Map.Entry entry : metadata.fileMetadataMap().entrySet()) { try { Store.checkIntegrity(entry.getValue(), store.directory()); if (corrupt == null) { diff --git a/server/src/main/java/org/elasticsearch/index/store/Store.java b/server/src/main/java/org/elasticsearch/index/store/Store.java index 3515f7f9b1be7..55228bcaf8e2d 100644 --- a/server/src/main/java/org/elasticsearch/index/store/Store.java +++ b/server/src/main/java/org/elasticsearch/index/store/Store.java @@ -265,7 +265,7 @@ public MetadataSnapshot getMetadata(IndexCommit commit, boolean lockDirectory) t java.util.concurrent.locks.Lock lock = lockDirectory ? metadataLock.writeLock() : metadataLock.readLock(); lock.lock(); try (Closeable ignored = lockDirectory ? directory.obtainLock(IndexWriter.WRITE_LOCK_NAME) : () -> {}) { - return new MetadataSnapshot(commit, directory, logger); + return MetadataSnapshot.loadFromIndexCommit(commit, directory, logger); } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) { markStoreCorrupted(ex); throw ex; @@ -448,7 +448,7 @@ public static MetadataSnapshot readMetadataSnapshot( Directory dir = new NIOFSDirectory(indexLocation) ) { failIfCorrupted(dir); - return new MetadataSnapshot(null, dir, logger); + return MetadataSnapshot.loadFromIndexCommit(null, dir, logger); } catch (IndexNotFoundException ex) { // that's fine - happens all the time no need to log } catch (FileNotFoundException | NoSuchFileException ex) { @@ -756,80 +756,24 @@ public String toString() { * change concurrently for safety reasons. * * @see StoreFileMetadata + * + * @param numDocs the number of documents in this store snapshot */ - public static final class MetadataSnapshot implements Iterable, Writeable { - private final Map metadata; - private final Map commitUserData; - private final long numDocs; + public record MetadataSnapshot(Map fileMetadataMap, Map commitUserData, long numDocs) + implements + Iterable, + Writeable { public static final MetadataSnapshot EMPTY = new MetadataSnapshot(emptyMap(), emptyMap(), 0L); - public MetadataSnapshot(Map metadata, Map commitUserData, long numDocs) { - this.metadata = metadata; - this.commitUserData = commitUserData; - this.numDocs = numDocs; - } - - MetadataSnapshot(IndexCommit commit, Directory directory, Logger logger) throws IOException { - LoadedMetadata loadedMetadata = loadMetadata(commit, directory, logger); - metadata = loadedMetadata.fileMetadata; - commitUserData = loadedMetadata.userData; - numDocs = loadedMetadata.numDocs; - assert metadata.isEmpty() || numSegmentFiles() == 1 : "numSegmentFiles: " + numSegmentFiles(); - } - - public static MetadataSnapshot readFrom(StreamInput in) throws IOException { - final Map metadata = in.readMapValues(StoreFileMetadata::new, StoreFileMetadata::name); - final var commitUserData = in.readMap(StreamInput::readString, StreamInput::readString); - final var numDocs = in.readLong(); - - if (metadata.size() == 0 && commitUserData.size() == 0 && numDocs == 0) { - return MetadataSnapshot.EMPTY; - } else { - return new MetadataSnapshot(metadata, commitUserData, numDocs); - } - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeMapValues(metadata); - out.writeMap(commitUserData, StreamOutput::writeString, StreamOutput::writeString); - out.writeLong(numDocs); - } - - /** - * Returns the number of documents in this store snapshot - */ - public long getNumDocs() { - return numDocs; - } - - @Nullable - public org.elasticsearch.Version getCommitVersion() { - String version = commitUserData.get(ES_VERSION); - return version == null ? null : org.elasticsearch.Version.fromString(version); - } - - static class LoadedMetadata { - final Map fileMetadata; - final Map userData; + static MetadataSnapshot loadFromIndexCommit(IndexCommit commit, Directory directory, Logger logger) throws IOException { final long numDocs; - - LoadedMetadata(Map fileMetadata, Map userData, long numDocs) { - this.fileMetadata = fileMetadata; - this.userData = userData; - this.numDocs = numDocs; - } - } - - static LoadedMetadata loadMetadata(IndexCommit commit, Directory directory, Logger logger) throws IOException { - long numDocs; - Map builder = new HashMap<>(); - Map commitUserDataBuilder = new HashMap<>(); + final Map metadataByFile = new HashMap<>(); + final Map commitUserData; try { final SegmentInfos segmentCommitInfos = Store.readSegmentsInfo(commit, directory); numDocs = Lucene.getNumDocs(segmentCommitInfos); - commitUserDataBuilder.putAll(segmentCommitInfos.getUserData()); + commitUserData = Map.copyOf(segmentCommitInfos.getUserData()); // we don't know which version was used to write so we take the max version. Version maxVersion = segmentCommitInfos.getMinSegmentLuceneVersion(); for (SegmentCommitInfo info : segmentCommitInfos) { @@ -849,7 +793,7 @@ static LoadedMetadata loadMetadata(IndexCommit commit, Directory directory, Logg checksumFromLuceneFile( directory, file, - builder, + metadataByFile, logger, version.toString(), SEGMENT_INFO_EXTENSION.equals(IndexFileNames.getExtension(file)), @@ -864,7 +808,7 @@ static LoadedMetadata loadMetadata(IndexCommit commit, Directory directory, Logg checksumFromLuceneFile( directory, segmentsFile, - builder, + metadataByFile, logger, maxVersion.toString(), true, @@ -886,16 +830,41 @@ static LoadedMetadata loadMetadata(IndexCommit commit, Directory directory, Logg ex ); Lucene.checkSegmentInfoIntegrity(directory); - } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException cex) { - cex.addSuppressed(ex); - throw cex; } catch (Exception inner) { inner.addSuppressed(ex); throw inner; } throw ex; } - return new LoadedMetadata(unmodifiableMap(builder), unmodifiableMap(commitUserDataBuilder), numDocs); + final var metadataSnapshot = new MetadataSnapshot(unmodifiableMap(metadataByFile), commitUserData, numDocs); + assert metadataSnapshot.fileMetadataMap.isEmpty() || metadataSnapshot.numSegmentFiles() == 1 + : "numSegmentFiles: " + metadataSnapshot.numSegmentFiles(); + return metadataSnapshot; + } + + public static MetadataSnapshot readFrom(StreamInput in) throws IOException { + final Map metadata = in.readMapValues(StoreFileMetadata::new, StoreFileMetadata::name); + final var commitUserData = in.readMap(StreamInput::readString, StreamInput::readString); + final var numDocs = in.readLong(); + + if (metadata.size() == 0 && commitUserData.size() == 0 && numDocs == 0) { + return MetadataSnapshot.EMPTY; + } else { + return new MetadataSnapshot(metadata, commitUserData, numDocs); + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeMapValues(fileMetadataMap); + out.writeMap(commitUserData, StreamOutput::writeString, StreamOutput::writeString); + out.writeLong(numDocs); + } + + @Nullable + public org.elasticsearch.Version getCommitVersion() { + String version = commitUserData.get(ES_VERSION); + return version == null ? null : org.elasticsearch.Version.fromString(version); } private static void checksumFromLuceneFile( @@ -956,15 +925,11 @@ public static void hashFile(BytesRefBuilder fileHash, InputStream in, long size) @Override public Iterator iterator() { - return metadata.values().iterator(); + return fileMetadataMap.values().iterator(); } public StoreFileMetadata get(String name) { - return metadata.get(name); - } - - public Map asMap() { - return metadata; + return fileMetadataMap.get(name); } private static final String SEGMENT_INFO_EXTENSION = "si"; @@ -1079,13 +1044,13 @@ public RecoveryDiff recoveryDiff(final MetadataSnapshot targetSnapshot) { Collections.unmodifiableList(different), Collections.unmodifiableList(missing) ); - assert recoveryDiff.size() == metadata.size() + assert recoveryDiff.size() == fileMetadataMap.size() : "some files are missing: recoveryDiff is [" + recoveryDiff + "] comparing: [" - + metadata + + fileMetadataMap + "] to [" - + targetSnapshot.metadata + + targetSnapshot.fileMetadataMap + "]"; return recoveryDiff; } @@ -1094,11 +1059,7 @@ public RecoveryDiff recoveryDiff(final MetadataSnapshot targetSnapshot) { * Returns the number of files in this snapshot */ public int size() { - return metadata.size(); - } - - public Map getCommitUserData() { - return commitUserData; + return fileMetadataMap.size(); } /** @@ -1112,7 +1073,7 @@ public String getHistoryUUID() { * Returns true iff this metadata contains the given file. */ public boolean contains(String existingFile) { - return metadata.containsKey(existingFile); + return fileMetadataMap.containsKey(existingFile); } /** @@ -1124,7 +1085,7 @@ public StoreFileMetadata getSegmentsFile() { return file; } } - assert metadata.isEmpty(); + assert fileMetadataMap.isEmpty(); return null; } diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetService.java b/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetService.java index 76141af94c53f..102a122c90020 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetService.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetService.java @@ -299,7 +299,7 @@ public static StartRecoveryRequest getStartRecoveryRequest( metadataSnapshot = recoveryTarget.indexShard().snapshotStoreMetadata(); // Make sure that the current translog is consistent with the Lucene index; otherwise, we have to throw away the Lucene index. try { - final String expectedTranslogUUID = metadataSnapshot.getCommitUserData().get(Translog.TRANSLOG_UUID_KEY); + final String expectedTranslogUUID = metadataSnapshot.commitUserData().get(Translog.TRANSLOG_UUID_KEY); final long globalCheckpoint = Translog.readGlobalCheckpoint(recoveryTarget.translogLocation(), expectedTranslogUUID); assert globalCheckpoint + 1 >= startingSeqNo : "invalid startingSeqNo " + startingSeqNo + " >= " + globalCheckpoint; } catch (IOException | TranslogCorruptedException e) { diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java index 5c1245788360e..c549e637ce926 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java @@ -547,10 +547,10 @@ void phase1(IndexCommit snapshot, long startingSeqNo, IntSupplier translogOps, A for (String name : snapshot.getFileNames()) { final StoreFileMetadata md = recoverySourceMetadata.get(name); if (md == null) { - logger.info("Snapshot differs from actual index for file: {} meta: {}", name, recoverySourceMetadata.asMap()); + logger.info("Snapshot differs from actual index for file: {} meta: {}", name, recoverySourceMetadata.fileMetadataMap()); throw new CorruptIndexException( "Snapshot differs from actual index - maybe index was removed metadata has " - + recoverySourceMetadata.asMap().size() + + recoverySourceMetadata.fileMetadataMap().size() + " files", name ); @@ -624,11 +624,11 @@ void recoverFilesFromSourceAndSnapshot( } for (StoreFileMetadata md : shardRecoveryPlan.getSourceFilesToRecover()) { - if (request.metadataSnapshot().asMap().containsKey(md.name())) { + if (request.metadataSnapshot().fileMetadataMap().containsKey(md.name())) { logger.trace( "recovery [phase1]: recovering [{}], exists in local store, but is different: remote [{}], local [{}]", md.name(), - request.metadataSnapshot().asMap().get(md.name()), + request.metadataSnapshot().fileMetadataMap().get(md.name()), md ); } else { @@ -638,11 +638,11 @@ void recoverFilesFromSourceAndSnapshot( for (BlobStoreIndexShardSnapshot.FileInfo fileInfo : shardRecoveryPlan.getSnapshotFilesToRecover()) { final StoreFileMetadata md = fileInfo.metadata(); - if (request.metadataSnapshot().asMap().containsKey(md.name())) { + if (request.metadataSnapshot().fileMetadataMap().containsKey(md.name())) { logger.trace( "recovery [phase1]: recovering [{}], exists in local store, but is different: remote [{}], local [{}]", md.name(), - request.metadataSnapshot().asMap().get(md.name()), + request.metadataSnapshot().fileMetadataMap().get(md.name()), md ); } else { @@ -986,32 +986,32 @@ boolean canSkipPhase1(Store.MetadataSnapshot source, Store.MetadataSnapshot targ if (source.getSyncId() == null || source.getSyncId().equals(target.getSyncId()) == false) { return false; } - if (source.getNumDocs() != target.getNumDocs()) { + if (source.numDocs() != target.numDocs()) { throw new IllegalStateException( "try to recover " + request.shardId() + " from primary shard with sync id but number " + "of docs differ: " - + source.getNumDocs() + + source.numDocs() + " (" + request.sourceNode().getName() + ", primary) vs " - + target.getNumDocs() + + target.numDocs() + "(" + request.targetNode().getName() + ")" ); } - SequenceNumbers.CommitInfo sourceSeqNos = SequenceNumbers.loadSeqNoInfoFromLuceneCommit(source.getCommitUserData().entrySet()); - SequenceNumbers.CommitInfo targetSeqNos = SequenceNumbers.loadSeqNoInfoFromLuceneCommit(target.getCommitUserData().entrySet()); + SequenceNumbers.CommitInfo sourceSeqNos = SequenceNumbers.loadSeqNoInfoFromLuceneCommit(source.commitUserData().entrySet()); + SequenceNumbers.CommitInfo targetSeqNos = SequenceNumbers.loadSeqNoInfoFromLuceneCommit(target.commitUserData().entrySet()); if (sourceSeqNos.localCheckpoint != targetSeqNos.localCheckpoint || targetSeqNos.maxSeqNo != sourceSeqNos.maxSeqNo) { final String message = "try to recover " + request.shardId() + " with sync id but " + "seq_no stats are mismatched: [" - + source.getCommitUserData() + + source.commitUserData() + "] vs [" - + target.getCommitUserData() + + target.commitUserData() + "]"; assert false : message; throw new IllegalStateException(message); diff --git a/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java b/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java index 016841af9601d..a3cb92a183a71 100644 --- a/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java +++ b/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java @@ -192,18 +192,14 @@ private StoreFilesMetadata listStoreMetadata(NodeRequest request) throws IOExcep } } - public static class StoreFilesMetadata implements Iterable, Writeable { - private final Store.MetadataSnapshot metadataSnapshot; - private final List peerRecoveryRetentionLeases; + public record StoreFilesMetadata(Store.MetadataSnapshot metadataSnapshot, List peerRecoveryRetentionLeases) + implements + Iterable, + Writeable { private static final ShardId FAKE_SHARD_ID = new ShardId("_na_", "_na_", 0); public static final StoreFilesMetadata EMPTY = new StoreFilesMetadata(Store.MetadataSnapshot.EMPTY, emptyList()); - public StoreFilesMetadata(Store.MetadataSnapshot metadataSnapshot, List peerRecoveryRetentionLeases) { - this.metadataSnapshot = metadataSnapshot; - this.peerRecoveryRetentionLeases = peerRecoveryRetentionLeases; - } - public static StoreFilesMetadata readFrom(StreamInput in) throws IOException { if (in.getVersion().before(Version.V_8_2_0)) { new ShardId(in); @@ -240,11 +236,11 @@ public Iterator iterator() { } public boolean fileExists(String name) { - return metadataSnapshot.asMap().containsKey(name); + return metadataSnapshot.fileMetadataMap().containsKey(name); } public StoreFileMetadata file(String name) { - return metadataSnapshot.asMap().get(name); + return metadataSnapshot.fileMetadataMap().get(name); } /** @@ -260,10 +256,6 @@ public long getPeerRecoveryRetentionLeaseRetainingSeqNo(DiscoveryNode node) { .orElse(-1L); } - public List peerRecoveryRetentionLeases() { - return peerRecoveryRetentionLeases; - } - /** * @return commit sync id if exists, else null */ diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 640da6b5799ab..731c8d7a2a768 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -3580,7 +3580,7 @@ public void testReadSnapshotAndCheckIndexConcurrently() throws Exception { while (stop.get() == false) { try { Store.MetadataSnapshot readMeta = newShard.snapshotStoreMetadata(); - assertThat(readMeta.getNumDocs(), equalTo(numDocs)); + assertThat(readMeta.numDocs(), equalTo(numDocs)); assertThat(storeFileMetadatas.recoveryDiff(readMeta).different.size(), equalTo(0)); assertThat(storeFileMetadatas.recoveryDiff(readMeta).missing.size(), equalTo(0)); assertThat(storeFileMetadatas.recoveryDiff(readMeta).identical.size(), equalTo(storeFileMetadatas.size())); diff --git a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java index 80055d6324a6b..d545ac1a4b16e 100644 --- a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -355,7 +355,7 @@ public void testNewChecksums() throws IOException { writer.commit(); writer.close(); metadata = store.getMetadata(null); - assertThat(metadata.asMap().isEmpty(), is(false)); + assertThat(metadata.fileMetadataMap().isEmpty(), is(false)); for (StoreFileMetadata meta : metadata) { try (IndexInput input = store.directory().openInput(meta.name(), IOContext.DEFAULT)) { String checksum = Store.digestToString(CodecUtil.retrieveChecksum(input)); @@ -486,13 +486,13 @@ public static void assertConsistent(Store store, Store.MetadataSnapshot metadata for (String file : store.directory().listAll()) { if (IndexWriter.WRITE_LOCK_NAME.equals(file) == false && file.startsWith("extra") == false) { assertTrue( - file + " is not in the map: " + metadata.asMap().size() + " vs. " + store.directory().listAll().length, - metadata.asMap().containsKey(file) + file + " is not in the map: " + metadata.fileMetadataMap().size() + " vs. " + store.directory().listAll().length, + metadata.fileMetadataMap().containsKey(file) ); } else { assertFalse( - file + " is not in the map: " + metadata.asMap().size() + " vs. " + store.directory().listAll().length, - metadata.asMap().containsKey(file) + file + " is not in the map: " + metadata.fileMetadataMap().size() + " vs. " + store.directory().listAll().length, + metadata.fileMetadataMap().containsKey(file) ); } } @@ -678,8 +678,8 @@ public void testRecoveryDiff() throws IOException, InterruptedException { } dvUpdateSnapshot = store.getMetadata(null); } - logger.info("--> source: {}", dvUpdateSnapshot.asMap()); - logger.info("--> target: {}", newCommitMetadata.asMap()); + logger.info("--> source: {}", dvUpdateSnapshot.fileMetadataMap()); + logger.info("--> target: {}", newCommitMetadata.fileMetadataMap()); Store.RecoveryDiff dvUpdateDiff = dvUpdateSnapshot.recoveryDiff(newCommitMetadata); final int delFileCount; if (delFile == null || dvUpdateDiff.different.isEmpty()) { @@ -924,12 +924,12 @@ public void testMetadataSnapshotStreaming() throws Exception { in.setVersion(targetNodeVersion); Store.MetadataSnapshot inMetadataSnapshot = Store.MetadataSnapshot.readFrom(in); Map origEntries = new HashMap<>(); - origEntries.putAll(outMetadataSnapshot.asMap()); - for (Map.Entry entry : inMetadataSnapshot.asMap().entrySet()) { + origEntries.putAll(outMetadataSnapshot.fileMetadataMap()); + for (Map.Entry entry : inMetadataSnapshot.fileMetadataMap().entrySet()) { assertThat(entry.getValue().name(), equalTo(origEntries.remove(entry.getKey()).name())); } assertThat(origEntries.size(), equalTo(0)); - assertThat(inMetadataSnapshot.getCommitUserData(), equalTo(outMetadataSnapshot.getCommitUserData())); + assertThat(inMetadataSnapshot.commitUserData(), equalTo(outMetadataSnapshot.commitUserData())); } public void testEmptyMetadataSnapshotStreaming() throws Exception { @@ -974,9 +974,9 @@ public void testUserDataRead() throws IOException { writer.close(); Store.MetadataSnapshot metadata; metadata = store.getMetadata(randomBoolean() ? null : deletionPolicy.snapshot()); - assertFalse(metadata.asMap().isEmpty()); + assertFalse(metadata.fileMetadataMap().isEmpty()); // do not check for correct files, we have enough tests for that above - assertThat(metadata.getCommitUserData().get(Engine.SYNC_COMMIT_ID), equalTo(syncId)); + assertThat(metadata.commitUserData().get(Engine.SYNC_COMMIT_ID), equalTo(syncId)); TestUtil.checkIndex(store.directory()); assertDeleteContent(store, store.directory()); IOUtils.close(store); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java index 25140ab0edf8b..b74000acfeab6 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java @@ -168,7 +168,7 @@ public void testWriteFileChunksConcurrently() throws Exception { PlainActionFuture cleanFilesFuture = new PlainActionFuture<>(); recoveryTarget.cleanFiles( 0, - Long.parseLong(sourceSnapshot.getCommitUserData().get(SequenceNumbers.MAX_SEQ_NO)), + Long.parseLong(sourceSnapshot.commitUserData().get(SequenceNumbers.MAX_SEQ_NO)), sourceSnapshot, cleanFilesFuture ); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java index 05ab6e34588b5..d31e58b8b116e 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java @@ -65,7 +65,7 @@ public void testSerialization() throws Exception { assertThat(outRequest.targetAllocationId(), equalTo(inRequest.targetAllocationId())); assertThat(outRequest.sourceNode(), equalTo(inRequest.sourceNode())); assertThat(outRequest.targetNode(), equalTo(inRequest.targetNode())); - assertThat(outRequest.metadataSnapshot().asMap(), equalTo(inRequest.metadataSnapshot().asMap())); + assertThat(outRequest.metadataSnapshot().fileMetadataMap(), equalTo(inRequest.metadataSnapshot().fileMetadataMap())); assertThat(outRequest.isPrimaryRelocation(), equalTo(inRequest.isPrimaryRelocation())); assertThat(outRequest.recoveryId(), equalTo(inRequest.recoveryId())); assertThat(outRequest.startingSeqNo(), equalTo(inRequest.startingSeqNo())); diff --git a/server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryRestoreTests.java b/server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryRestoreTests.java index eb7d10fb56758..dc6216b2c7004 100644 --- a/server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryRestoreTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryRestoreTests.java @@ -92,13 +92,13 @@ public void testRestoreSnapshotWithExistingFiles() throws IOException { // capture current store files final Store.MetadataSnapshot storeFiles = shard.snapshotStoreMetadata(); - assertFalse(storeFiles.asMap().isEmpty()); + assertFalse(storeFiles.fileMetadataMap().isEmpty()); // close the shard closeShards(shard); // delete some random files in the store - List deletedFiles = randomSubsetOf(randomIntBetween(1, storeFiles.size() - 1), storeFiles.asMap().keySet()); + List deletedFiles = randomSubsetOf(randomIntBetween(1, storeFiles.size() - 1), storeFiles.fileMetadataMap().keySet()); for (String deletedFile : deletedFiles) { Files.delete(shard.shardPath().resolveIndex().resolve(deletedFile)); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java index 5ff52fd9c23bc..da89daaf93ae8 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java @@ -469,17 +469,29 @@ public void testMetadataSnapshotsDoesNotAccessFilesOnDisk() throws Exception { : snapshotMetadata.recoveryDiff(metadata); assertThat( - "List of different files should be empty but got [" + metadata.asMap() + "] and [" + snapshotMetadata.asMap() + ']', + "List of different files should be empty but got [" + + metadata.fileMetadataMap() + + "] and [" + + snapshotMetadata.fileMetadataMap() + + ']', diff.different.isEmpty(), is(true) ); assertThat( - "List of missing files should be empty but got [" + metadata.asMap() + "] and [" + snapshotMetadata.asMap() + ']', + "List of missing files should be empty but got [" + + metadata.fileMetadataMap() + + "] and [" + + snapshotMetadata.fileMetadataMap() + + ']', diff.missing.isEmpty(), is(true) ); assertThat( - "List of files should be identical [" + metadata.asMap() + "] and [" + snapshotMetadata.asMap() + ']', + "List of files should be identical [" + + metadata.fileMetadataMap() + + "] and [" + + snapshotMetadata.fileMetadataMap() + + ']', diff.identical.size(), equalTo(metadata.size()) );