Skip to content

Commit 981a876

Browse files
committed
Only load FST off heap if we are actually using mmaps for the term dictionary
Given the significant performance impact that NIOFS has when term dicts are loaded off-heap this change enforces FstLoadMode#AUTO that loads term dicts off heap only if the underlying index input indicates a memory map. Relates to elastic#43150
1 parent 4937471 commit 981a876

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public class ReadOnlyEngine extends Engine {
6767

6868
/**
6969
* Reader attributes used for read only engines. These attributes prevent loading term dictionaries on-heap even if the field is an
70-
* ID field.
70+
* ID field if we are reading form memory maps.
7171
*/
7272
public static final Map<String, String> OFF_HEAP_READER_ATTRIBUTES = Collections.singletonMap(BlockTreeTermsReader.FST_MODE_KEY,
73-
BlockTreeTermsReader.FSTLoadMode.OFF_HEAP.name());
73+
BlockTreeTermsReader.FSTLoadMode.AUTO.name());
7474
private final SegmentInfos lastCommittedSegmentInfos;
7575
private final SeqNoStats seqNoStats;
7676
private final TranslogStats translogStats;

x-pack/plugin/core/src/main/java/org/elasticsearch/snapshots/SourceOnlySnapshot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.snapshots;
77

88
import org.apache.lucene.codecs.Codec;
9+
import org.apache.lucene.codecs.blocktree.BlockTreeTermsReader;
910
import org.apache.lucene.index.CheckIndex;
1011
import org.apache.lucene.index.DirectoryReader;
1112
import org.apache.lucene.index.DocValuesType;
@@ -38,7 +39,6 @@
3839
import org.apache.lucene.util.FixedBitSet;
3940
import org.elasticsearch.common.lucene.Lucene;
4041
import org.elasticsearch.core.internal.io.IOUtils;
41-
import org.elasticsearch.index.engine.ReadOnlyEngine;
4242

4343
import java.io.ByteArrayOutputStream;
4444
import java.io.IOException;
@@ -82,7 +82,7 @@ public synchronized List<String> syncSnapshot(IndexCommit commit) throws IOExcep
8282
String segmentFileName;
8383
try (Lock writeLock = targetDirectory.obtainLock(IndexWriter.WRITE_LOCK_NAME);
8484
StandardDirectoryReader reader = (StandardDirectoryReader) DirectoryReader.open(commit,
85-
ReadOnlyEngine.OFF_HEAP_READER_ATTRIBUTES)) {
85+
Collections.singletonMap(BlockTreeTermsReader.FST_MODE_KEY, BlockTreeTermsReader.FSTLoadMode.OFF_HEAP.name()))) {
8686
SegmentInfos segmentInfos = reader.getSegmentInfos().clone();
8787
DirectoryReader wrappedReader = wrapReader(reader);
8888
List<SegmentCommitInfo> newInfos = new ArrayList<>();

x-pack/plugin/core/src/main/java/org/elasticsearch/snapshots/SourceOnlySnapshotRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.snapshots;
77

88
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
9+
import org.apache.lucene.codecs.blocktree.BlockTreeTermsReader;
910
import org.apache.lucene.index.DirectoryReader;
1011
import org.apache.lucene.index.IndexCommit;
1112
import org.apache.lucene.index.SegmentInfos;
@@ -37,6 +38,7 @@
3738
import java.io.IOException;
3839
import java.io.UncheckedIOException;
3940
import java.nio.file.Path;
41+
import java.util.Collections;
4042
import java.util.Iterator;
4143
import java.util.List;
4244
import java.util.function.Function;
@@ -135,7 +137,8 @@ protected void closeInternal() {
135137
final long maxDoc = segmentInfos.totalMaxDoc();
136138
tempStore.bootstrapNewHistory(maxDoc, maxDoc);
137139
store.incRef();
138-
try (DirectoryReader reader = DirectoryReader.open(tempStore.directory(), ReadOnlyEngine.OFF_HEAP_READER_ATTRIBUTES)) {
140+
try (DirectoryReader reader = DirectoryReader.open(tempStore.directory(),
141+
Collections.singletonMap(BlockTreeTermsReader.FST_MODE_KEY, BlockTreeTermsReader.FSTLoadMode.OFF_HEAP.name()))) {
139142
IndexCommit indexCommit = reader.getIndexCommit();
140143
super.snapshotShard(tempStore, mapperService, snapshotId, indexId, indexCommit, snapshotStatus);
141144
} finally {

0 commit comments

Comments
 (0)