Import replicated closed dangling indices (#50649)

Dangling replicated closed indices are not imported properly (they miss their routing table when imported).
This commit is contained in:
Yannick Welsch 2020-01-08 11:35:30 +01:00
parent b1ff74f652
commit f203c2b39d
3 changed files with 10 additions and 2 deletions

View File

@ -510,7 +510,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi
} }
public Builder addAsFromDangling(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()) IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
.initializeAsFromDangling(indexMetaData); .initializeAsFromDangling(indexMetaData);
add(indexRoutingBuilder); add(indexRoutingBuilder);

View File

@ -51,6 +51,8 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import static org.elasticsearch.cluster.metadata.MetaDataIndexStateService.isIndexVerifiedBeforeClosed;
public class LocalAllocateDangledIndices { public class LocalAllocateDangledIndices {
private static final Logger logger = LogManager.getLogger(LocalAllocateDangledIndices.class); private static final Logger logger = LogManager.getLogger(LocalAllocateDangledIndices.class);
@ -149,7 +151,7 @@ public class LocalAllocateDangledIndices {
} }
metaData.put(upgradedIndexMetaData, false); metaData.put(upgradedIndexMetaData, false);
blocks.addBlocks(upgradedIndexMetaData); blocks.addBlocks(upgradedIndexMetaData);
if (upgradedIndexMetaData.getState() == IndexMetaData.State.OPEN) { if (upgradedIndexMetaData.getState() == IndexMetaData.State.OPEN || isIndexVerifiedBeforeClosed(indexMetaData)) {
routingTableBuilder.addAsFromDangling(upgradedIndexMetaData); routingTableBuilder.addAsFromDangling(upgradedIndexMetaData);
} }
sb.append("[").append(upgradedIndexMetaData.getIndex()).append("/").append(upgradedIndexMetaData.getState()) sb.append("[").append(upgradedIndexMetaData.getIndex()).append("/").append(upgradedIndexMetaData.getState())

View File

@ -53,6 +53,11 @@ public class DanglingIndicesIT extends ESIntegTestCase {
createIndex(INDEX_NAME, Settings.builder().put("number_of_replicas", 2).build()); 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 // Restart node, deleting the index in its absence, so that there is a dangling index to recover
internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() {
@ -64,6 +69,7 @@ public class DanglingIndicesIT extends ESIntegTestCase {
}); });
assertBusy(() -> assertTrue("Expected dangling index " + INDEX_NAME + " to be recovered", indexExists(INDEX_NAME))); assertBusy(() -> assertTrue("Expected dangling index " + INDEX_NAME + " to be recovered", indexExists(INDEX_NAME)));
ensureGreen(INDEX_NAME);
} }
/** /**