Skip to content

Commit 0bb15d3

Browse files
committed
Allow ops to be blocked after primary promotion (#41360)
Today we assert that there are no operations in flight in this test. However we will sometimes be in a situation where the operations are blocked, and we distinguish these cases since #41271 causing the assertion to fail. This commit addresses this by allowing operations to be blocked sometimes after a primary promotion. Fixes #41333.
1 parent 4ef4ed6 commit 0bb15d3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
import static org.hamcrest.Matchers.hasToString;
183183
import static org.hamcrest.Matchers.instanceOf;
184184
import static org.hamcrest.Matchers.isIn;
185+
import static org.hamcrest.Matchers.isOneOf;
185186
import static org.hamcrest.Matchers.lessThan;
186187
import static org.hamcrest.Matchers.lessThanOrEqualTo;
187188
import static org.hamcrest.Matchers.not;
@@ -630,14 +631,15 @@ public void onFailure(Exception e) {
630631
closeShards(indexShard);
631632
}
632633

633-
public void testOperationPermitsOnPrimaryShards() throws InterruptedException, ExecutionException, IOException {
634+
public void testOperationPermitsOnPrimaryShards() throws Exception {
634635
final ShardId shardId = new ShardId("test", "_na_", 0);
635636
final IndexShard indexShard;
636637

637638
if (randomBoolean()) {
638639
// relocation target
639640
indexShard = newShard(newShardRouting(shardId, "local_node", "other node",
640641
true, ShardRoutingState.INITIALIZING, AllocationId.newRelocation(AllocationId.newInitializing())));
642+
assertEquals(0, indexShard.getActiveOperationsCount());
641643
} else if (randomBoolean()) {
642644
// simulate promotion
643645
indexShard = newStartedShard(false);
@@ -654,11 +656,15 @@ public void testOperationPermitsOnPrimaryShards() throws InterruptedException, E
654656
new IndexShardRoutingTable.Builder(indexShard.shardId()).addShard(primaryRouting).build(),
655657
Collections.emptySet());
656658
latch.await();
659+
assertThat(indexShard.getActiveOperationsCount(), isOneOf(0, IndexShard.OPERATIONS_BLOCKED));
660+
if (randomBoolean()) {
661+
assertBusy(() -> assertEquals(0, indexShard.getActiveOperationsCount()));
662+
}
657663
} else {
658664
indexShard = newStartedShard(true);
665+
assertEquals(0, indexShard.getActiveOperationsCount());
659666
}
660667
final long primaryTerm = indexShard.getPendingPrimaryTerm();
661-
assertEquals(0, indexShard.getActiveOperationsCount());
662668
Releasable operation1 = acquirePrimaryOperationPermitBlockingly(indexShard);
663669
assertEquals(1, indexShard.getActiveOperationsCount());
664670
Releasable operation2 = acquirePrimaryOperationPermitBlockingly(indexShard);

0 commit comments

Comments
 (0)