Skip to content

Commit

Permalink
Fix explanation message for TargetPoolAllocationDecider (opensearch-p…
Browse files Browse the repository at this point in the history
…roject#11449)

Signed-off-by: panguixin <panguixin@bytedance.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
bugmakerrrrrr authored and shiv0408 committed Apr 25, 2024
1 parent bf03556 commit f9a3b3f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
return allocation.decision(
Decision.NO,
NAME,
"Routing pools are incompatible. Shard pool: [%s], Node Pool: [%s]",
"Routing pools are incompatible. Shard pool: [%s], node pool: [%s]",
shardPool,
targetNodePool
);
Expand All @@ -56,21 +56,21 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
shardRouting,
shardPool,
node.node(),
DiscoveryNodeRole.DATA_ROLE
DiscoveryNodeRole.DATA_ROLE.roleName()
);
return allocation.decision(
Decision.NO,
NAME,
"Routing pools are incompatible. Shard pool: [{}], Node Pool: [{}] without [{}] role",
"Routing pools are incompatible. Shard pool: [%s], node pool: [%s] without [%s] role",
shardPool,
targetNodePool,
DiscoveryNodeRole.DATA_ROLE
DiscoveryNodeRole.DATA_ROLE.roleName()
);
}
return allocation.decision(
Decision.YES,
NAME,
"Routing pools are compatible. Shard pool: [%s], Node Pool: [%s]",
"Routing pools are compatible. Shard pool: [%s], node pool: [%s]",
shardPool,
targetNodePool
);
Expand Down Expand Up @@ -106,7 +106,7 @@ private Decision canAllocateInTargetPool(IndexMetadata indexMetadata, DiscoveryN
return allocation.decision(
Decision.NO,
NAME,
"Routing pools are incompatible. Index pool: [%s], Node Pool: [%s]",
"Routing pools are incompatible. Index pool: [%s], node pool: [%s]",
indexPool,
targetNodePool
);
Expand All @@ -118,21 +118,21 @@ private Decision canAllocateInTargetPool(IndexMetadata indexMetadata, DiscoveryN
indexMetadata.getIndex().getName(),
indexPool,
node,
DiscoveryNodeRole.DATA_ROLE
DiscoveryNodeRole.DATA_ROLE.roleName()
);
return allocation.decision(
Decision.NO,
NAME,
"Routing pools are incompatible. Index pool: [{}], Node Pool: [{}] without [{}] role",
"Routing pools are incompatible. Index pool: [%s], node pool: [%s] without [%s] role",
indexPool,
targetNodePool,
DiscoveryNodeRole.DATA_ROLE
DiscoveryNodeRole.DATA_ROLE.roleName()
);
}
return allocation.decision(
Decision.YES,
NAME,
"Routing pools are compatible. Index pool: [%s], Node Pool: [%s]",
"Routing pools are compatible. Index pool: [%s], node pool: [%s]",
indexPool,
targetNodePool
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,88 @@ public void testTargetPoolDedicatedSearchNodeAllocationDecisions() {
assertEquals(Decision.YES.type(), deciders.shouldAutoExpandToNode(localIdx, localOnlyNode.node(), globalAllocation).type());
assertEquals(Decision.YES.type(), deciders.shouldAutoExpandToNode(remoteIdx, remoteCapableNode.node(), globalAllocation).type());
}

public void testDebugMessage() {
ClusterState clusterState = createInitialCluster(3, 3, true, 2, 2);
AllocationService service = this.createRemoteCapableAllocationService();
clusterState = allocateShardsAndBalance(clusterState, service);

// Add an unassigned primary shard for force allocation checks
Metadata metadata = Metadata.builder(clusterState.metadata())
.put(IndexMetadata.builder("test_local_unassigned").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = RoutingTable.builder(clusterState.routingTable())
.addAsNew(metadata.index("test_local_unassigned"))
.build();
clusterState = ClusterState.builder(clusterState).metadata(metadata).routingTable(routingTable).build();

// Add remote index unassigned primary
clusterState = createRemoteIndex(clusterState, "test_remote_unassigned");

RoutingNodes defaultRoutingNodes = clusterState.getRoutingNodes();
RoutingAllocation globalAllocation = getRoutingAllocation(clusterState, defaultRoutingNodes);
globalAllocation.setDebugMode(RoutingAllocation.DebugMode.ON);

ShardRouting localShard = clusterState.routingTable()
.allShards(getIndexName(0, false))
.stream()
.filter(ShardRouting::primary)
.collect(Collectors.toList())
.get(0);
ShardRouting remoteShard = clusterState.routingTable()
.allShards(getIndexName(0, true))
.stream()
.filter(ShardRouting::primary)
.collect(Collectors.toList())
.get(0);
ShardRouting unassignedLocalShard = clusterState.routingTable()
.allShards("test_local_unassigned")
.stream()
.filter(ShardRouting::primary)
.collect(Collectors.toList())
.get(0);
ShardRouting unassignedRemoteShard = clusterState.routingTable()
.allShards("test_remote_unassigned")
.stream()
.filter(ShardRouting::primary)
.collect(Collectors.toList())
.get(0);
IndexMetadata localIdx = globalAllocation.metadata().getIndexSafe(localShard.index());
IndexMetadata remoteIdx = globalAllocation.metadata().getIndexSafe(remoteShard.index());
String localNodeId = LOCAL_NODE_PREFIX;
for (RoutingNode routingNode : globalAllocation.routingNodes()) {
if (routingNode.nodeId().startsWith(LOCAL_NODE_PREFIX)) {
localNodeId = routingNode.nodeId();
break;
}
}
String remoteNodeId = remoteShard.currentNodeId();
RoutingNode localOnlyNode = defaultRoutingNodes.node(localNodeId);
RoutingNode remoteCapableNode = defaultRoutingNodes.node(remoteNodeId);

TargetPoolAllocationDecider targetPoolAllocationDecider = new TargetPoolAllocationDecider();
Decision decision = targetPoolAllocationDecider.canAllocate(localShard, remoteCapableNode, globalAllocation);
assertEquals(
"Routing pools are incompatible. Shard pool: [LOCAL_ONLY], node pool: [REMOTE_CAPABLE] without [data] role",
decision.getExplanation()
);

decision = targetPoolAllocationDecider.canAllocate(remoteShard, localOnlyNode, globalAllocation);
assertEquals("Routing pools are incompatible. Shard pool: [REMOTE_CAPABLE], node pool: [LOCAL_ONLY]", decision.getExplanation());

decision = targetPoolAllocationDecider.canAllocate(remoteShard, remoteCapableNode, globalAllocation);
assertEquals("Routing pools are compatible. Shard pool: [REMOTE_CAPABLE], node pool: [REMOTE_CAPABLE]", decision.getExplanation());

decision = targetPoolAllocationDecider.canAllocate(localIdx, remoteCapableNode, globalAllocation);
assertEquals(
"Routing pools are incompatible. Index pool: [LOCAL_ONLY], node pool: [REMOTE_CAPABLE] without [data] role",
decision.getExplanation()
);

decision = targetPoolAllocationDecider.canAllocate(remoteIdx, localOnlyNode, globalAllocation);
assertEquals("Routing pools are incompatible. Index pool: [REMOTE_CAPABLE], node pool: [LOCAL_ONLY]", decision.getExplanation());

decision = targetPoolAllocationDecider.canAllocate(remoteIdx, remoteCapableNode, globalAllocation);
assertEquals("Routing pools are compatible. Index pool: [REMOTE_CAPABLE], node pool: [REMOTE_CAPABLE]", decision.getExplanation());
}
}

0 comments on commit f9a3b3f

Please sign in to comment.