-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
private final ConcurrentMap< | ||
ShardId, | ||
|
@@ -113,6 +113,17 @@ protected GatewayAllocator() { | |
this.replicaShardAllocator = null; | ||
} | ||
|
||
// for tests | ||
protected void setShardAllocators(PrimaryShardAllocator primaryShardAllocator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -188,12 +199,27 @@ 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); | ||
boolean batchMode = routingAllocation.nodes().getMinNodeVersion().onOrAfter(Version.CURRENT); | ||
shiv0408 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (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); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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 forexplainUnassigned
in batch mode scenario.