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.
This commit is contained in:
parent
4ef4ed66b9
commit
0bb15d3dac
|
@ -182,6 +182,7 @@ import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.hasToString;
|
import static org.hamcrest.Matchers.hasToString;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.isIn;
|
import static org.hamcrest.Matchers.isIn;
|
||||||
|
import static org.hamcrest.Matchers.isOneOf;
|
||||||
import static org.hamcrest.Matchers.lessThan;
|
import static org.hamcrest.Matchers.lessThan;
|
||||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
@ -630,7 +631,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
closeShards(indexShard);
|
closeShards(indexShard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOperationPermitsOnPrimaryShards() throws InterruptedException, ExecutionException, IOException {
|
public void testOperationPermitsOnPrimaryShards() throws Exception {
|
||||||
final ShardId shardId = new ShardId("test", "_na_", 0);
|
final ShardId shardId = new ShardId("test", "_na_", 0);
|
||||||
final IndexShard indexShard;
|
final IndexShard indexShard;
|
||||||
|
|
||||||
|
@ -638,6 +639,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
// relocation target
|
// relocation target
|
||||||
indexShard = newShard(newShardRouting(shardId, "local_node", "other node",
|
indexShard = newShard(newShardRouting(shardId, "local_node", "other node",
|
||||||
true, ShardRoutingState.INITIALIZING, AllocationId.newRelocation(AllocationId.newInitializing())));
|
true, ShardRoutingState.INITIALIZING, AllocationId.newRelocation(AllocationId.newInitializing())));
|
||||||
|
assertEquals(0, indexShard.getActiveOperationsCount());
|
||||||
} else if (randomBoolean()) {
|
} else if (randomBoolean()) {
|
||||||
// simulate promotion
|
// simulate promotion
|
||||||
indexShard = newStartedShard(false);
|
indexShard = newStartedShard(false);
|
||||||
|
@ -654,11 +656,15 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
new IndexShardRoutingTable.Builder(indexShard.shardId()).addShard(primaryRouting).build(),
|
new IndexShardRoutingTable.Builder(indexShard.shardId()).addShard(primaryRouting).build(),
|
||||||
Collections.emptySet());
|
Collections.emptySet());
|
||||||
latch.await();
|
latch.await();
|
||||||
|
assertThat(indexShard.getActiveOperationsCount(), isOneOf(0, IndexShard.OPERATIONS_BLOCKED));
|
||||||
|
if (randomBoolean()) {
|
||||||
|
assertBusy(() -> assertEquals(0, indexShard.getActiveOperationsCount()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
indexShard = newStartedShard(true);
|
indexShard = newStartedShard(true);
|
||||||
|
assertEquals(0, indexShard.getActiveOperationsCount());
|
||||||
}
|
}
|
||||||
final long primaryTerm = indexShard.getPendingPrimaryTerm();
|
final long primaryTerm = indexShard.getPendingPrimaryTerm();
|
||||||
assertEquals(0, indexShard.getActiveOperationsCount());
|
|
||||||
Releasable operation1 = acquirePrimaryOperationPermitBlockingly(indexShard);
|
Releasable operation1 = acquirePrimaryOperationPermitBlockingly(indexShard);
|
||||||
assertEquals(1, indexShard.getActiveOperationsCount());
|
assertEquals(1, indexShard.getActiveOperationsCount());
|
||||||
Releasable operation2 = acquirePrimaryOperationPermitBlockingly(indexShard);
|
Releasable operation2 = acquirePrimaryOperationPermitBlockingly(indexShard);
|
||||||
|
|
Loading…
Reference in New Issue