Skip to content

Commit 5e9d79f

Browse files
committed
Fix order and beef up test
1 parent 8f74e92 commit 5e9d79f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

core/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,8 @@ public void acquireReplicaOperationPermit(final long operationPrimaryTerm, final
20652065
getLocalCheckpoint(),
20662066
globalCheckpoint,
20672067
globalCheckpoint);
2068-
getEngine().seqNoService().resetLocalCheckpoint(globalCheckpoint);
20692068
updateGlobalCheckpointOnReplica(globalCheckpoint);
2069+
getEngine().seqNoService().resetLocalCheckpoint(getGlobalCheckpoint());
20702070
getEngine().getTranslog().rollGeneration();
20712071
});
20722072
globalCheckpointUpdated = true;

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,19 @@ private void finish() {
692692
closeShards(indexShard);
693693
}
694694

695-
public void testThrowbackLocalCheckpointOnReplica() throws IOException, InterruptedException {
695+
public void testThrowBackLocalCheckpointOnReplica() throws IOException, InterruptedException {
696696
final IndexShard indexShard = newStartedShard(false);
697697

698698
// most of the time this is large enough that most of the time there will be at least one gap
699699
final int operations = 1024 - scaledRandomIntBetween(0, 1024);
700700
indexOnReplicaWithGaps(indexShard, operations, Math.toIntExact(SequenceNumbersService.NO_OPS_PERFORMED));
701701

702+
final long globalCheckpointOnReplica =
703+
randomIntBetween(
704+
Math.toIntExact(SequenceNumbersService.NO_OPS_PERFORMED),
705+
Math.toIntExact(indexShard.getLocalCheckpoint()));
706+
indexShard.updateGlobalCheckpointOnReplica(globalCheckpointOnReplica);
707+
702708
final int globalCheckpoint =
703709
randomIntBetween(
704710
Math.toIntExact(SequenceNumbersService.NO_OPS_PERFORMED),
@@ -721,9 +727,9 @@ public void onFailure(Exception e) {
721727
ThreadPool.Names.SAME);
722728

723729
latch.await();
724-
assertThat(indexShard.getLocalCheckpoint(), equalTo((long) globalCheckpoint));
730+
assertThat(indexShard.getLocalCheckpoint(), equalTo(Math.max(globalCheckpoint, globalCheckpointOnReplica)));
725731

726-
// ensure that after the local checkpoint throwback and indexing again, the local checkpoint advances
732+
// ensure that after the local checkpoint throw back and indexing again, the local checkpoint advances
727733
final Result result = indexOnReplicaWithGaps(indexShard, operations, Math.toIntExact(indexShard.getLocalCheckpoint()));
728734
assertThat(indexShard.getLocalCheckpoint(), equalTo((long) result.localCheckpoint));
729735

0 commit comments

Comments
 (0)