use the computed data structure to optimize the awareness allocation decider

This commit is contained in:
Shay Banon 2013-12-18 14:29:41 +01:00
parent 5827170d42
commit d5192ecd31
2 changed files with 13 additions and 13 deletions

View File

@ -184,19 +184,17 @@ public class AwarenessAllocationDecider extends AllocationDecider {
// build the count of shards per attribute value
ObjectIntOpenHashMap<String> shardPerAttribute = new ObjectIntOpenHashMap<String>();
for (RoutingNode routingNode : allocation.routingNodes()) {
for (MutableShardRouting nodeShardRouting : routingNode) {
if (nodeShardRouting.shardId().equals(shardRouting.shardId())) {
for (MutableShardRouting assignedShard : allocation.routingNodes().assignedShards(shardRouting)) {
// if the shard is relocating, then make sure we count it as part of the node it is relocating to
if (nodeShardRouting.relocating()) {
RoutingNode relocationNode = allocation.routingNodes().node(nodeShardRouting.relocatingNodeId());
if (assignedShard.relocating()) {
RoutingNode relocationNode = allocation.routingNodes().node(assignedShard.relocatingNodeId());
shardPerAttribute.addTo(relocationNode.node().attributes().get(awarenessAttribute), 1);
} else if (nodeShardRouting.started()) {
} else if (assignedShard.started()) {
RoutingNode routingNode = allocation.routingNodes().node(assignedShard.currentNodeId());
shardPerAttribute.addTo(routingNode.node().attributes().get(awarenessAttribute), 1);
}
}
}
}
if (moveToNode) {
if (shardRouting.assignedToNode()) {
String nodeId = shardRouting.relocating() ? shardRouting.relocatingNodeId() : shardRouting.currentNodeId();

View File

@ -48,7 +48,9 @@ public class ClusterAllocationRerouteBenchmark {
final int numReplicas = 2;
final int numberOfNodes = 30;
final int numberOfTags = 2;
AllocationService strategy = ElasticsearchAllocationTestCase.createAllocationService(ImmutableSettings.EMPTY, new Random(1));
AllocationService strategy = ElasticsearchAllocationTestCase.createAllocationService(ImmutableSettings.builder()
.put("cluster.routing.allocation.awareness.attributes", "tag")
.build(), new Random(1));
MetaData.Builder mb = MetaData.builder();
for (int i = 1; i <= numIndices; i++) {
@ -62,7 +64,7 @@ public class ClusterAllocationRerouteBenchmark {
RoutingTable routingTable = rb.build();
DiscoveryNodes.Builder nb = DiscoveryNodes.builder();
for (int i = 1; i <= numberOfNodes; i++) {
nb.put(newNode("node" + i, ImmutableMap.of("tag", "tag_" + (i % numberOfTags))));
nb.put(newNode("node" + i, numberOfTags == 0 ? ImmutableMap.<String, String>of() : ImmutableMap.of("tag", "tag_" + (i % numberOfTags))));
}
ClusterState initialClusterState = ClusterState.builder().metaData(metaData).routingTable(routingTable).nodes(nb).build();