From 6c9bdb83ed04aa398f0ace252ce1a713c6a3cc93 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 12 Feb 2020 11:06:11 -0500 Subject: [PATCH] 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 --- .../test/java/org/elasticsearch/index/shard/IndexShardIT.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index bcec724a72de4..d6079bd7677bb 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -349,8 +349,8 @@ public void testMaybeFlush() throws Exception { 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()); @@ -369,6 +369,7 @@ public void testMaybeFlush() throws Exception { commitStats.getUserData(), flushStats.getPeriodic(), flushStats.getTotal()); assertFalse(shard.shouldPeriodicallyFlush()); }); + shard.sync(); assertEquals(0, translog.stats().getUncommittedOperations()); }