Skip to content

Commit f28d3c1

Browse files
committed
TEST: Tightens file-based condition in peer-recovery
As a replica always keeps a safe commit and starts peer-recovery with that commit; file-based recovery only happens if new operations are added to the primary and the required translog is not fully retained. In the test, we tried to produce this condition by flushing a new commit in order to trim all translog. However, if the new global checkpoint is not persisted yet, we will keep two commits and not trim translog. This commit tightens the file-based condition in the test by waiting for the global checkpoint persisted properly on the new primary before flushing. Close #28209 Relates #28181
1 parent 8a4d27a commit f28d3c1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ public void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception {
215215
}
216216

217217
@TestLogging("org.elasticsearch.index.shard:TRACE,org.elasticsearch.indices.recovery:TRACE")
218-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/28209")
219218
public void testRecoveryAfterPrimaryPromotion() throws Exception {
220219
try (ReplicationGroup shards = createGroup(2)) {
221220
shards.startAll();
@@ -268,7 +267,12 @@ public void testRecoveryAfterPrimaryPromotion() throws Exception {
268267
);
269268
newPrimary.indexSettings().updateIndexMetaData(builder.build());
270269
newPrimary.onSettingsChanged();
271-
shards.syncGlobalCheckpoint();
270+
// Make sure the global checkpoint on the new primary is persisted properly,
271+
// otherwise the deletion policy won't trim translog
272+
assertBusy(() -> {
273+
shards.syncGlobalCheckpoint();
274+
assertThat(newPrimary.getTranslog().getLastSyncedGlobalCheckpoint(), equalTo(newPrimary.seqNoStats().getMaxSeqNo()));
275+
});
272276
newPrimary.flush(new FlushRequest());
273277
uncommittedOpsOnPrimary = shards.indexDocs(randomIntBetween(0, 10));
274278
totalDocs += uncommittedOpsOnPrimary;

0 commit comments

Comments
 (0)