Class IndicesQueryCache

java.lang.Object
org.elasticsearch.indices.IndicesQueryCache
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.lucene.search.QueryCache

public class IndicesQueryCache extends Object implements org.apache.lucene.search.QueryCache, Closeable
  • Field Details

    • INDICES_CACHE_QUERY_SIZE_SETTING

      public static final Setting<ByteSizeValue> INDICES_CACHE_QUERY_SIZE_SETTING
    • INDICES_CACHE_QUERY_COUNT_SETTING

      public static final Setting<Integer> INDICES_CACHE_QUERY_COUNT_SETTING
    • INDICES_QUERIES_CACHE_ALL_SEGMENTS_SETTING

      public static final Setting<Boolean> INDICES_QUERIES_CACHE_ALL_SEGMENTS_SETTING
  • Constructor Details

    • IndicesQueryCache

      public IndicesQueryCache(Settings settings)
  • Method Details

    • getSharedRamSizeForAllShards

      public static Map<ShardId,Long> getSharedRamSizeForAllShards(IndicesService indicesService)
      Calculates a map of ShardId to Long which contains the calculated share of the IndicesQueryCache shared ram size for a given shard (that is, the sum of all the longs is the size of the indices query cache). Since many shards will not participate in the cache, shards whose calculated share is zero will not be contained in the map at all. As a consequence, the correct pattern for using the returned map will be via Map.getOrDefault(Object, Object) with a defaultValue of 0L.
      Returns:
      an unmodifiable map from ShardId to the calculated share of the query cache's shared RAM size for each shard, omitting shards with a zero share
    • getCacheSizeForShard

      public long getCacheSizeForShard(ShardId shardId)
    • getSharedRamBytesUsed

      public long getSharedRamBytesUsed()
    • getCacheTotalsForAllShards

      public static IndicesQueryCache.CacheTotals getCacheTotalsForAllShards(IndicesService indicesService)
      Computes the total cache size in bytes, and the total shard count in the cache for all shards.
      Parameters:
      indicesService - the IndicesService instance to retrieve cache information from
      Returns:
      A CacheTotals object containing the computed total number of items in the cache and the number of shards seen in the cache
    • getSharedRamSizeForShard

      public long getSharedRamSizeForShard(ShardId shardId, IndicesQueryCache.CacheTotals cacheTotals)
      This method computes the shared RAM size in bytes for the given indexShard.
      Parameters:
      shardId - The shard to compute the shared RAM size for.
      cacheTotals - Shard totals computed in getCacheTotalsForAllShards(IndicesService).
      Returns:
      the shared RAM size in bytes allocated to the given shard, or 0 if unavailable
    • getStats

      public QueryCacheStats getStats(ShardId shard, Supplier<Long> precomputedSharedRamBytesUsed)
      Get usage statistics for the given shard.
    • doCache

      public org.apache.lucene.search.Weight doCache(org.apache.lucene.search.Weight weight, org.apache.lucene.search.QueryCachingPolicy policy)
      Specified by:
      doCache in interface org.apache.lucene.search.QueryCache
    • clearIndex

      public void clearIndex(String index)
      Clear all entries that belong to the given index.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • onClose

      public void onClose(ShardId shardId)