use the computed data structure to optimize the awareness allocation decider
This commit is contained in:
parent
5827170d42
commit
d5192ecd31
|
@ -184,19 +184,17 @@ public class AwarenessAllocationDecider extends AllocationDecider {
|
||||||
|
|
||||||
// build the count of shards per attribute value
|
// build the count of shards per attribute value
|
||||||
ObjectIntOpenHashMap<String> shardPerAttribute = new ObjectIntOpenHashMap<String>();
|
ObjectIntOpenHashMap<String> shardPerAttribute = new ObjectIntOpenHashMap<String>();
|
||||||
for (RoutingNode routingNode : allocation.routingNodes()) {
|
for (MutableShardRouting assignedShard : allocation.routingNodes().assignedShards(shardRouting)) {
|
||||||
for (MutableShardRouting nodeShardRouting : routingNode) {
|
// if the shard is relocating, then make sure we count it as part of the node it is relocating to
|
||||||
if (nodeShardRouting.shardId().equals(shardRouting.shardId())) {
|
if (assignedShard.relocating()) {
|
||||||
// if the shard is relocating, then make sure we count it as part of the node it is relocating to
|
RoutingNode relocationNode = allocation.routingNodes().node(assignedShard.relocatingNodeId());
|
||||||
if (nodeShardRouting.relocating()) {
|
shardPerAttribute.addTo(relocationNode.node().attributes().get(awarenessAttribute), 1);
|
||||||
RoutingNode relocationNode = allocation.routingNodes().node(nodeShardRouting.relocatingNodeId());
|
} else if (assignedShard.started()) {
|
||||||
shardPerAttribute.addTo(relocationNode.node().attributes().get(awarenessAttribute), 1);
|
RoutingNode routingNode = allocation.routingNodes().node(assignedShard.currentNodeId());
|
||||||
} else if (nodeShardRouting.started()) {
|
shardPerAttribute.addTo(routingNode.node().attributes().get(awarenessAttribute), 1);
|
||||||
shardPerAttribute.addTo(routingNode.node().attributes().get(awarenessAttribute), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveToNode) {
|
if (moveToNode) {
|
||||||
if (shardRouting.assignedToNode()) {
|
if (shardRouting.assignedToNode()) {
|
||||||
String nodeId = shardRouting.relocating() ? shardRouting.relocatingNodeId() : shardRouting.currentNodeId();
|
String nodeId = shardRouting.relocating() ? shardRouting.relocatingNodeId() : shardRouting.currentNodeId();
|
||||||
|
|
|
@ -48,7 +48,9 @@ public class ClusterAllocationRerouteBenchmark {
|
||||||
final int numReplicas = 2;
|
final int numReplicas = 2;
|
||||||
final int numberOfNodes = 30;
|
final int numberOfNodes = 30;
|
||||||
final int numberOfTags = 2;
|
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();
|
MetaData.Builder mb = MetaData.builder();
|
||||||
for (int i = 1; i <= numIndices; i++) {
|
for (int i = 1; i <= numIndices; i++) {
|
||||||
|
@ -62,7 +64,7 @@ public class ClusterAllocationRerouteBenchmark {
|
||||||
RoutingTable routingTable = rb.build();
|
RoutingTable routingTable = rb.build();
|
||||||
DiscoveryNodes.Builder nb = DiscoveryNodes.builder();
|
DiscoveryNodes.Builder nb = DiscoveryNodes.builder();
|
||||||
for (int i = 1; i <= numberOfNodes; i++) {
|
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();
|
ClusterState initialClusterState = ClusterState.builder().metaData(metaData).routingTable(routingTable).nodes(nb).build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue