Skip to content

Commit b727a60

Browse files
authored
Add an escape hatch to increase the maximum amount of memory that IndexWriter gets. (#31133)
Relates #31105
1 parent c29e9e8 commit b727a60

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

core/src/main/java/org/elasticsearch/index/engine/EngineConfig.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.common.settings.Setting.Property;
3232
import org.elasticsearch.common.unit.ByteSizeUnit;
3333
import org.elasticsearch.common.unit.ByteSizeValue;
34+
import org.elasticsearch.common.unit.MemorySizeValue;
3435
import org.elasticsearch.common.unit.TimeValue;
3536
import org.elasticsearch.index.IndexSettings;
3637
import org.elasticsearch.index.codec.CodecService;
@@ -129,10 +130,19 @@ public EngineConfig(OpenMode openMode, ShardId shardId, ThreadPool threadPool,
129130
this.codecService = codecService;
130131
this.eventListener = eventListener;
131132
codecName = indexSettings.getValue(INDEX_CODEC_SETTING);
132-
// We give IndexWriter a "huge" (256 MB) buffer, so it won't flush on its own unless the ES indexing buffer is also huge and/or
133-
// there are not too many shards allocated to this node. Instead, IndexingMemoryController periodically checks
134-
// and refreshes the most heap-consuming shards when total indexing heap usage across all shards is too high:
135-
indexingBufferSize = new ByteSizeValue(256, ByteSizeUnit.MB);
133+
// We add an escape hatch to allow users to configure larger indexing
134+
// buffers if necessary. The default 256MB proved to be too little for
135+
// users with lots of fields.
136+
final String escapeHatchProperty = "es.index.memory.max_index_buffer_size";
137+
String maxBufferSize = System.getProperty(escapeHatchProperty);
138+
if (maxBufferSize != null) {
139+
indexingBufferSize = MemorySizeValue.parseBytesSizeValueOrHeapRatio(maxBufferSize, escapeHatchProperty);
140+
} else {
141+
// We give IndexWriter a "huge" (256 MB) buffer, so it won't flush on its own unless the ES indexing buffer is also huge and/or
142+
// there are not too many shards allocated to this node. Instead, IndexingMemoryController periodically checks
143+
// and refreshes the most heap-consuming shards when total indexing heap usage across all shards is too high:
144+
indexingBufferSize = new ByteSizeValue(256, ByteSizeUnit.MB);
145+
}
136146
this.translogRecoveryPerformer = translogRecoveryPerformer;
137147
this.queryCache = queryCache;
138148
this.queryCachingPolicy = queryCachingPolicy;

0 commit comments

Comments
 (0)