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:
David Turner 2019-04-19 07:37:22 +01:00
parent 4ef4ed66b9
commit 0bb15d3dac
1 changed files with 8 additions and 2 deletions

View File

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