Skip to content

Commit 7282460

Browse files
authored
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 loop 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. Relates #23779
1 parent 2d3c2a4 commit 7282460

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

core/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ public final class IndexSettings {
119119
Setting.byteSizeSetting(
120120
"index.translog.generation_threshold_size",
121121
new ByteSizeValue(64, ByteSizeUnit.MB),
122+
/*
123+
* An empty translog occupies 43 bytes on disk. If the generation threshold is
124+
* below this, the flush thread can get stuck in an infinite loop repeatedly
125+
* rolling the generation as every new generation will already exceed the
126+
* generation threshold. However, small thresholds are useful for testing so we
127+
* do not add a large lower bound here.
128+
*/
129+
new ByteSizeValue(64, ByteSizeUnit.BYTES),
130+
new ByteSizeValue(Long.MAX_VALUE, ByteSizeUnit.BYTES),
122131
new Property[]{Property.Dynamic, Property.IndexScope});
123132

124133
public static final Setting<TimeValue> INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL =

core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void testMaybeFlush() throws Exception {
364364
}
365365

366366
public void testMaybeRollTranslogGeneration() throws Exception {
367-
final int generationThreshold = randomIntBetween(1, 512);
367+
final int generationThreshold = randomIntBetween(64, 512);
368368
final Settings settings =
369369
Settings
370370
.builder()
@@ -380,7 +380,8 @@ public void testMaybeRollTranslogGeneration() throws Exception {
380380
int rolls = 0;
381381
final Translog translog = shard.getEngine().getTranslog();
382382
final long generation = translog.currentFileGeneration();
383-
for (int i = 0; i < randomIntBetween(32, 128); i++) {
383+
final int numberOfDocuments = randomIntBetween(32, 128);
384+
for (int i = 0; i < numberOfDocuments; i++) {
384385
assertThat(translog.currentFileGeneration(), equalTo(generation + rolls));
385386
final ParsedDocument doc = testParsedDocument(
386387
"1",

0 commit comments

Comments
 (0)