Skip to content

Commit

Permalink
Alloc. awareness should ignore nodes without attr (#69374)
Browse files Browse the repository at this point in the history
Today we count `null` (i.e. missing) as a valid attribute value in
allocation awareness, even though allocation awareness forbids the
allocation of shards to such a node. Prior to #69334 this didn't matter,
a data node without allocation attributes was pointless.

However, #69334 means we now can allocate shards to such a node: for
instance, there is no need for nodes holding only enrich indices to have
allocation attributes. Therefore we should stop counting `null` as one
of the attribute values.
  • Loading branch information
DaveCTurner committed Feb 23, 2021
1 parent 5ff8b8c commit 2e5625d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Expand Up @@ -237,7 +237,9 @@ public ObjectIntHashMap<String> nodesPerAttributesCounts(String attributeName) {
nodesPerAttributesCounts = new ObjectIntHashMap<>();
for (RoutingNode routingNode : this) {
String attrValue = routingNode.node().getAttributes().get(attributeName);
nodesPerAttributesCounts.addTo(attrValue, 1);
if (attrValue != null) {
nodesPerAttributesCounts.addTo(attrValue, 1);
}
}
nodesPerAttributeNames.put(attributeName, nodesPerAttributesCounts);
return nodesPerAttributesCounts;
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.HashMap;
import java.util.Map;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
Expand Down Expand Up @@ -904,4 +905,36 @@ public void testDisabledByAutoExpandReplicas() {

assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED), empty());
}

public void testNodesWithoutAttributeAreIgnored() {
final Settings settings = Settings.builder()
.put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey(), "zone")
.build();

final AllocationService strategy = createAllocationService(settings);

final Metadata metadata = Metadata.builder()
.put(IndexMetadata.builder("test").settings(settings(Version.CURRENT)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)))
.build();

final ClusterState clusterState = applyStartedShardsUntilNoChange(
ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(Settings.EMPTY))
.metadata(metadata)
.routingTable(RoutingTable.builder()
.addAsNew(metadata.index("test"))
.build())
.nodes(DiscoveryNodes.builder()
.add(newNode("A-0", singletonMap("zone", "a")))
.add(newNode("A-1", singletonMap("zone", "a")))
.add(newNode("B-0", singletonMap("zone", "b")))
.add(newNode("B-1", singletonMap("zone", "b")))
.add(newNode("X-0", emptyMap()))
).build(), strategy);

assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED), empty());
assertTrue(clusterState.getRoutingNodes().node("X-0").isEmpty());
}

}

0 comments on commit 2e5625d

Please sign in to comment.