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

Fixed Allocation Explain API in batch mode #10348

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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 @@ -76,8 +76,8 @@ public class GatewayAllocator implements ExistingShardsAllocator {

private final RerouteService rerouteService;

private final PrimaryShardAllocator primaryShardAllocator;
private final ReplicaShardAllocator replicaShardAllocator;
private PrimaryShardAllocator primaryShardAllocator;
private ReplicaShardAllocator replicaShardAllocator;
Comment on lines +79 to +80
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, let us add back the final modifier and instead of a UT, we can use an Integration test for explainUnassigned in batch mode scenario.


private final ConcurrentMap<
ShardId,
Expand Down Expand Up @@ -113,6 +113,17 @@ protected GatewayAllocator() {
this.replicaShardAllocator = null;
}

// for tests
protected void setShardAllocators(PrimaryShardAllocator primaryShardAllocator,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a constructor that is exposed for tests.

We expose protected methods for testing a method behaviour per say. For example we have exposed protected static void innerAllocatedUnassigned that takes allocators as argument.

The way you are exposing makes the room potential data loss or state loss for GatewayAllocator state, since GatewayAllocator is a singleton object for that reason itself in the memory. I would highly appreaciate to do away with this function as it can cause a potential state loss leak in GatewayAllocator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did tried writing this test without above code, but could not found any way to do it. If you have any other approach how we test the usecase without using this, happy to try that out.

ReplicaShardAllocator replicaShardAllocator,
PrimaryShardBatchAllocator primaryShardBatchAllocator,
ReplicaShardBatchAllocator replicaBatchShardAllocator) {
this.primaryShardAllocator = primaryShardAllocator;
this.replicaShardAllocator = replicaShardAllocator;
this.primaryBatchShardAllocator = primaryShardBatchAllocator;
this.replicaBatchShardAllocator = replicaBatchShardAllocator;
}

@Override
public int getNumberOfInFlightFetches() {
int count = 0;
Expand Down Expand Up @@ -188,12 +199,26 @@ protected static void innerAllocatedUnassigned(
public AllocateUnassignedDecision explainUnassignedShardAllocation(ShardRouting unassignedShard, RoutingAllocation routingAllocation) {
assert unassignedShard.unassigned();
assert routingAllocation.debugDecision();
if (unassignedShard.primary()) {
assert primaryShardAllocator != null;
return primaryShardAllocator.makeAllocationDecision(unassignedShard, routingAllocation, logger);
if (this.batchMode) {
if (getBatchId(unassignedShard, unassignedShard.primary()) == null) {
createAndUpdateBatches(routingAllocation, unassignedShard.primary());
}
assert getBatchId(unassignedShard, unassignedShard.primary()) != null;
if (unassignedShard.primary()) {
assert primaryBatchShardAllocator != null;
return primaryBatchShardAllocator.makeAllocationDecision(unassignedShard, routingAllocation, logger);
shiv0408 marked this conversation as resolved.
Show resolved Hide resolved
} else {
assert replicaBatchShardAllocator != null;
return replicaBatchShardAllocator.makeAllocationDecision(unassignedShard, routingAllocation, logger);
}
} else {
assert replicaShardAllocator != null;
return replicaShardAllocator.makeAllocationDecision(unassignedShard, routingAllocation, logger);
if (unassignedShard.primary()) {
assert primaryShardAllocator != null;
return primaryShardAllocator.makeAllocationDecision(unassignedShard, routingAllocation, logger);
} else {
assert replicaShardAllocator != null;
return replicaShardAllocator.makeAllocationDecision(unassignedShard, routingAllocation, logger);
}
}
}

Expand Down
Loading
Loading