fix wrong routing table versioning when deleting an index
This commit is contained in:
parent
4139bb5180
commit
0bf1ed964e
|
@ -24,7 +24,6 @@ import org.elasticsearch.cluster.ClusterState;
|
|||
import org.elasticsearch.cluster.ClusterStateUpdateTask;
|
||||
import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
|
@ -74,19 +73,16 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
|
|||
@Override public ClusterState execute(ClusterState currentState) {
|
||||
final DeleteIndexListener listener = new DeleteIndexListener(request, userListener);
|
||||
try {
|
||||
if (!currentState.metaData().hasIndex(request.index)) {
|
||||
if (!currentState.metaData().hasConcreteIndex(request.index)) {
|
||||
listener.onFailure(new IndexMissingException(new Index(request.index)));
|
||||
return currentState;
|
||||
}
|
||||
|
||||
logger.info("[{}] deleting index", request.index);
|
||||
|
||||
RoutingTable.Builder routingTableBuilder = new RoutingTable.Builder();
|
||||
for (IndexRoutingTable indexRoutingTable : currentState.routingTable().indicesRouting().values()) {
|
||||
if (!indexRoutingTable.index().equals(request.index)) {
|
||||
routingTableBuilder.add(indexRoutingTable);
|
||||
}
|
||||
}
|
||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
|
||||
routingTableBuilder.remove(request.index);
|
||||
|
||||
MetaData newMetaData = newMetaDataBuilder()
|
||||
.metaData(currentState.metaData())
|
||||
.remove(request.index)
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.RoutingTable.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
|
@ -141,7 +139,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
@Override public ClusterState execute(ClusterState currentState) {
|
||||
try {
|
||||
String[] actualIndices = currentState.metaData().concreteIndices(indices);
|
||||
RoutingTable.Builder routingTableBuilder = newRoutingTableBuilder().routingTable(currentState.routingTable());
|
||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
|
||||
MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());
|
||||
|
||||
int updatedNumberOfReplicas = openSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);
|
||||
|
|
|
@ -107,6 +107,11 @@ public class IndexRoutingTable implements Iterable<IndexShardRoutingTable> {
|
|||
validation.addIndexFailure(index(), "Shard [" + indexShardRoutingTable.shardId().id()
|
||||
+ "] routing table has wrong number of replicas, expected [" + indexMetaData.numberOfReplicas() + "], got [" + routingNumberOfReplicas + "]");
|
||||
}
|
||||
for (ShardRouting shardRouting : indexShardRoutingTable) {
|
||||
if (!shardRouting.index().equals(index())) {
|
||||
validation.addIndexFailure(index(), "shard routing has an index [" + shardRouting.index() + "] that is different than the routing table");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ import static org.elasticsearch.common.collect.Maps.*;
|
|||
@Immutable
|
||||
public class RoutingTable implements Iterable<IndexRoutingTable> {
|
||||
|
||||
public static final RoutingTable EMPTY_ROUTING_TABLE = newRoutingTableBuilder().build();
|
||||
public static final RoutingTable EMPTY_ROUTING_TABLE = builder().build();
|
||||
|
||||
private final long version;
|
||||
|
||||
|
@ -204,10 +204,6 @@ public class RoutingTable implements Iterable<IndexRoutingTable> {
|
|||
return new Builder();
|
||||
}
|
||||
|
||||
public static Builder newRoutingTableBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private long version;
|
||||
|
|
|
@ -392,8 +392,9 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
|
|||
clusterBlocks = ClusterBlocks.builder().blocks(clusterBlocks).addGlobalBlock(NO_MASTER_BLOCK).build();
|
||||
// if this is a data node, clean the metadata and routing, since we want to recreate the indices and shards
|
||||
if (currentState.nodes().localNode().dataNode()) {
|
||||
// TODO, what happens with versioning here?
|
||||
metaData = MetaData.newMetaDataBuilder().build();
|
||||
routingTable = RoutingTable.newRoutingTableBuilder().build();
|
||||
routingTable = RoutingTable.builder().build();
|
||||
}
|
||||
masterFD.stop("no master elected since master left (reason = " + reason + ")");
|
||||
asyncJoinCluster();
|
||||
|
|
|
@ -13,7 +13,6 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
|
|||
import static org.elasticsearch.cluster.metadata.MetaData.*;
|
||||
import static org.elasticsearch.cluster.node.DiscoveryNodes.*;
|
||||
import static org.elasticsearch.cluster.routing.RoutingBuilders.*;
|
||||
import static org.elasticsearch.cluster.routing.RoutingTable.*;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
|
||||
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.*;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.*;
|
||||
|
@ -83,7 +82,7 @@ public class UpdateNumberOfReplicasTests {
|
|||
logger.info("add another replica");
|
||||
routingNodes = clusterState.routingNodes();
|
||||
prevRoutingTable = routingTable;
|
||||
routingTable = newRoutingTableBuilder().routingTable(routingTable).updateNumberOfReplicas(2).build();
|
||||
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(2).build();
|
||||
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(2).build();
|
||||
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
|
||||
|
||||
|
@ -135,7 +134,7 @@ public class UpdateNumberOfReplicasTests {
|
|||
logger.info("now remove a replica");
|
||||
routingNodes = clusterState.routingNodes();
|
||||
prevRoutingTable = routingTable;
|
||||
routingTable = newRoutingTableBuilder().routingTable(routingTable).updateNumberOfReplicas(1).build();
|
||||
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(1).build();
|
||||
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(1).build();
|
||||
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
|
||||
|
||||
|
|
Loading…
Reference in New Issue