Java Code Examples for org.apache.lucene.index.IndexReader#CacheKey
The following examples show how to use
org.apache.lucene.index.IndexReader#CacheKey .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr File: FieldCacheImpl.java License: Apache License 2.0 | 6 votes |
@Override public synchronized CacheEntry[] getCacheEntries() { List<CacheEntry> result = new ArrayList<>(17); for(final Map.Entry<Class<?>,Cache> cacheEntry: caches.entrySet()) { final Cache cache = cacheEntry.getValue(); final Class<?> cacheType = cacheEntry.getKey(); synchronized(cache.readerCache) { for (final Map.Entry<IndexReader.CacheKey,Map<CacheKey, Accountable>> readerCacheEntry : cache.readerCache.entrySet()) { final IndexReader.CacheKey readerKey = readerCacheEntry.getKey(); if (readerKey == null) continue; final Map<CacheKey, Accountable> innerCache = readerCacheEntry.getValue(); for (final Map.Entry<CacheKey, Accountable> mapEntry : innerCache.entrySet()) { CacheKey entry = mapEntry.getKey(); result.add(new CacheEntry(readerKey, entry.field, cacheType, entry.custom, mapEntry.getValue())); } } } } return result.toArray(new CacheEntry[result.size()]); }
Example 2
Source Project: lucene-solr File: FieldCacheImpl.java License: Apache License 2.0 | 6 votes |
/** Sets the key to the value for the provided reader; * if the key is already set then this doesn't change it. */ public void put(LeafReader reader, CacheKey key, Accountable value) { IndexReader.CacheHelper cacheHelper = reader.getCoreCacheHelper(); if (cacheHelper == null) { throw new IllegalStateException("Cannot cache on " + reader); } final IndexReader.CacheKey readerKey = cacheHelper.getKey(); synchronized (readerCache) { Map<CacheKey,Accountable> innerCache = readerCache.get(readerKey); if (innerCache == null) { // First time this reader is using FieldCache innerCache = new HashMap<>(); readerCache.put(readerKey, innerCache); wrapper.initReader(reader); } if (innerCache.get(key) == null) { innerCache.put(key, value); } else { // Another thread beat us to it; leave the current // value } } }
Example 3
Source Project: lucene-solr File: FieldCache.java License: Apache License 2.0 | 5 votes |
public CacheEntry(IndexReader.CacheKey readerKey, String fieldName, Class<?> cacheType, Object custom, Accountable value) { this.readerKey = readerKey; this.fieldName = fieldName; this.cacheType = cacheType; this.custom = custom; this.value = value; }
Example 4
Source Project: lucene-solr File: FieldCacheImpl.java License: Apache License 2.0 | 5 votes |
public Object get(LeafReader reader, CacheKey key) throws IOException { Map<CacheKey,Accountable> innerCache; Accountable value; IndexReader.CacheHelper cacheHelper = reader.getCoreCacheHelper(); if (cacheHelper == null) { reader.getCoreCacheHelper(); throw new IllegalStateException("Cannot cache on " + reader); } final IndexReader.CacheKey readerKey = cacheHelper.getKey(); synchronized (readerCache) { innerCache = readerCache.get(readerKey); if (innerCache == null) { // First time this reader is using FieldCache innerCache = new HashMap<>(); readerCache.put(readerKey, innerCache); wrapper.initReader(reader); value = null; } else { value = innerCache.get(key); } if (value == null) { value = new CreationPlaceholder(); innerCache.put(key, value); } } if (value instanceof CreationPlaceholder) { synchronized (value) { CreationPlaceholder progress = (CreationPlaceholder) value; if (progress.value == null) { progress.value = createValue(reader, key); synchronized (readerCache) { innerCache.put(key, progress.value); } } return progress.value; } } return value; }
Example 5
Source Project: lucene-solr File: SolrIndexSplitter.java License: Apache License 2.0 | 5 votes |
SplittingQuery(int partition, SchemaField field, DocRouter.Range[] rangesArr, HashBasedRouter hashRouter, String splitKey, Map<IndexReader.CacheKey, FixedBitSet[]> docsToDelete, AtomicInteger currentPartition) { this.partition = partition; this.field = field; this.rangesArr = rangesArr; this.hashRouter = hashRouter; this.splitKey = splitKey; this.docsToDelete = docsToDelete; this.currentPartition = currentPartition; }
Example 6
Source Project: crate File: ShardCoreKeyMap.java License: Apache License 2.0 | 5 votes |
/** * Get the set of core cache keys associated with the given index. */ public synchronized Set<Object> getCoreKeysForIndex(String index) { final Set<IndexReader.CacheKey> objects = indexToCoreKey.get(index); if (objects == null) { return Collections.emptySet(); } // we have to copy otherwise we risk ConcurrentModificationException return Collections.unmodifiableSet(new HashSet<>(objects)); }
Example 7
Source Project: crate File: ShardCoreKeyMap.java License: Apache License 2.0 | 5 votes |
private synchronized boolean assertSize() { if (!Assertions.ENABLED) { throw new AssertionError("only run this if assertions are enabled"); } Collection<Set<IndexReader.CacheKey>> values = indexToCoreKey.values(); int size = 0; for (Set<IndexReader.CacheKey> value : values) { size += value.size(); } return size == coreKeyToShard.size(); }
Example 8
Source Project: lucene-solr File: FieldCacheImpl.java License: Apache License 2.0 | 4 votes |
@Override public synchronized void purgeByCacheKey(IndexReader.CacheKey coreCacheKey) { for(Cache c : caches.values()) { c.purgeByCacheKey(coreCacheKey); } }
Example 9
Source Project: lucene-solr File: FieldCacheImpl.java License: Apache License 2.0 | 4 votes |
/** Remove this reader from the cache, if present. */ public void purgeByCacheKey(IndexReader.CacheKey coreCacheKey) { synchronized(readerCache) { readerCache.remove(coreCacheKey); } }
Example 10
Source Project: lucene-solr File: TestSlowCompositeReaderWrapper.java License: Apache License 2.0 | 4 votes |
@Override public void onClose(IndexReader.CacheKey coreCacheKey) { assertSame(this.coreCacheKey, coreCacheKey); count.decrementAndGet(); }
Example 11
Source Project: lucene-solr File: FieldCache.java License: Apache License 2.0 | 2 votes |
/** * Expert: drops all cache entries associated with this * reader {@link org.apache.lucene.index.IndexReader.CacheHelper#getKey()}. * NOTE: this cache key must * precisely match the reader that the cache entry is * keyed on. If you pass a top-level reader, it usually * will have no effect as Lucene now caches at the segment * reader level. */ public void purgeByCacheKey(IndexReader.CacheKey coreCacheKey);