Acknowledge problem for put mapping with multiple indices or all indices, closes #720.

This commit is contained in:
kimchy 2011-02-24 21:17:24 +02:00
parent 4def1f4b8e
commit ecc1a3cd8c
2 changed files with 15 additions and 6 deletions

View File

@ -281,13 +281,10 @@ public class MetaDataMappingService extends AbstractComponent {
for (String index : request.indices) {
IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(index);
if (indexRoutingTable != null) {
counter += indexRoutingTable.numberOfNodesShardsAreAllocatedOn();
counter += indexRoutingTable.numberOfNodesShardsAreAllocatedOn(clusterState.nodes().masterNodeId());
}
}
if (counter > 0) {
counter = counter - 1; // we already added the mapping on the master here...
}
if (counter == 0) {
listener.onResponse(new Response(true));
return;

View File

@ -102,12 +102,24 @@ public class IndexRoutingTable implements Iterable<IndexShardRoutingTable> {
return shards.values().iterator();
}
public int numberOfNodesShardsAreAllocatedOn() {
public int numberOfNodesShardsAreAllocatedOn(String... excludedNodes) {
Set<String> nodes = Sets.newHashSet();
for (IndexShardRoutingTable shardRoutingTable : this) {
for (ShardRouting shardRouting : shardRoutingTable) {
if (shardRouting.assignedToNode()) {
nodes.add(shardRouting.currentNodeId());
String currentNodeId = shardRouting.currentNodeId();
boolean excluded = false;
if (excludedNodes != null) {
for (String excludedNode : excludedNodes) {
if (currentNodeId.equals(excludedNode)) {
excluded = true;
break;
}
}
}
if (!excluded) {
nodes.add(currentNodeId);
}
}
}
}