Skip to content

Commit ceb7967

Browse files
committed
Fix testSeqNoCollision (elastic#52588)
Adjusts the assertion as we trim translog more eagerly since elastic#52556. Relates elastic#52556 Closes elastic#52148
1 parent 9e12124 commit ceb7967

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ public void testRequestFailureReplication() throws Exception {
543543
}
544544

545545
public void testSeqNoCollision() throws Exception {
546-
try (ReplicationGroup shards = createGroup(2)) {
546+
try (ReplicationGroup shards = createGroup(2, Settings.builder()
547+
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
548+
.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), "-1")
549+
.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), "-1").build())) {
547550
shards.startAll();
548551
int initDocs = shards.indexDocs(randomInt(10));
549552
List<IndexShard> replicas = shards.getReplicas();
@@ -570,19 +573,17 @@ public void testSeqNoCollision() throws Exception {
570573
assertThat(snapshot.next(), nullValue());
571574
assertThat(snapshot.skippedOperations(), equalTo(0));
572575
}
573-
// Make sure that replica2 receives translog ops (eg. op2) from replica1
574-
// and does not overwrite its stale operation (op1) as it is trimmed.
575576
logger.info("--> Promote replica1 as the primary");
576577
shards.promoteReplicaToPrimary(replica1).get(); // wait until resync completed.
577578
shards.index(new IndexRequest(index.getName(), "type", "d2").source("{}", XContentType.JSON));
578579
final Translog.Operation op2;
579580
try (Translog.Snapshot snapshot = getTranslog(replica2).newSnapshot()) {
580-
assertThat(snapshot.totalOperations(), equalTo(initDocs + 2));
581+
assertThat(snapshot.totalOperations(), equalTo(1));
581582
op2 = snapshot.next();
582583
assertThat(op2.seqNo(), equalTo(op1.seqNo()));
583584
assertThat(op2.primaryTerm(), greaterThan(op1.primaryTerm()));
584-
assertThat("Remaining of snapshot should contain init operations", snapshot, containsOperationsInAnyOrder(initOperations));
585-
assertThat(snapshot.skippedOperations(), equalTo(1));
585+
assertNull(snapshot.next());
586+
assertThat(snapshot.skippedOperations(), equalTo(0));
586587
}
587588

588589
// Make sure that peer-recovery transfers all but non-overridden operations.
@@ -591,8 +592,7 @@ public void testSeqNoCollision() throws Exception {
591592
shards.promoteReplicaToPrimary(replica2).get();
592593
logger.info("--> Recover replica3 from replica2");
593594
recoverReplica(replica3, replica2, true);
594-
try (Translog.Snapshot snapshot = replica3.getHistoryOperations(
595-
"test", replica3.indexSettings().isSoftDeleteEnabled() ? Engine.HistorySource.INDEX : Engine.HistorySource.TRANSLOG, 0)) {
595+
try (Translog.Snapshot snapshot = replica3.newChangesSnapshot("test", 0, Long.MAX_VALUE, false)) {
596596
assertThat(snapshot.totalOperations(), equalTo(initDocs + 1));
597597
final List<Translog.Operation> expectedOps = new ArrayList<>(initOperations);
598598
expectedOps.add(op2);

0 commit comments

Comments
 (0)