diff --git a/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java b/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java index b12698c8a320e..6e7bf8dd7006b 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java +++ b/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java @@ -457,7 +457,7 @@ public Builder initializeAsRemoteStoreRestore( boolean forceRecoverAllPrimaries ) { final UnassignedInfo unassignedInfo = new UnassignedInfo( - UnassignedInfo.Reason.EXISTING_INDEX_RESTORED, + UnassignedInfo.Reason.REMOTE_METADATA_RECOVERED, "restore_source[remote_store]" ); assert indexMetadata.getIndex().equals(index); diff --git a/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java b/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java index 5e748df5eed2d..7602efe342628 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java +++ b/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java @@ -147,7 +147,9 @@ public enum Reason { /** * Unassigned as a result of closing an index. */ - INDEX_CLOSED + INDEX_CLOSED, + + REMOTE_METADATA_RECOVERED } /** diff --git a/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java b/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java index c0211e1257c8e..f01abd2af5e96 100644 --- a/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java +++ b/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java @@ -48,6 +48,7 @@ import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.cluster.routing.RecoverySource; import org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource; +import org.opensearch.cluster.routing.UnassignedInfo; import org.opensearch.common.UUIDs; import org.opensearch.common.lucene.Lucene; import org.opensearch.common.unit.TimeValue; @@ -434,6 +435,9 @@ private boolean canRecover(IndexShard indexShard) { // got closed on us, just ignore this recovery return false; } + if (indexShard.shardRouting.unassignedInfo().getReason() == UnassignedInfo.Reason.REMOTE_METADATA_RECOVERED) { + return false; + } if (indexShard.routingEntry().primary() == false) { throw new IndexShardRecoveryException(shardId, "Trying to recover when the shard is in backup state", null); }