@@ -602,7 +602,21 @@ public synchronized IndexShard createShard(
602
602
this .indexSettings .getRemoteStorePathStrategy ()
603
603
);
604
604
}
605
- remoteStore = new Store (shardId , this .indexSettings , remoteDirectory , lock , Store .OnClose .EMPTY , path );
605
+ // When an instance of Store is created, a shardlock is created which is released on closing the instance of store.
606
+ // Currently, we create 2 instances of store for remote store backed indices: store and remoteStore.
607
+ // As there can be only one shardlock acquired for a given shard, the lock is shared between store and remoteStore.
608
+ // This creates an issue when we are deleting the index as it results in closing both store and remoteStore.
609
+ // Sample test failure: https://github.com/opensearch-project/OpenSearch/issues/13871
610
+ // The following method provides ShardLock that is not maintained by NodeEnvironment.
611
+ // As part of https://github.com/opensearch-project/OpenSearch/issues/13075, we want to move away from keeping 2
612
+ // store instances.
613
+ ShardLock remoteStoreLock = new ShardLock (shardId ) {
614
+ @ Override
615
+ protected void closeInternal () {
616
+ // Do nothing for shard lock on remote store
617
+ }
618
+ };
619
+ remoteStore = new Store (shardId , this .indexSettings , remoteDirectory , remoteStoreLock , Store .OnClose .EMPTY , path );
606
620
} else {
607
621
// Disallow shards with remote store based settings to be created on non-remote store enabled nodes
608
622
// Even though we have `RemoteStoreMigrationAllocationDecider` in place to prevent something like this from happening at the
@@ -625,7 +639,6 @@ public synchronized IndexShard createShard(
625
639
} else {
626
640
directory = directoryFactory .newDirectory (this .indexSettings , path );
627
641
}
628
-
629
642
store = new Store (
630
643
shardId ,
631
644
this .indexSettings ,
0 commit comments