Fix global checkpoint sync test

This commit fixes issues with the global checkpoint sync test. The test
was off in initializing the maximum sequence number on the primary
shard, and off setting the local knowledge on the primary of the global
checkpoint on the replica.
This commit is contained in:
Jason Tedor 2017-09-22 17:12:32 -04:00
parent d8bb413b1b
commit d87ab67e44
1 changed files with 6 additions and 7 deletions

View File

@ -730,12 +730,12 @@ public class IndexShardTests extends IndexShardTestCase {
final IndexMetaData.Builder indexMetadata = IndexMetaData.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, 1); final IndexMetaData.Builder indexMetadata = IndexMetaData.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, 1);
final AtomicBoolean synced = new AtomicBoolean(); final AtomicBoolean synced = new AtomicBoolean();
final IndexShard primaryShard = newShard(shardRouting, indexMetadata.build(), null, null, () -> { synced.set(true); }); final IndexShard primaryShard = newShard(shardRouting, indexMetadata.build(), null, null, () -> { synced.set(true); });
// add a replicas // add a replica
recoverShardFromStore(primaryShard); recoverShardFromStore(primaryShard);
final IndexShard replicaShard = newShard(shardId, false); final IndexShard replicaShard = newShard(shardId, false);
recoverReplica(replicaShard, primaryShard); recoverReplica(replicaShard, primaryShard);
final int maxSeqNo = randomIntBetween(0, 128); final int maxSeqNo = randomIntBetween(0, 128);
for (int i = 0; i < maxSeqNo; i++) { for (int i = 0; i <= maxSeqNo; i++) {
primaryShard.getEngine().seqNoService().generateSeqNo(); primaryShard.getEngine().seqNoService().generateSeqNo();
} }
final long checkpoint = rarely() ? maxSeqNo - scaledRandomIntBetween(0, maxSeqNo) : maxSeqNo; final long checkpoint = rarely() ? maxSeqNo - scaledRandomIntBetween(0, maxSeqNo) : maxSeqNo;
@ -746,11 +746,10 @@ public class IndexShardTests extends IndexShardTestCase {
final String replicaAllocationId = replicaShard.routingEntry().allocationId().getId(); final String replicaAllocationId = replicaShard.routingEntry().allocationId().getId();
primaryShard.updateLocalCheckpointForShard(replicaAllocationId, replicaLocalCheckpoint); primaryShard.updateLocalCheckpointForShard(replicaAllocationId, replicaLocalCheckpoint);
// initialize the local knowledge on the primary of the global checkpoint on the replica shards // initialize the local knowledge on the primary of the global checkpoint on the replica shard
final int replicaGlobalCheckpoint = Math.toIntExact(primaryShard.getGlobalCheckpoint()); final int replicaGlobalCheckpoint =
primaryShard.updateGlobalCheckpointForShard( randomIntBetween(Math.toIntExact(SequenceNumbers.NO_OPS_PERFORMED), Math.toIntExact(primaryShard.getGlobalCheckpoint()));
replicaAllocationId, primaryShard.updateGlobalCheckpointForShard(replicaAllocationId, replicaGlobalCheckpoint);
randomIntBetween(Math.toIntExact(SequenceNumbers.NO_OPS_PERFORMED), replicaGlobalCheckpoint));
// simulate a background maybe sync; it should only run if the knowledge on the replica of the global checkpoint lags the primary // simulate a background maybe sync; it should only run if the knowledge on the replica of the global checkpoint lags the primary
primaryShard.maybeSyncGlobalCheckpoint("test"); primaryShard.maybeSyncGlobalCheckpoint("test");