@@ -730,12 +730,12 @@ public void testGlobalCheckpointSync() throws IOException {
730
730
final IndexMetaData .Builder indexMetadata = IndexMetaData .builder (shardRouting .getIndexName ()).settings (settings ).primaryTerm (0 , 1 );
731
731
final AtomicBoolean synced = new AtomicBoolean ();
732
732
final IndexShard primaryShard = newShard (shardRouting , indexMetadata .build (), null , null , () -> { synced .set (true ); });
733
- // add a replicas
733
+ // add a replica
734
734
recoverShardFromStore (primaryShard );
735
735
final IndexShard replicaShard = newShard (shardId , false );
736
736
recoverReplica (replicaShard , primaryShard );
737
737
final int maxSeqNo = randomIntBetween (0 , 128 );
738
- for (int i = 0 ; i < maxSeqNo ; i ++) {
738
+ for (int i = 0 ; i <= maxSeqNo ; i ++) {
739
739
primaryShard .getEngine ().seqNoService ().generateSeqNo ();
740
740
}
741
741
final long checkpoint = rarely () ? maxSeqNo - scaledRandomIntBetween (0 , maxSeqNo ) : maxSeqNo ;
@@ -746,11 +746,10 @@ public void testGlobalCheckpointSync() throws IOException {
746
746
final String replicaAllocationId = replicaShard .routingEntry ().allocationId ().getId ();
747
747
primaryShard .updateLocalCheckpointForShard (replicaAllocationId , replicaLocalCheckpoint );
748
748
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 );
754
753
755
754
// simulate a background maybe sync; it should only run if the knowledge on the replica of the global checkpoint lags the primary
756
755
primaryShard .maybeSyncGlobalCheckpoint ("test" );
0 commit comments