Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
zshuyi committed Jul 3, 2024
1 parent 53500b4 commit bd2877b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.Strings;

import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING;

/**
* An allocation decider that prevents multiple instances of the same shard to
* be allocated on the same {@code node}.
Expand Down Expand Up @@ -95,10 +93,6 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
// if its already a NO decision looking at the node, or we aren't configured to look at the host, return the decision
return decision;
}
if (INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(allocation.metadata().getIndexSafe(shardRouting.index()).getSettings())
.autoExpandToAll()) {
return allocation.decision(Decision.YES, NAME, "allocation awareness is ignored, this index is set to auto-expand to all");
}
if (node.node() != null) {
for (RoutingNode checkNode : allocation.routingNodes()) {
if (checkNode.node() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

import static java.util.Collections.emptyMap;
import static org.opensearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.opensearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.opensearch.cluster.routing.allocation.RoutingNodesUtils.numberOfShardsOfType;
import static org.hamcrest.Matchers.equalTo;

Expand Down Expand Up @@ -188,60 +187,4 @@ public void testForceAllocatePrimaryOnSameNodeNotAllowed() {
decision = decider.canForceAllocatePrimary(newPrimary, unassignedNode, routingAllocation);
assertEquals(Decision.Type.YES, decision.type());
}

public void testSameHostCheckIgnoredByAutoExpandReplicasToAll() {
final AllocationService strategy = createAllocationService(
Settings.builder().put(SameShardAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.getKey(), true).build()
);

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, 100)
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all")
)
)
.build();

final ClusterState clusterState = applyStartedShardsUntilNoChange(
ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
.metadata(metadata)
.routingTable(RoutingTable.builder().addAsNew(metadata.index("test")).build())
.nodes(
DiscoveryNodes.builder()
.add(
new DiscoveryNode(
"node1_name",
"node1",
"node1",
"test_host_1",
"test_host_address1",
buildNewFakeTransportAddress(),
emptyMap(),
CLUSTER_MANAGER_DATA_ROLES,
Version.CURRENT
)
)
.add(
new DiscoveryNode(
"node2_name",
"node2",
"node2",
"test_host_2",
"test_host_address2",
buildNewFakeTransportAddress(),
emptyMap(),
CLUSTER_MANAGER_DATA_ROLES,
Version.CURRENT
)
)
)
.build(),
strategy
);

assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(0));
}
}

0 comments on commit bd2877b

Please sign in to comment.