Browse Source

Assert primary indexing requires started shard (#96704)

Strengthen the assertion for when we can index into a shard to include
that the shard is started.
Henning Andersen 2 years ago
parent
commit
60acb88cc1

+ 6 - 0
server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

@@ -2145,6 +2145,12 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
         } else {
             if (origin == Engine.Operation.Origin.PRIMARY) {
                 assert assertPrimaryMode();
+                // We only do indexing into primaries that are started since:
+                // * TransportReplicationAction.ReroutePhase only allows to index into active primaries.
+                // * A relocation will retry the reroute phase.
+                // * Allocation ids protect against spurious requests towards old allocations.
+                // * We apply the cluster state on IndexShard instances before making it available for routing
+                assert state == IndexShardState.STARTED : "must be started to do primary indexing";
             } else if (origin == Engine.Operation.Origin.REPLICA) {
                 assert assertReplicationTarget();
             } else {