From c28eee77df89b64cc51557bbebeca7c3d69dcb4c Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Tue, 2 Aug 2016 18:00:39 -0400 Subject: [PATCH] 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). --- .../elasticsearch/action/support/ActiveShardCount.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/support/ActiveShardCount.java b/core/src/main/java/org/elasticsearch/action/support/ActiveShardCount.java index d6648462a55..9f3f8b9a5d2 100644 --- a/core/src/main/java/org/elasticsearch/action/support/ActiveShardCount.java +++ b/core/src/main/java/org/elasticsearch/action/support/ActiveShardCount.java @@ -160,12 +160,15 @@ public final class ActiveShardCount implements Writeable { * to meet the required shard count represented by this instance. */ public boolean enoughShardsActive(final IndexShardRoutingTable shardRoutingTable) { + final int activeShardCount = shardRoutingTable.activeShards().size(); if (this == ActiveShardCount.ALL) { - return shardRoutingTable.allShardsStarted(); + // adding 1 for the primary in addition to the total number of replicas, + // which gives us the total number of shard copies + return activeShardCount == shardRoutingTable.replicaShards().size() + 1; } else if (this == ActiveShardCount.DEFAULT) { - return shardRoutingTable.primaryShard().started(); + return activeShardCount >= 1; } else { - return shardRoutingTable.activeShards().size() >= value; + return activeShardCount >= value; } }