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

Caching total number of primary shards per node for evaluating constraints on avg primary shards across all indices per node #14992

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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 @@ -459,6 +459,7 @@ void updateRebalanceConstraint(String constraint, boolean add) {
public static class ModelNode implements Iterable<ModelIndex> {
private final Map<String, ModelIndex> indices = new HashMap<>();
private int numShards = 0;
private int numPrimaryShards = 0;
private final RoutingNode routingNode;

ModelNode(RoutingNode routingNode) {
Expand Down Expand Up @@ -492,7 +493,7 @@ public int numPrimaryShards(String idx) {
}

public int numPrimaryShards() {
return indices.values().stream().mapToInt(index -> index.numPrimaryShards()).sum();
return numPrimaryShards;
}

public int highestPrimary(String index) {
Expand All @@ -510,6 +511,10 @@ public void addShard(ShardRouting shard) {
indices.put(index.getIndexId(), index);
}
index.addShard(shard);
if (shard.primary()) {
numPrimaryShards++;
}

numShards++;
}

Expand All @@ -521,6 +526,11 @@ public void removeShard(ShardRouting shard) {
indices.remove(shard.getIndexName());
}
}

if (shard.primary()) {
numPrimaryShards--;
}

numShards--;
}

Expand Down
Loading