@Override public void onClose(Object key) { CloseableThreadLocal<PerThreadIDAndVersionLookup> ctl = lookupStates.remove(key); if (ctl != null) { ctl.close(); } }
private static PerThreadIDAndVersionLookup getLookupState(LeafReader reader) throws IOException { Object key = reader.getCoreCacheKey(); CloseableThreadLocal<PerThreadIDAndVersionLookup> ctl = lookupStates.get(key); if (ctl == null) { // First time we are seeing this reader's core; make a // new CTL: ctl = new CloseableThreadLocal<>(); CloseableThreadLocal<PerThreadIDAndVersionLookup> other = lookupStates.putIfAbsent(key, ctl); if (other == null) { // Our CTL won, we must remove it when the // core is closed: reader.addCoreClosedListener(removeLookupState); } else { // Another thread beat us to it: just use // their CTL: ctl = other; } } PerThreadIDAndVersionLookup lookupState = ctl.get(); if (lookupState == null) { lookupState = new PerThreadIDAndVersionLookup(reader); ctl.set(lookupState); } return lookupState; }
@Inject public PercolatorService(Settings settings, IndexNameExpressionResolver indexNameExpressionResolver, IndicesService indicesService, PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, HighlightPhase highlightPhase, ClusterService clusterService, AggregationPhase aggregationPhase, ScriptService scriptService, MappingUpdatedAction mappingUpdatedAction) { super(settings); this.indexNameExpressionResolver = indexNameExpressionResolver; this.parseFieldMatcher = new ParseFieldMatcher(settings); this.indicesService = indicesService; this.pageCacheRecycler = pageCacheRecycler; this.bigArrays = bigArrays; this.clusterService = clusterService; this.highlightPhase = highlightPhase; this.aggregationPhase = aggregationPhase; this.scriptService = scriptService; this.mappingUpdatedAction = mappingUpdatedAction; this.sortParseElement = new SortParseElement(); final long maxReuseBytes = settings.getAsBytesSize("indices.memory.memory_index.size_per_thread", new ByteSizeValue(1, ByteSizeUnit.MB)).bytes(); cache = new CloseableThreadLocal<MemoryIndex>() { @Override protected MemoryIndex initialValue() { // TODO: should we expose payloads as an option? should offsets be turned on always? return new ExtendedMemoryIndex(true, false, maxReuseBytes); } }; single = new SingleDocumentPercolatorIndex(cache); multi = new MultiDocumentPercolatorIndex(cache); percolatorTypes = new IntObjectHashMap<>(6); percolatorTypes.put(countPercolator.id(), countPercolator); percolatorTypes.put(queryCountPercolator.id(), queryCountPercolator); percolatorTypes.put(matchPercolator.id(), matchPercolator); percolatorTypes.put(queryPercolator.id(), queryPercolator); percolatorTypes.put(scoringPercolator.id(), scoringPercolator); percolatorTypes.put(topMatchingPercolator.id(), topMatchingPercolator); }
MultiDocumentPercolatorIndex(CloseableThreadLocal<MemoryIndex> cache) { this.cache = cache; }
SingleDocumentPercolatorIndex(CloseableThreadLocal<MemoryIndex> cache) { this.cache = cache; }