Fix testSeqNoCollision (#52588)

Adjusts the assertion as we trim translog more eagerly since #52556.

Relates #52556
Closes #52148
This commit is contained in:
Nhat Nguyen 2020-02-20 14:29:48 -05:00
parent 87e765609e
commit 0a15a6bfad
1 changed files with 8 additions and 8 deletions

View File

@ -543,7 +543,10 @@ public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase
}
public void testSeqNoCollision() throws Exception {
try (ReplicationGroup shards = createGroup(2)) {
try (ReplicationGroup shards = createGroup(2, Settings.builder()
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), "-1")
.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), "-1").build())) {
shards.startAll();
int initDocs = shards.indexDocs(randomInt(10));
List<IndexShard> replicas = shards.getReplicas();
@ -570,19 +573,17 @@ public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase
assertThat(snapshot.next(), nullValue());
assertThat(snapshot.skippedOperations(), equalTo(0));
}
// Make sure that replica2 receives translog ops (eg. op2) from replica1
// and does not overwrite its stale operation (op1) as it is trimmed.
logger.info("--> Promote replica1 as the primary");
shards.promoteReplicaToPrimary(replica1).get(); // wait until resync completed.
shards.index(new IndexRequest(index.getName(), "type", "d2").source("{}", XContentType.JSON));
final Translog.Operation op2;
try (Translog.Snapshot snapshot = getTranslog(replica2).newSnapshot()) {
assertThat(snapshot.totalOperations(), equalTo(initDocs + 2));
assertThat(snapshot.totalOperations(), equalTo(1));
op2 = snapshot.next();
assertThat(op2.seqNo(), equalTo(op1.seqNo()));
assertThat(op2.primaryTerm(), greaterThan(op1.primaryTerm()));
assertThat("Remaining of snapshot should contain init operations", snapshot, containsOperationsInAnyOrder(initOperations));
assertThat(snapshot.skippedOperations(), equalTo(1));
assertNull(snapshot.next());
assertThat(snapshot.skippedOperations(), equalTo(0));
}
// Make sure that peer-recovery transfers all but non-overridden operations.
@ -591,8 +592,7 @@ public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase
shards.promoteReplicaToPrimary(replica2).get();
logger.info("--> Recover replica3 from replica2");
recoverReplica(replica3, replica2, true);
try (Translog.Snapshot snapshot = replica3.getHistoryOperations(
"test", replica3.indexSettings().isSoftDeleteEnabled() ? Engine.HistorySource.INDEX : Engine.HistorySource.TRANSLOG, 0)) {
try (Translog.Snapshot snapshot = replica3.newChangesSnapshot("test", 0, Long.MAX_VALUE, false)) {
assertThat(snapshot.totalOperations(), equalTo(initDocs + 1));
final List<Translog.Operation> expectedOps = new ArrayList<>(initOperations);
expectedOps.add(op2);