@@ -597,7 +597,14 @@ 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
+ remoteStore = new Store (
601
+ shardId ,
602
+ this .indexSettings ,
603
+ remoteDirectory ,
604
+ getRemoteStoreLock (shardId ),
605
+ Store .OnClose .EMPTY ,
606
+ path
607
+ );
601
608
} else {
602
609
// Disallow shards with remote store based settings to be created on non-remote store enabled nodes
603
610
// Even though we have `RemoteStoreMigrationAllocationDecider` in place to prevent something like this from happening at the
@@ -678,6 +685,23 @@ public synchronized IndexShard createShard(
678
685
}
679
686
}
680
687
688
+ // When an instance of Store is created, a shardlock is created which is released on closing the instance of store.
689
+ // Currently, we create 2 instances of store for remote store backed indices: store and remoteStore.
690
+ // As there can be only one shardlock acquired for a given shard, the lock is shared between store and remoteStore.
691
+ // This creates an issue when we are deleting the index as it results in closing both store and remoteStore.
692
+ // Sample test failure: https://github.com/opensearch-project/OpenSearch/issues/13871
693
+ // The following method provides ShardLock that is not maintained by NodeEnvironment.
694
+ // As part of https://github.com/opensearch-project/OpenSearch/issues/13075, we want to move away from keeping 2
695
+ // store instances.
696
+ private ShardLock getRemoteStoreLock (ShardId shardId ) {
697
+ return new ShardLock (shardId ) {
698
+ @ Override
699
+ protected void closeInternal () {
700
+ // Ignore for remote store
701
+ }
702
+ };
703
+ }
704
+
681
705
/*
682
706
Fetches the shard path based on the index type -
683
707
For a remote snapshot index, the cache path is used to initialize the shards.
0 commit comments