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",