Skip to content

Commit c28eee7

Browse files
author
Ali Beyad
authored
Fixes the active shard count check in the case of (#19760)
ActiveShardCount.ALL by checking for active shards, not just started shards, as a shard could be active but in the relocating state (i.e. not in the started state).
1 parent 22e63b4 commit c28eee7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/src/main/java/org/elasticsearch/action/support/ActiveShardCount.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,15 @@ public boolean enoughShardsActive(final ClusterState clusterState, final String
160160
* to meet the required shard count represented by this instance.
161161
*/
162162
public boolean enoughShardsActive(final IndexShardRoutingTable shardRoutingTable) {
163+
final int activeShardCount = shardRoutingTable.activeShards().size();
163164
if (this == ActiveShardCount.ALL) {
164-
return shardRoutingTable.allShardsStarted();
165+
// adding 1 for the primary in addition to the total number of replicas,
166+
// which gives us the total number of shard copies
167+
return activeShardCount == shardRoutingTable.replicaShards().size() + 1;
165168
} else if (this == ActiveShardCount.DEFAULT) {
166-
return shardRoutingTable.primaryShard().started();
169+
return activeShardCount >= 1;
167170
} else {
168-
return shardRoutingTable.activeShards().size() >= value;
171+
return activeShardCount >= value;
169172
}
170173
}
171174

0 commit comments

Comments
 (0)