diff --git a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index 43a5ca8fd98e6..6c6752de7d2d4 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -1390,18 +1390,19 @@ public boolean shouldPeriodicallyFlush() { return false; } /* - * We flush to reduce the size of uncommitted translog but strictly speaking the uncommitted size won't always be below - * the threshold after a flush. An endless loop may occur when the uncommitted size is close to the flush threshold, - * the current generation is also close to the generation threshold, and an index is faster and rolls a new generation. + * We flush to reduce the size of uncommitted translog but strictly speaking the uncommitted size won't always be + * below the flush-threshold after a flush. To avoid getting into an endless loop of flushing, we only enable the + * periodically flush condition if this condition is disabled after a flush. The condition will change if the new + * commit points to the later generation the last commit's(eg. gen-of-last-commit < gen-of-new-commit)[1]. * - * Avoid getting into an endless loop of flushing, we only enable the periodically flush condition if this condition is disabled - * after a flush. The condition will change if the new commit points to the later generation the last commit's. - * Or if the local checkpoint equals to max_seqno and translogGenerationOfLastCommit equals to translogGenerationOfNewCommit, - * we know that the last generation must contain operations because its size is above the flush threshold and - * the flush threshold is guaranteed to be higher than an empty translog by the setting validation. - * This guarantees that the new commit will point to the newly rolled generation. + * When the local checkpoint equals to max_seqno, and translog-gen of the last commit equals to translog-gen of + * the new commit, we know that the last generation must contain operations because its size is above the flush + * threshold and the flush-threshold is guaranteed to be higher than an empty translog by the setting validation. + * This guarantees that the new commit will point to the newly rolled generation. In fact, this scenario only + * happens when the generation-threshold is close to or above the flush-threshold; otherwise we have rolled + * generations as the generation-threshold was reached, then the first condition (eg. [1]) is already satisfied. * - * This method is to maintain translog only, thus the IndexWriter#hasUncommittedChanges condition is not considered. + * This method is to maintain translog only, thus IndexWriter#hasUncommittedChanges condition is not considered. */ final long translogGenerationOfNewCommit = translog.getMinGenerationForSeqNo(localCheckpointTracker.getCheckpoint() + 1).translogFileGeneration;