From d4c20113234c54cfd177f2d122cfe84c9a85906e Mon Sep 17 00:00:00 2001 From: Sachin Kale Date: Mon, 16 Oct 2023 09:07:37 +0530 Subject: [PATCH] Fix assertion failure while closing remoteStore Signed-off-by: Sachin Kale --- .../main/java/org/opensearch/index/IndexService.java | 10 +++++++++- .../java/org/opensearch/index/shard/IndexShard.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/IndexService.java b/server/src/main/java/org/opensearch/index/IndexService.java index 84e8e2f41aaf1..bf1860dc7e1d8 100644 --- a/server/src/main/java/org/opensearch/index/IndexService.java +++ b/server/src/main/java/org/opensearch/index/IndexService.java @@ -654,7 +654,15 @@ private void closeShard(String reason, ShardId sId, IndexShard indexShard, Store } if (remoteStore != null && indexShard.isPrimaryMode() && deleted.get()) { - remoteStore.close(); + // When an instance of Store is created, a shardlock is created which is released on closing the instance of store. + // Currently, we create 2 instances of store for remote store backed indices: store and remoteStore. + // As there can be only one shardlock acquired for a given shard, the lock is shared between store and remoteStore. + // This creates an issue when we are deleting the index as it results in closing both store and remoteStore. At the time + // of closure of second Store instance, we get the assertion error saying shard is not locked. + // Ideally, we should be closing the remoteStore but until we work on CompositeStore + // (https://github.com/opensearch-project/OpenSearch/issues/3719), we mitigate the test failures by + // closing the remoteDirectory. + indexShard.getRemoteDirectory().close(); } } catch (Exception e) { 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 9489c7d7fc1dd..7e65d26b53615 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -1975,7 +1975,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();