@@ -102,6 +102,24 @@ private static QueryCacheStats toQueryCacheStatsSafe(@Nullable Stats stats) {
102102 return stats == null ? new QueryCacheStats () : stats .toQueryCacheStats ();
103103 }
104104
105+ /** Get usage statistics for the given shard. */
106+ public QueryCacheStats getStats (ShardId shard , long precomputedSharedRamBytesUsed ) {
107+ final QueryCacheStats queryCacheStats = toQueryCacheStatsSafe (shardStats .get (shard ));
108+ queryCacheStats .addRamBytesUsed (precomputedSharedRamBytesUsed );
109+ return queryCacheStats ;
110+ }
111+
112+ @ Override
113+ public Weight doCache (Weight weight , QueryCachingPolicy policy ) {
114+ while (weight instanceof CachingWeightWrapper ) {
115+ weight = ((CachingWeightWrapper ) weight ).in ;
116+ }
117+ final Weight in = cache .doCache (weight , policy );
118+ // We wrap the weight to track the readers it sees and map them with
119+ // the shards they belong to
120+ return new CachingWeightWrapper (in );
121+ }
122+
105123 public static CacheTotals getCacheTotalsForAllShards (IndicesService indicesService ) {
106124 IndicesQueryCache queryCache = indicesService .getIndicesQueryCache ();
107125 boolean hasQueryCache = queryCache != null ;
@@ -149,24 +167,6 @@ public static long getSharedRamSizeForShard(IndicesQueryCache queryCache, IndexS
149167
150168 public record CacheTotals (long totalSize , int shardCount , long sharedRamBytesUsed ) {}
151169
152- /** Get usage statistics for the given shard. */
153- public QueryCacheStats getStats (ShardId shard , long precomputedSharedRamBytesUsed ) {
154- final QueryCacheStats queryCacheStats = toQueryCacheStatsSafe (shardStats .get (shard ));
155- queryCacheStats .addRamBytesUsed (precomputedSharedRamBytesUsed );
156- return queryCacheStats ;
157- }
158-
159- @ Override
160- public Weight doCache (Weight weight , QueryCachingPolicy policy ) {
161- while (weight instanceof CachingWeightWrapper ) {
162- weight = ((CachingWeightWrapper ) weight ).in ;
163- }
164- final Weight in = cache .doCache (weight , policy );
165- // We wrap the weight to track the readers it sees and map them with
166- // the shards they belong to
167- return new CachingWeightWrapper (in );
168- }
169-
170170 private class CachingWeightWrapper extends Weight {
171171
172172 private final Weight in ;
0 commit comments