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