diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index df5e32f9f1708..b595efb3a5b4b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -511,7 +511,7 @@ public Builder addAsRecovery(IndexMetaData indexMetaData) { } public Builder addAsFromDangling(IndexMetaData indexMetaData) { - if (indexMetaData.getState() == IndexMetaData.State.OPEN) { + if (indexMetaData.getState() == IndexMetaData.State.OPEN || isIndexVerifiedBeforeClosed(indexMetaData)) { IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex()) .initializeAsFromDangling(indexMetaData); add(indexRoutingBuilder); diff --git a/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java b/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java index a90e31ada1cf2..6d6273f5e7f62 100644 --- a/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java +++ b/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java @@ -51,6 +51,8 @@ import java.util.Arrays; import java.util.Collection; +import static org.elasticsearch.cluster.metadata.MetaDataIndexStateService.isIndexVerifiedBeforeClosed; + public class LocalAllocateDangledIndices { private static final Logger logger = LogManager.getLogger(LocalAllocateDangledIndices.class); @@ -149,7 +151,7 @@ public ClusterState execute(ClusterState currentState) { } metaData.put(upgradedIndexMetaData, false); blocks.addBlocks(upgradedIndexMetaData); - if (upgradedIndexMetaData.getState() == IndexMetaData.State.OPEN) { + if (upgradedIndexMetaData.getState() == IndexMetaData.State.OPEN || isIndexVerifiedBeforeClosed(indexMetaData)) { routingTableBuilder.addAsFromDangling(upgradedIndexMetaData); } sb.append("[").append(upgradedIndexMetaData.getIndex()).append("/").append(upgradedIndexMetaData.getState()) diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java b/server/src/test/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java index 31afef73ad450..ba77877f7f67d 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java @@ -53,6 +53,11 @@ public void testDanglingIndicesAreRecoveredWhenSettingIsEnabled() throws Excepti createIndex(INDEX_NAME, Settings.builder().put("number_of_replicas", 2).build()); + if (randomBoolean()) { + client().admin().indices().prepareClose(INDEX_NAME).get(); + } + ensureGreen(INDEX_NAME); + // Restart node, deleting the index in its absence, so that there is a dangling index to recover internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { @@ -64,6 +69,7 @@ public Settings onNodeStopped(String nodeName) throws Exception { }); assertBusy(() -> assertTrue("Expected dangling index " + INDEX_NAME + " to be recovered", indexExists(INDEX_NAME))); + ensureGreen(INDEX_NAME); } /**