fix wrong routing table versioning when deleting an index

This commit is contained in:
kimchy 2011-06-29 14:51:32 +03:00
parent 4139bb5180
commit 0bf1ed964e
6 changed files with 15 additions and 20 deletions

View File

@ -24,7 +24,6 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction; import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction;
import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.routing.IndexRoutingTable;
import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
@ -74,19 +73,16 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
@Override public ClusterState execute(ClusterState currentState) { @Override public ClusterState execute(ClusterState currentState) {
final DeleteIndexListener listener = new DeleteIndexListener(request, userListener); final DeleteIndexListener listener = new DeleteIndexListener(request, userListener);
try { try {
if (!currentState.metaData().hasIndex(request.index)) { if (!currentState.metaData().hasConcreteIndex(request.index)) {
listener.onFailure(new IndexMissingException(new Index(request.index))); listener.onFailure(new IndexMissingException(new Index(request.index)));
return currentState; return currentState;
} }
logger.info("[{}] deleting index", request.index); logger.info("[{}] deleting index", request.index);
RoutingTable.Builder routingTableBuilder = new RoutingTable.Builder(); RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
for (IndexRoutingTable indexRoutingTable : currentState.routingTable().indicesRouting().values()) { routingTableBuilder.remove(request.index);
if (!indexRoutingTable.index().equals(request.index)) {
routingTableBuilder.add(indexRoutingTable);
}
}
MetaData newMetaData = newMetaDataBuilder() MetaData newMetaData = newMetaDataBuilder()
.metaData(currentState.metaData()) .metaData(currentState.metaData())
.remove(request.index) .remove(request.index)

View File

@ -36,8 +36,6 @@ import org.elasticsearch.common.settings.Settings;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.elasticsearch.cluster.routing.RoutingTable.*;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
@ -141,7 +139,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
@Override public ClusterState execute(ClusterState currentState) { @Override public ClusterState execute(ClusterState currentState) {
try { try {
String[] actualIndices = currentState.metaData().concreteIndices(indices); 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()); MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());
int updatedNumberOfReplicas = openSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1); int updatedNumberOfReplicas = openSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);

View File

@ -107,6 +107,11 @@ public class IndexRoutingTable implements Iterable<IndexShardRoutingTable> {
validation.addIndexFailure(index(), "Shard [" + indexShardRoutingTable.shardId().id() validation.addIndexFailure(index(), "Shard [" + indexShardRoutingTable.shardId().id()
+ "] routing table has wrong number of replicas, expected [" + indexMetaData.numberOfReplicas() + "], got [" + routingNumberOfReplicas + "]"); + "] 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");
}
}
} }
} }

View File

@ -46,7 +46,7 @@ import static org.elasticsearch.common.collect.Maps.*;
@Immutable @Immutable
public class RoutingTable implements Iterable<IndexRoutingTable> { 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; private final long version;
@ -204,10 +204,6 @@ public class RoutingTable implements Iterable<IndexRoutingTable> {
return new Builder(); return new Builder();
} }
public static Builder newRoutingTableBuilder() {
return new Builder();
}
public static class Builder { public static class Builder {
private long version; private long version;

View File

@ -392,8 +392,9 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
clusterBlocks = ClusterBlocks.builder().blocks(clusterBlocks).addGlobalBlock(NO_MASTER_BLOCK).build(); 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 this is a data node, clean the metadata and routing, since we want to recreate the indices and shards
if (currentState.nodes().localNode().dataNode()) { if (currentState.nodes().localNode().dataNode()) {
// TODO, what happens with versioning here?
metaData = MetaData.newMetaDataBuilder().build(); metaData = MetaData.newMetaDataBuilder().build();
routingTable = RoutingTable.newRoutingTableBuilder().build(); routingTable = RoutingTable.builder().build();
} }
masterFD.stop("no master elected since master left (reason = " + reason + ")"); masterFD.stop("no master elected since master left (reason = " + reason + ")");
asyncJoinCluster(); asyncJoinCluster();

View File

@ -13,7 +13,6 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
import static org.elasticsearch.cluster.metadata.MetaData.*; import static org.elasticsearch.cluster.metadata.MetaData.*;
import static org.elasticsearch.cluster.node.DiscoveryNodes.*; import static org.elasticsearch.cluster.node.DiscoveryNodes.*;
import static org.elasticsearch.cluster.routing.RoutingBuilders.*; 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.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.*; import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.*;
import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.common.settings.ImmutableSettings.*;
@ -83,7 +82,7 @@ public class UpdateNumberOfReplicasTests {
logger.info("add another replica"); logger.info("add another replica");
routingNodes = clusterState.routingNodes(); routingNodes = clusterState.routingNodes();
prevRoutingTable = routingTable; 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(); metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(2).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build(); clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
@ -135,7 +134,7 @@ public class UpdateNumberOfReplicasTests {
logger.info("now remove a replica"); logger.info("now remove a replica");
routingNodes = clusterState.routingNodes(); routingNodes = clusterState.routingNodes();
prevRoutingTable = routingTable; 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(); metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(1).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build(); clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();