Class StatsCache
- All Implemented Interfaces:
AutoCloseable,SolrInfoBean,SolrMetricProducer,PluginInfoInitialized
- Direct Known Subclasses:
ExactStatsCache,LocalStatsCache
There are instances of this class at the aggregator node (where the partial data from shards is aggregated), and on each core involved in a shard request (where this data is maintained and updated from the aggregator's cache).
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoBean
SolrInfoBean.Category, SolrInfoBean.Group -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringValue ofCollectionStats.static final StringList of fields in the query.protected PluginInfoprotected StatsCache.StatsCacheMetricsstatic final StringMap of terms andTermStats.static final StringList of terms in the query.Fields inherited from interface org.apache.solr.metrics.SolrMetricProducer
CATEGORY_ATTR, HANDLER_ATTR, NAME_ATTR, OPERATION_ATTR, PLUGIN_NAME_ATTR, RESULT_ATTR, TYPE_ATTR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintapproxCheckMissingStats(ResponseBuilder rb, StatsSource statsSource, Consumer<org.apache.lucene.index.Term> missingTermStats, Consumer<String> missingFieldStats) Check if thestatsSourceis missing some term or field statistics info, which then needs to be retrieved.voidclear()Clear cached statistics.voidclose()Implementations should always callSolrMetricProducer.super.close()to ensure that metrics with the same life-cycle as this component are properly unregistered.protected abstract StatsSourcedoGet(SolrQueryRequest req) protected abstract voiddoMergeToGlobalStats(SolrQueryRequest req, List<ShardResponse> responses) protected abstract voidprotected abstract ShardRequestprotected abstract voiddoReturnLocalStats(ResponseBuilder rb, SolrIndexSearcher searcher) protected abstract voiddoSendGlobalStats(ResponseBuilder rb, ShardRequest outgoing) get(SolrQueryRequest req) Prepare aStatsSourcethat provides stats information to perform local scoring (to be precise, to build a localWeightfrom the query).Category of this componentSimple one or two line descriptiongetName()Simple common usage name, e.g.Implementations should return the context used inSolrMetricProducer.initializeMetrics(SolrMetricsContext, Attributes)to ensure proper cleanup of metrics at the end of the life-cycle of this component.voidinit(PluginInfo info) voidinitializeMetrics(SolrMetricsContext solrMetricsContext, io.opentelemetry.api.common.Attributes attributes) Implementation should initialize all metrics to aSolrMetricsContextRegistry/MeterProvider withAttributesas the common set of attributes that will be attached to every metric that is initialized for that class/componentvoidmergeToGlobalStats(SolrQueryRequest req, List<ShardResponse> responses) Process shard responses that contain partial local stats.voidReceive global stats data from the leader and update a local cache of global stats with this global data.Creates aShardRequestto retrieve per-shard stats related to the current query and the current state of the requester'sStatsCache.voidreturnLocalStats(ResponseBuilder rb, SolrIndexSearcher searcher) Prepare a local (from the local shard) response to a "retrieve stats" shard request.voidsendGlobalStats(ResponseBuilder rb, ShardRequest outgoing) Prepare global stats data to be sent out to shards in this request.
-
Field Details
-
TERM_STATS_KEY
Map of terms andTermStats.- See Also:
-
COL_STATS_KEY
Value ofCollectionStats.- See Also:
-
TERMS_KEY
List of terms in the query.- See Also:
-
FIELDS_KEY
List of fields in the query.- See Also:
-
statsCacheMetrics
-
pluginInfo
-
-
Constructor Details
-
StatsCache
public StatsCache()
-
-
Method Details
-
getCacheMetrics
-
init
- Specified by:
initin interfacePluginInfoInitialized
-
retrieveStatsRequest
Creates aShardRequestto retrieve per-shard stats related to the current query and the current state of the requester'sStatsCache.This method updates the cache metrics and calls
doRetrieveStatsRequest(ResponseBuilder).- Parameters:
rb- contains current request- Returns:
- shard request to retrieve stats for terms in the current request, or null if no additional request is needed (e.g. if the information in global cache is already sufficient to satisfy this request).
-
doRetrieveStatsRequest
-
returnLocalStats
Prepare a local (from the local shard) response to a "retrieve stats" shard request.This method updates the cache metrics and calls
doReturnLocalStats(ResponseBuilder, SolrIndexSearcher).- Parameters:
rb- response buildersearcher- current local searcher
-
doReturnLocalStats
-
mergeToGlobalStats
Process shard responses that contain partial local stats. Usually this entails combining per-shard stats for each term.This method updates the cache metrics and calls
doMergeToGlobalStats(SolrQueryRequest, List).- Parameters:
req- query requestresponses- responses from shards containing local stats for each shard
-
doMergeToGlobalStats
-
receiveGlobalStats
Receive global stats data from the leader and update a local cache of global stats with this global data. This event occurs either as a separate request, or together with the regular query request, in which case this method is called first, before preparing aQueryCommandto be submitted to the localSolrIndexSearcher.This method updates the cache metrics and calls
doReceiveGlobalStats(SolrQueryRequest).- Parameters:
req- query request with global stats data
-
doReceiveGlobalStats
-
sendGlobalStats
Prepare global stats data to be sent out to shards in this request.This method updates the cache metrics and calls
doSendGlobalStats(ResponseBuilder, ShardRequest).- Parameters:
rb- response builderoutgoing- shard request to be sent
-
doSendGlobalStats
-
get
Prepare aStatsSourcethat provides stats information to perform local scoring (to be precise, to build a localWeightfrom the query).This method updates the cache metrics and calls
doGet(SolrQueryRequest).- Parameters:
req- query request- Returns:
- an instance of
StatsSourceto use in creating a queryWeight
-
doGet
-
clear
public void clear()Clear cached statistics. -
approxCheckMissingStats
public int approxCheckMissingStats(ResponseBuilder rb, StatsSource statsSource, Consumer<org.apache.lucene.index.Term> missingTermStats, Consumer<String> missingFieldStats) throws IOException Check if thestatsSourceis missing some term or field statistics info, which then needs to be retrieved.NOTE: this uses the local IndexReader for query rewriting, which may expand to less (or different) terms as rewriting the same query on other shards' readers. This in turn may falsely fail to inform the consumers about possibly missing stats, which may lead consumers to skip the fetching of full stats. Consequently this would lead to incorrect global IDF data for the missing terms (because for these terms only local stats would be used).
- Parameters:
rb- request to evaluate against the statsSourcestatsSource- stats source to checkmissingTermStats- consumer of missing term statsmissingFieldStats- consumer of missing field stats- Returns:
- approximate number of missing term stats and field stats combined
- Throws:
IOException
-
getName
Description copied from interface:SolrInfoBeanSimple common usage name, e.g. BasicQueryHandler, or fully qualified class name.- Specified by:
getNamein interfaceSolrInfoBean
-
getDescription
Description copied from interface:SolrInfoBeanSimple one or two line description- Specified by:
getDescriptionin interfaceSolrInfoBean
-
getCategory
Description copied from interface:SolrInfoBeanCategory of this component- Specified by:
getCategoryin interfaceSolrInfoBean
-
getSolrMetricsContext
Description copied from interface:SolrMetricProducerImplementations should return the context used inSolrMetricProducer.initializeMetrics(SolrMetricsContext, Attributes)to ensure proper cleanup of metrics at the end of the life-cycle of this component. This should be the child context if one was created, or null if the parent context was used.- Specified by:
getSolrMetricsContextin interfaceSolrMetricProducer
-
initializeMetrics
public void initializeMetrics(SolrMetricsContext solrMetricsContext, io.opentelemetry.api.common.Attributes attributes) Description copied from interface:SolrMetricProducerImplementation should initialize all metrics to aSolrMetricsContextRegistry/MeterProvider withAttributesas the common set of attributes that will be attached to every metric that is initialized for that class/component- Specified by:
initializeMetricsin interfaceSolrMetricProducer- Parameters:
solrMetricsContext- The registry that the component will initialize metrics toattributes- Base set of attributes that will be bound to all metrics for that component
-
close
Description copied from interface:SolrMetricProducerImplementations should always callSolrMetricProducer.super.close()to ensure that metrics with the same life-cycle as this component are properly unregistered. This prevents obscure memory leaks.from: https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html While this interface method is declared to throw Exception, implementers are strongly encouraged to declare concrete implementations of the close method to throw more specific exceptions, or to throw no exception at all if the close operation cannot fail.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSolrMetricProducer- Throws:
IOException
-