From 85ef83242fb300e43a4990807b7b924f7f82948a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 28 Mar 2017 13:37:15 -0400 Subject: [PATCH] Add lower bound for translog generation threshold The translog already occupies 43 bytes on disk when empty. If the translog generation threshold is below this, the flush thread can get stuck in an infinite repeatedly rolling the generation. This commit adds a lower bound on the translog generation to avoid this problem, however we keep the lower bound small for convenience in testing. --- .../main/java/org/elasticsearch/index/IndexSettings.java | 9 +++++++++ .../java/org/elasticsearch/index/shard/IndexShardIT.java | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index 599fea1823800..4ae16255d5e97 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -119,6 +119,15 @@ public final class IndexSettings { Setting.byteSizeSetting( "index.translog.generation_threshold_size", new ByteSizeValue(64, ByteSizeUnit.MB), + /* + * An empty translog occupies 43 bytes on disk. If the generation threshold is + * below this, the flush thread can get stuck in an infinite loop repeatedly + * rolling the generation as every new generation will already exceed the + * generation threshold. However, small thresholds are useful for testing so we + * do not add a large lower bound here. + */ + new ByteSizeValue(64, ByteSizeUnit.BYTES), + new ByteSizeValue(Long.MAX_VALUE, ByteSizeUnit.BYTES), new Property[]{Property.Dynamic, Property.IndexScope}); public static final Setting INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL = diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index ff5556089d28d..3313736ffcfe3 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -364,7 +364,7 @@ public void testMaybeFlush() throws Exception { } public void testMaybeRollTranslogGeneration() throws Exception { - final int generationThreshold = randomIntBetween(1, 512); + final int generationThreshold = randomIntBetween(64, 512); final Settings settings = Settings .builder() @@ -380,7 +380,8 @@ public void testMaybeRollTranslogGeneration() throws Exception { int rolls = 0; final Translog translog = shard.getEngine().getTranslog(); final long generation = translog.currentFileGeneration(); - for (int i = 0; i < randomIntBetween(32, 128); i++) { + final int numberOfDocuments = randomIntBetween(32, 128); + for (int i = 0; i < numberOfDocuments; i++) { assertThat(translog.currentFileGeneration(), equalTo(generation + rolls)); final ParsedDocument doc = testParsedDocument( "1",