Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.internal.hppc.IntHashSet;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.util.FeatureFlag;

import java.io.IOException;
import java.util.function.IntConsumer;
Expand All @@ -34,8 +33,6 @@
* {@link org.apache.lucene.codecs.lucene90.blocktree.FieldReader} keeps an in-memory reference to the min and max term.
*/
public class TrackingPostingsInMemoryBytesCodec extends FilterCodec {
public static final FeatureFlag TRACK_POSTINGS_IN_MEMORY_BYTES = new FeatureFlag("track_postings_in_memory_bytes");

public static final String IN_MEMORY_POSTINGS_BYTES_KEY = "es.postings.in_memory_bytes";

public TrackingPostingsInMemoryBytesCodec(Codec delegate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.SubscribableListener;
import org.elasticsearch.action.support.UnsafePlainActionFuture;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterApplierService;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.Loggers;
Expand Down Expand Up @@ -266,7 +267,8 @@ protected final DocsStats docsStats(IndexReader indexReader) {
*/
public ShardFieldStats shardFieldStats() {
try (var searcher = acquireSearcher("shard_field_stats", Engine.SearcherScope.INTERNAL)) {
return shardFieldStats(searcher.getLeafContexts());
boolean isStateless = DiscoveryNode.isStateless(engineConfig.getIndexSettings().getNodeSettings());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we turn this into a field in Engine? Then there is no need to read the node settings every time this method gets invoked.

return shardFieldStats(searcher.getLeafContexts(), isStateless);
}
}

Expand All @@ -279,7 +281,7 @@ public FieldInfos shardFieldInfos() {
}
}

protected static ShardFieldStats shardFieldStats(List<LeafReaderContext> leaves) {
protected static ShardFieldStats shardFieldStats(List<LeafReaderContext> leaves, boolean isStateless) {
int numSegments = 0;
int totalFields = 0;
long usages = 0;
Expand All @@ -296,7 +298,7 @@ protected static ShardFieldStats shardFieldStats(List<LeafReaderContext> leaves)
} else {
usages = -1;
}
boolean trackPostingsMemoryEnabled = TrackingPostingsInMemoryBytesCodec.TRACK_POSTINGS_IN_MEMORY_BYTES.isEnabled();
boolean trackPostingsMemoryEnabled = isStateless;
boolean trackLiveDocsMemoryEnabled = ShardFieldStats.TRACK_LIVE_DOCS_IN_MEMORY_BYTES.isEnabled();
if (trackLiveDocsMemoryEnabled || trackPostingsMemoryEnabled) {
SegmentReader segmentReader = Lucene.tryUnwrapSegmentReader(leaf.reader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.SubscribableListener;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterApplierService;
import org.elasticsearch.common.ReferenceDocs;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -2807,7 +2808,7 @@ private IndexWriterConfig getIndexWriterConfig() {
iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());

Codec codec = engineConfig.getCodec();
if (TrackingPostingsInMemoryBytesCodec.TRACK_POSTINGS_IN_MEMORY_BYTES.isEnabled()) {
if (DiscoveryNode.isStateless(engineConfig.getIndexSettings().getNodeSettings())) {
codec = new TrackingPostingsInMemoryBytesCodec(codec);
}
iwc.setCodec(codec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.MergePolicyConfig;
import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.codec.TrackingPostingsInMemoryBytesCodec;
import org.elasticsearch.index.engine.CommitStats;
import org.elasticsearch.index.engine.DocIdSeqNoAndSource;
import org.elasticsearch.index.engine.Engine;
Expand Down Expand Up @@ -1887,7 +1886,7 @@ public void testShardFieldStats() throws IOException {
assertThat(stats.fieldUsages(), equalTo(0L));
assertThat(stats.postingsInMemoryBytes(), equalTo(0L));

boolean postingsBytesTrackingEnabled = TrackingPostingsInMemoryBytesCodec.TRACK_POSTINGS_IN_MEMORY_BYTES.isEnabled();
boolean postingsBytesTrackingEnabled = DiscoveryNode.isStateless(shard.indexSettings().getNodeSettings());

// index some documents
int numDocs = between(2, 10);
Expand Down