Skip to content

Commit a92bf5e

Browse files
committed
Fix IndexShardIT#testMaybeFlush (#52247)
Since #51905, we use the local checkpoint of the safe commit to calculate the number of uncommitted operations of a translog stats. If a periodic flush triggered by afterWriteOperation completes before we sync translog, then the last commit is not safe. We also need to sync translog from Engine instead of the translog so that we can advance the safe commit. Relates #51905 Closes #52223
1 parent d7fe135 commit a92bf5e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ public void testMaybeFlush() throws Exception {
368368
assertFalse(shard.shouldPeriodicallyFlush());
369369
assertThat(shard.flushStats().getPeriodic(), greaterThan(0L));
370370
});
371+
shard.sync();
371372
assertEquals(0, translog.stats().getUncommittedOperations());
372-
translog.sync();
373373
long size = Math.max(translog.stats().getUncommittedSizeInBytes(), Translog.DEFAULT_HEADER_SIZE_IN_BYTES + 1);
374374
logger.info("--> current translog size: [{}] num_ops [{}] generation [{}]",
375375
translog.stats().getUncommittedSizeInBytes(), translog.stats().getUncommittedOperations(), translog.getGeneration());
@@ -388,6 +388,7 @@ public void testMaybeFlush() throws Exception {
388388
commitStats.getUserData(), flushStats.getPeriodic(), flushStats.getTotal());
389389
assertFalse(shard.shouldPeriodicallyFlush());
390390
});
391+
shard.sync();
391392
assertEquals(0, translog.stats().getUncommittedOperations());
392393
}
393394

0 commit comments

Comments
 (0)