4444import org .elasticsearch .action .support .PlainActionFuture ;
4545import org .elasticsearch .action .support .SubscribableListener ;
4646import org .elasticsearch .action .support .UnsafePlainActionFuture ;
47+ import org .elasticsearch .cluster .node .DiscoveryNode ;
4748import org .elasticsearch .cluster .service .ClusterApplierService ;
4849import org .elasticsearch .common .bytes .BytesReference ;
4950import org .elasticsearch .common .logging .Loggers ;
@@ -161,6 +162,8 @@ public abstract class Engine implements Closeable {
161162 private final RefCounted ensureOpenRefs = AbstractRefCounted .of (() -> drainOnCloseListener .onResponse (null ));
162163 private final Releasable releaseEnsureOpenRef = ensureOpenRefs ::decRef ; // reuse this to avoid allocation for each op
163164
165+ private final boolean isStateless ;
166+
164167 /*
165168 * on {@code lastWriteNanos} we use System.nanoTime() to initialize this since:
166169 * - we use the value for figuring out if the shard / engine is active so if we startup and no write has happened yet we still
@@ -189,6 +192,8 @@ protected Engine(EngineConfig engineConfig) {
189192 this .pauseIndexingOnThrottle = IndexingMemoryController .PAUSE_INDEXING_ON_THROTTLE .get (
190193 engineConfig .getIndexSettings ().getSettings ()
191194 );
195+
196+ this .isStateless = DiscoveryNode .isStateless (engineConfig .getIndexSettings ().getNodeSettings ());
192197 }
193198
194199 /**
@@ -266,7 +271,7 @@ protected final DocsStats docsStats(IndexReader indexReader) {
266271 */
267272 public ShardFieldStats shardFieldStats () {
268273 try (var searcher = acquireSearcher ("shard_field_stats" , Engine .SearcherScope .INTERNAL )) {
269- return shardFieldStats (searcher .getLeafContexts ());
274+ return shardFieldStats (searcher .getLeafContexts (), isStateless );
270275 }
271276 }
272277
@@ -279,7 +284,7 @@ public FieldInfos shardFieldInfos() {
279284 }
280285 }
281286
282- protected static ShardFieldStats shardFieldStats (List <LeafReaderContext > leaves ) {
287+ protected static ShardFieldStats shardFieldStats (List <LeafReaderContext > leaves , boolean isStateless ) {
283288 int numSegments = 0 ;
284289 int totalFields = 0 ;
285290 long usages = 0 ;
@@ -296,7 +301,7 @@ protected static ShardFieldStats shardFieldStats(List<LeafReaderContext> leaves)
296301 } else {
297302 usages = -1 ;
298303 }
299- boolean trackPostingsMemoryEnabled = TrackingPostingsInMemoryBytesCodec . TRACK_POSTINGS_IN_MEMORY_BYTES . isEnabled () ;
304+ boolean trackPostingsMemoryEnabled = isStateless ;
300305 boolean trackLiveDocsMemoryEnabled = ShardFieldStats .TRACK_LIVE_DOCS_IN_MEMORY_BYTES .isEnabled ();
301306 if (trackLiveDocsMemoryEnabled || trackPostingsMemoryEnabled ) {
302307 SegmentReader segmentReader = Lucene .tryUnwrapSegmentReader (leaf .reader ());
0 commit comments