@@ -160,48 +160,6 @@ public QueryCacheStats getStats(ShardId shard, long precomputedSharedRamBytesUse
160160 return queryCacheStats ;
161161 }
162162
163- /**
164- * Precompute the shared RAM split for all shards, returning a map of ShardId to the additional shared RAM bytes used.
165- * This avoids O(N^2) when collecting stats for all shards.
166- */
167- public Map <ShardId , Long > computeAllShardSharedRamBytesUsed () {
168- Map <ShardId , Long > result = new HashMap <>();
169- if (sharedRamBytesUsed == 0L ) {
170- for (ShardId shardId : shardStats .keySet ()) {
171- result .put (shardId , 0L );
172- }
173- return result ;
174- }
175- long totalSize = 0L ;
176- int shardCount = 0 ;
177- boolean anyNonZero = false ;
178- for (Stats stats : shardStats .values ()) {
179- shardCount += 1 ;
180- if (stats .cacheSize > 0L ) {
181- anyNonZero = true ;
182- totalSize += stats .cacheSize ;
183- }
184- }
185- if (shardCount == 0 ) {
186- return result ;
187- }
188- if (anyNonZero == false ) {
189- // All shards have zero cache footprint, apportion equally
190- long perShard = Math .round ((double ) sharedRamBytesUsed / shardCount );
191- for (ShardId shardId : shardStats .keySet ()) {
192- result .put (shardId , perShard );
193- }
194- } else {
195- // Apportion proportionally to cache footprint
196- for (Map .Entry <ShardId , Stats > entry : shardStats .entrySet ()) {
197- long cacheSize = entry .getValue ().cacheSize ;
198- long ram = (totalSize == 0 ) ? 0L : Math .round ((double ) sharedRamBytesUsed * cacheSize / totalSize );
199- result .put (entry .getKey (), ram );
200- }
201- }
202- return result ;
203- }
204-
205163 @ Override
206164 public Weight doCache (Weight weight , QueryCachingPolicy policy ) {
207165 while (weight instanceof CachingWeightWrapper ) {
0 commit comments