From 9e1468b284d699b20d268471930c03613b05c2c3 Mon Sep 17 00:00:00 2001 From: Sachin Kale Date: Sun, 29 Oct 2023 19:51:51 +0530 Subject: [PATCH] Fix directory casting Signed-off-by: Sachin Kale --- .../java/org/opensearch/index/shard/IndexShard.java | 2 +- .../opensearch/snapshots/SnapshotShardsService.java | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/shard/IndexShard.java b/server/src/main/java/org/opensearch/index/shard/IndexShard.java index 32396f1a3df2e..183e1b3a68128 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -1998,7 +1998,7 @@ public void close(String reason, boolean flushEngine, boolean deleted) throws IO /* ToDo : Fix this https://github.com/opensearch-project/OpenSearch/issues/8003 */ - private RemoteSegmentStoreDirectory getRemoteDirectory() { + public RemoteSegmentStoreDirectory getRemoteDirectory() { assert indexSettings.isRemoteStoreEnabled(); assert remoteStore.directory() instanceof FilterDirectory : "Store.directory is not an instance of FilterDirectory"; FilterDirectory remoteStoreDirectory = (FilterDirectory) remoteStore.directory(); diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java b/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java index 6a6458094a721..a07558697a0b5 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java @@ -506,18 +506,12 @@ private GatedCloseable acquireLock(IndexShard indexShard, ShardId s } private void validateSegmentFilesFromAcquiredLock(IndexShard indexShard, long primaryTerm, long generation) throws IOException { - Store remoteStore = indexShard.remoteStore(); Store store = indexShard.store(); try { - remoteStore.incRef(); store.incRef(); - String metadataFilename = ((RemoteSegmentStoreDirectory) remoteStore.directory()).getMetadataFileForCommit( - primaryTerm, - generation - ); - RemoteSegmentMetadata remoteSegmentMetadata = ((RemoteSegmentStoreDirectory) remoteStore.directory()).readMetadataFile( - metadataFilename - ); + RemoteSegmentStoreDirectory remoteDirectory = indexShard.getRemoteDirectory(); + String metadataFilename = remoteDirectory.getMetadataFileForCommit(primaryTerm, generation); + RemoteSegmentMetadata remoteSegmentMetadata = remoteDirectory.readMetadataFile(metadataFilename); Optional segmentInfosFileName = remoteSegmentMetadata.getMetadata() .keySet() .stream() @@ -536,7 +530,6 @@ private void validateSegmentFilesFromAcquiredLock(IndexShard indexShard, long pr } } } finally { - remoteStore.decRef(); store.decRef(); } }