Skip to content

Commit 3c79d57

Browse files
committed
fix test and add assertion
1 parent 6cd553a commit 3c79d57

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

+5
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ public void onFailure(Exception e) {
525525
}
526526
// set this last, once we finished updating all internal state.
527527
this.shardRouting = newRouting;
528+
529+
assert this.shardRouting.primary() == false ||
530+
this.shardRouting.started() == false || // note that we use started and not active to avoid relocating shards
531+
this.replicationTracker.isPrimaryMode()
532+
: "an started primary must be in primary mode " + this.shardRouting;
528533
shardStateUpdated.countDown();
529534
}
530535
if (currentRouting != null && currentRouting.active() == false && newRouting.active()) {

server/src/test/java/org/elasticsearch/indices/cluster/AbstractIndicesClusterStateServiceTestCase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ public void updateShardState(ShardRouting shardRouting,
362362
} else if (shardRouting.primary()) {
363363
// note: it's ok for a replica in post recovery to be started and promoted at once
364364
// this can happen when the primary failed after we sent the start shard message
365-
assertTrue("a replica can only be promoted when started", shardRouting.started());
365+
assertTrue("a replica can only be promoted when active. current: " + this.shardRouting + " new: " + shardRouting,
366+
shardRouting.active());
366367
}
367368
this.shardRouting = shardRouting;
368369
if (shardRouting.primary()) {

0 commit comments

Comments
 (0)