Skip to content

Commit 0b493e5

Browse files
authored
Fix testSeqNoCollision (#52154)
We roll a new translog generation and trim operations that are above the global checkpoint during primary-replica resync. If the initOperations is empty, then the stale operation on the replica2 will be discarded as it is the only operation in a translog file (since #51905 where we started using the local checkpoint to calculate the minimum required translog generation for recovery). Otherwise, the stale op will be retained along with initOperations but will be skipped in snapshots. Relates #51905 Closes #52148
1 parent 1f144f2 commit 0b493e5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

server/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ public void testRequestFailureReplication() throws Exception {
536536
}
537537
}
538538

539-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/52148")
540539
public void testSeqNoCollision() throws Exception {
541540
try (ReplicationGroup shards = createGroup(2)) {
542541
shards.startAll();
@@ -565,19 +564,21 @@ public void testSeqNoCollision() throws Exception {
565564
assertThat(snapshot.next(), nullValue());
566565
assertThat(snapshot.skippedOperations(), equalTo(0));
567566
}
568-
// Make sure that replica2 receives translog ops (eg. op2) from replica1
569-
// and does not overwrite its stale operation (op1) as it is trimmed.
570567
logger.info("--> Promote replica1 as the primary");
571568
shards.promoteReplicaToPrimary(replica1).get(); // wait until resync completed.
569+
// We roll a new translog generation and trim operations that are above the global checkpoint during primary-replica resync.
570+
// If the `initOperations` is empty, then the stale operation on the replica2 will be discarded as it is the only operation
571+
// in a translog file. Otherwise, the stale op will be retained along with initOperations but will be skipped in snapshot.
572+
int staleOps = initOperations.isEmpty() ? 0 : 1;
572573
shards.index(new IndexRequest(index.getName()).id("d2").source("{}", XContentType.JSON));
573574
final Translog.Operation op2;
574575
try (Translog.Snapshot snapshot = getTranslog(replica2).newSnapshot()) {
575-
assertThat(snapshot.totalOperations(), equalTo(initDocs + 2));
576+
assertThat(snapshot.totalOperations(), equalTo(initDocs + 1 + staleOps));
576577
op2 = snapshot.next();
577578
assertThat(op2.seqNo(), equalTo(op1.seqNo()));
578579
assertThat(op2.primaryTerm(), greaterThan(op1.primaryTerm()));
579580
assertThat("Remaining of snapshot should contain init operations", snapshot, containsOperationsInAnyOrder(initOperations));
580-
assertThat(snapshot.skippedOperations(), equalTo(1));
581+
assertThat(snapshot.skippedOperations(), equalTo(staleOps));
581582
}
582583

583584
// Make sure that peer-recovery transfers all but non-overridden operations.

0 commit comments

Comments
 (0)