44
44
import org .elasticsearch .action .support .PlainActionFuture ;
45
45
import org .elasticsearch .action .support .SubscribableListener ;
46
46
import org .elasticsearch .action .support .UnsafePlainActionFuture ;
47
+ import org .elasticsearch .cluster .node .DiscoveryNode ;
47
48
import org .elasticsearch .cluster .service .ClusterApplierService ;
48
49
import org .elasticsearch .common .bytes .BytesReference ;
49
50
import org .elasticsearch .common .logging .Loggers ;
@@ -161,6 +162,8 @@ public abstract class Engine implements Closeable {
161
162
private final RefCounted ensureOpenRefs = AbstractRefCounted .of (() -> drainOnCloseListener .onResponse (null ));
162
163
private final Releasable releaseEnsureOpenRef = ensureOpenRefs ::decRef ; // reuse this to avoid allocation for each op
163
164
165
+ private final boolean isStateless ;
166
+
164
167
/*
165
168
* on {@code lastWriteNanos} we use System.nanoTime() to initialize this since:
166
169
* - 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) {
189
192
this .pauseIndexingOnThrottle = IndexingMemoryController .PAUSE_INDEXING_ON_THROTTLE .get (
190
193
engineConfig .getIndexSettings ().getSettings ()
191
194
);
195
+
196
+ this .isStateless = DiscoveryNode .isStateless (engineConfig .getIndexSettings ().getNodeSettings ());
192
197
}
193
198
194
199
/**
@@ -266,7 +271,7 @@ protected final DocsStats docsStats(IndexReader indexReader) {
266
271
*/
267
272
public ShardFieldStats shardFieldStats () {
268
273
try (var searcher = acquireSearcher ("shard_field_stats" , Engine .SearcherScope .INTERNAL )) {
269
- return shardFieldStats (searcher .getLeafContexts ());
274
+ return shardFieldStats (searcher .getLeafContexts (), isStateless );
270
275
}
271
276
}
272
277
@@ -279,7 +284,7 @@ public FieldInfos shardFieldInfos() {
279
284
}
280
285
}
281
286
282
- protected static ShardFieldStats shardFieldStats (List <LeafReaderContext > leaves ) {
287
+ protected static ShardFieldStats shardFieldStats (List <LeafReaderContext > leaves , boolean isStateless ) {
283
288
int numSegments = 0 ;
284
289
int totalFields = 0 ;
285
290
long usages = 0 ;
@@ -296,7 +301,7 @@ protected static ShardFieldStats shardFieldStats(List<LeafReaderContext> leaves)
296
301
} else {
297
302
usages = -1 ;
298
303
}
299
- boolean trackPostingsMemoryEnabled = TrackingPostingsInMemoryBytesCodec . TRACK_POSTINGS_IN_MEMORY_BYTES . isEnabled () ;
304
+ boolean trackPostingsMemoryEnabled = isStateless ;
300
305
boolean trackLiveDocsMemoryEnabled = ShardFieldStats .TRACK_LIVE_DOCS_IN_MEMORY_BYTES .isEnabled ();
301
306
if (trackLiveDocsMemoryEnabled || trackPostingsMemoryEnabled ) {
302
307
SegmentReader segmentReader = Lucene .tryUnwrapSegmentReader (leaf .reader ());
0 commit comments