Skip to content

Commit 6c9bdb8

Browse files
authored
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 6b62ec5 commit 6c9bdb8

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ public void testMaybeFlush() throws Exception {
349349
assertFalse(shard.shouldPeriodicallyFlush());
350350
assertThat(shard.flushStats().getPeriodic(), greaterThan(0L));
351351
});
352+
shard.sync();
352353
assertEquals(0, translog.stats().getUncommittedOperations());
353-
translog.sync();
354354
long size = Math.max(translog.stats().getUncommittedSizeInBytes(), Translog.DEFAULT_HEADER_SIZE_IN_BYTES + 1);
355355
logger.info("--> current translog size: [{}] num_ops [{}] generation [{}]",
356356
translog.stats().getUncommittedSizeInBytes(), translog.stats().getUncommittedOperations(), translog.getGeneration());
@@ -369,6 +369,7 @@ public void testMaybeFlush() throws Exception {
369369
commitStats.getUserData(), flushStats.getPeriodic(), flushStats.getTotal());
370370
assertFalse(shard.shouldPeriodicallyFlush());
371371
});
372+
shard.sync();
372373
assertEquals(0, translog.stats().getUncommittedOperations());
373374
}
374375

0 commit comments

Comments
 (0)