Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage tests for New Index creation in PrimaryShardBatchAl… #13733

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,68 @@ public void testMakeAllocationDecisionForReplicaShard() {
assertFalse(allDecisions.get(replicaShards.get(0)).isDecisionTaken());
}

public void testDecisionTakenForNewIndexShards() {

// Simulating for unassigned info = EMPTY_STORE (In the case of new index creations)
final ShardId shard1 = new ShardId("test", "_na_", 0);
final ShardId shard2 = new ShardId("test", "_na_", 1);

// Creating metadata for such a scenario.
Metadata metadata = Metadata.builder()
.put(
IndexMetadata.builder(shard1.getIndexName())
.settings(settings(Version.CURRENT))
.numberOfShards(2)
.numberOfReplicas(1)
.putInSyncAllocationIds(shard1.id(), Sets.newHashSet())
.putInSyncAllocationIds(shard2.id(), Sets.newHashSet())
)
.build();

RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
routingTableBuilder.addAsNew(metadata.index(shard1.getIndex()));

ClusterState state = ClusterState.builder(org.opensearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
.metadata(metadata)
.routingTable(routingTableBuilder.build())
.nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3))
.build();
RoutingAllocation newIndexRoutingAllocation = new RoutingAllocation(
noAllocationDeciders(),
new RoutingNodes(state, false),
state,
null,
null,
System.nanoTime()
);

ShardRouting primaryShard1 = newIndexRoutingAllocation.routingTable()
.getIndicesRouting()
.get("test")
.shard(shard1.id())
.primaryShard();
ShardRouting primaryShard2 = newIndexRoutingAllocation.routingTable()
.getIndicesRouting()
.get("test")
.shard(shard2.id())
.primaryShard();

List<ShardRouting> shards = new ArrayList<>();
shards.add(primaryShard1);
shards.add(primaryShard2);

HashMap<ShardRouting, AllocateUnassignedDecision> allDecisions = batchAllocator.makeAllocationDecision(
shards,
newIndexRoutingAllocation,
logger
);
// verify we get decisions for all the shards
assertEquals(shards.size(), allDecisions.size());
assertEquals(shards, new ArrayList<>(allDecisions.keySet()));
assertFalse(allDecisions.get(shards.get(0)).isDecisionTaken());
assertFalse(allDecisions.get(shards.get(1)).isDecisionTaken());
}

public void testMakeAllocationDecisionDataFetched() {
final RoutingAllocation allocation = routingAllocationWithOnePrimary(noAllocationDeciders(), CLUSTER_RECOVERED, "allocId1");

Expand Down
Loading