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
This commit is contained in:
Nhat Nguyen 2020-02-12 11:06:11 -05:00
parent d7fe135d90
commit a92bf5ec61
1 changed files with 2 additions and 1 deletions

View File

@ -368,8 +368,8 @@ public class IndexShardIT extends ESSingleNodeTestCase {
assertFalse(shard.shouldPeriodicallyFlush());
assertThat(shard.flushStats().getPeriodic(), greaterThan(0L));
});
shard.sync();
assertEquals(0, translog.stats().getUncommittedOperations());
translog.sync();
long size = Math.max(translog.stats().getUncommittedSizeInBytes(), Translog.DEFAULT_HEADER_SIZE_IN_BYTES + 1);
logger.info("--> current translog size: [{}] num_ops [{}] generation [{}]",
translog.stats().getUncommittedSizeInBytes(), translog.stats().getUncommittedOperations(), translog.getGeneration());
@ -388,6 +388,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
commitStats.getUserData(), flushStats.getPeriodic(), flushStats.getTotal());
assertFalse(shard.shouldPeriodicallyFlush());
});
shard.sync();
assertEquals(0, translog.stats().getUncommittedOperations());
}