Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d87ab67

Browse files
committed
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.
1 parent d8bb413 commit d87ab67

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,12 @@ public void testGlobalCheckpointSync() throws IOException {
730730
final IndexMetaData.Builder indexMetadata = IndexMetaData.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, 1);
731731
final AtomicBoolean synced = new AtomicBoolean();
732732
final IndexShard primaryShard = newShard(shardRouting, indexMetadata.build(), null, null, () -> { synced.set(true); });
733-
// add a replicas
733+
// add a replica
734734
recoverShardFromStore(primaryShard);
735735
final IndexShard replicaShard = newShard(shardId, false);
736736
recoverReplica(replicaShard, primaryShard);
737737
final int maxSeqNo = randomIntBetween(0, 128);
738-
for (int i = 0; i < maxSeqNo; i++) {
738+
for (int i = 0; i <= maxSeqNo; i++) {
739739
primaryShard.getEngine().seqNoService().generateSeqNo();
740740
}
741741
final long checkpoint = rarely() ? maxSeqNo - scaledRandomIntBetween(0, maxSeqNo) : maxSeqNo;
@@ -746,11 +746,10 @@ public void testGlobalCheckpointSync() throws IOException {
746746
final String replicaAllocationId = replicaShard.routingEntry().allocationId().getId();
747747
primaryShard.updateLocalCheckpointForShard(replicaAllocationId, replicaLocalCheckpoint);
748748

749-
// initialize the local knowledge on the primary of the global checkpoint on the replica shards
750-
final int replicaGlobalCheckpoint = Math.toIntExact(primaryShard.getGlobalCheckpoint());
751-
primaryShard.updateGlobalCheckpointForShard(
752-
replicaAllocationId,
753-
randomIntBetween(Math.toIntExact(SequenceNumbers.NO_OPS_PERFORMED), replicaGlobalCheckpoint));
749+
// initialize the local knowledge on the primary of the global checkpoint on the replica shard
750+
final int replicaGlobalCheckpoint =
751+
randomIntBetween(Math.toIntExact(SequenceNumbers.NO_OPS_PERFORMED), Math.toIntExact(primaryShard.getGlobalCheckpoint()));
752+
primaryShard.updateGlobalCheckpointForShard(replicaAllocationId, replicaGlobalCheckpoint);
754753

755754
// simulate a background maybe sync; it should only run if the knowledge on the replica of the global checkpoint lags the primary
756755
primaryShard.maybeSyncGlobalCheckpoint("test");

0 commit comments

Comments
 (0)