All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.solr.search.stats.ExactSharedStatsCache Maven / Gradle / Ivy

There is a newer version: 9.7.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.solr.search.stats;

import java.lang.invoke.MethodHandles;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SolrQueryRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class implements exact caching of statistics. It requires an additional round-trip to parse
 * query at shard servers, and return term statistics for query terms (and collection statistics for
 * term fields).
 *
 * 

Global statistics are accumulated in the instance of this component (with the same life-cycle * as SolrSearcher), in unbounded maps. NOTE: This may lead to excessive memory usage, in which case * a {@link LRUStatsCache} should be considered. */ public class ExactSharedStatsCache extends ExactStatsCache { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // local stats obtained from shard servers private final Map> perShardTermStats = new ConcurrentHashMap<>(); private final Map> perShardColStats = new ConcurrentHashMap<>(); // global stats synchronized from the leader private final Map currentGlobalTermStats = new ConcurrentHashMap<>(); private final Map currentGlobalColStats = new ConcurrentHashMap<>(); @Override protected StatsSource doGet(SolrQueryRequest req) { if (log.isDebugEnabled()) { log.debug("total={}, cache {}", currentGlobalColStats, currentGlobalTermStats.size()); } return new ExactStatsSource(statsCacheMetrics, currentGlobalTermStats, currentGlobalColStats); } @Override public void clear() { super.clear(); perShardTermStats.clear(); perShardColStats.clear(); currentGlobalTermStats.clear(); currentGlobalColStats.clear(); } @Override protected void addToPerShardColStats( SolrQueryRequest req, String shard, Map colStats) { perShardColStats.put(shard, colStats); } @Override protected void printStats(SolrQueryRequest req) { log.debug("perShardColStats={}, perShardTermStats={}", perShardColStats, perShardTermStats); } @Override protected void addToPerShardTermStats( SolrQueryRequest req, String shard, String termStatsString) { Map termStats = StatsUtil.termStatsMapFromString(termStatsString); if (termStats != null) { perShardTermStats.put(shard, termStats); } } @Override protected Map getPerShardColStats(ResponseBuilder rb, String shard) { return perShardColStats.get(shard); } @Override protected TermStats getPerShardTermStats(SolrQueryRequest req, String t, String shard) { Map cache = perShardTermStats.get(shard); return (cache != null) ? cache.get(t) : null; // Term doesn't exist in shard; } @Override protected void addToGlobalColStats(SolrQueryRequest req, Entry e) { currentGlobalColStats.put(e.getKey(), e.getValue()); } @Override protected void addToGlobalTermStats(SolrQueryRequest req, Entry e) { currentGlobalTermStats.put(e.getKey(), e.getValue()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy