Java Code Examples for org.apache.lucene.index.AtomicReader#getCoreCacheKey()

The following examples show how to use org.apache.lucene.index.AtomicReader#getCoreCacheKey() . 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 File: LindenFieldCacheImpl.java    From linden with Apache License 2.0 6 votes vote down vote up
/**
 * 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(AtomicReader reader, CacheKey key, Accountable value) {
  final Object readerKey = reader.getCoreCacheKey();
  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 2
Source File: SecureIndexSearcher.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
public SecureIndexSearcher(IndexReaderContext context, ExecutorService executor,
    AccessControlFactory accessControlFactory, Collection<String> readAuthorizations,
    Collection<String> discoverAuthorizations, Set<String> discoverableFields, String defaultReadMaskMessage)
    throws IOException {
  super(context, executor);
  _accessControlFactory = accessControlFactory;
  _readAuthorizations = readAuthorizations;
  _discoverAuthorizations = discoverAuthorizations;
  _discoverableFields = discoverableFields;
  _defaultReadMaskMessage = defaultReadMaskMessage;
  _accessControlReader = _accessControlFactory.getReader(readAuthorizations, discoverAuthorizations,
      discoverableFields, _defaultReadMaskMessage);
  _secureIndexReader = getSecureIndexReader(context);
  List<AtomicReaderContext> leaves = _secureIndexReader.leaves();
  _leaveMap = new HashMap<Object, AtomicReaderContext>();
  for (AtomicReaderContext atomicReaderContext : leaves) {
    AtomicReader atomicReader = atomicReaderContext.reader();
    SecureAtomicReader secureAtomicReader = (SecureAtomicReader) atomicReader;
    AtomicReader originalReader = secureAtomicReader.getOriginalReader();
    Object coreCacheKey = originalReader.getCoreCacheKey();
    _leaveMap.put(coreCacheKey, atomicReaderContext);
  }
}
 
Example 3
Source File: LindenFieldCacheImpl.java    From linden with Apache License 2.0 5 votes vote down vote up
private void initReader(AtomicReader reader) {
  if (reader instanceof SegmentReader) {
    reader.addCoreClosedListener(purgeCore);
  } else {
    // we have a slow reader of some sort, try to register a purge event
    // rather than relying on gc:
    Object key = reader.getCoreCacheKey();
    if (key instanceof AtomicReader) {
      ((AtomicReader) key).addReaderClosedListener(purgeReader);
    } else {
      // last chance
      reader.addReaderClosedListener(purgeReader);
    }
  }
}
 
Example 4
Source File: BitSetDocumentVisibilityFilterCacheStrategy.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public DocIdSet getDocIdSet(String fieldName, BytesRef term, AtomicReader reader) {
  Key key = new Key(fieldName, term, reader.getCoreCacheKey());
  DocIdSet docIdSet = _cache.get(key);
  if (docIdSet != null) {
    LOG.debug("Cache hit for key [" + key + "]");
  } else {
    LOG.debug("Cache miss for key [" + key + "]");
  }
  return docIdSet;
}
 
Example 5
Source File: FilterCache.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
  AtomicReader reader = context.reader();
  Object key = reader.getCoreCacheKey();
  DocIdSet docIdSet = _cache.get(key);
  if (docIdSet != null) {
    _hits.incrementAndGet();
    return BitsFilteredDocIdSet.wrap(docIdSet, acceptDocs);
  }
  // This will only allow a single instance be created per reader per filter
  Object lock = getLock(key);
  synchronized (lock) {
    SegmentReader segmentReader = getSegmentReader(reader);
    if (segmentReader == null) {
      LOG.warn("Could not find SegmentReader from [{0}]", reader);
      return _filter.getDocIdSet(context, acceptDocs);
    }
    Directory directory = getDirectory(segmentReader);
    if (directory == null) {
      LOG.warn("Could not find Directory from [{0}]", segmentReader);
      return _filter.getDocIdSet(context, acceptDocs);
    }
    _misses.incrementAndGet();
    String segmentName = segmentReader.getSegmentName();
    docIdSet = docIdSetToCache(_filter.getDocIdSet(context, null), reader, segmentName, directory);
    _cache.put(key, docIdSet);
    return BitsFilteredDocIdSet.wrap(docIdSet, acceptDocs);
  }
}
 
Example 6
Source File: LindenFieldCacheImpl.java    From linden with Apache License 2.0 4 votes vote down vote up
public Accountable get(AtomicReader reader, CacheKey key, boolean setDocsWithField) throws IOException {
  Map<CacheKey, Accountable> innerCache;
  Accountable value;
  final Object readerKey = reader.getCoreCacheKey();
  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) {
        long start = System.currentTimeMillis();
        progress.value = createValue(reader, key, setDocsWithField);
        long end = System.currentTimeMillis();
        LOGGER.info("createValue for {} cache in LindenFieldCacheImpl took {} ms", key.field, (end - start));
        synchronized (readerCache) {
          innerCache.put(key, progress.value);
        }

        // Only check if key.custom (the parser) is
        // non-null; else, we check twice for a single
        // call to FieldCache.getXXX
        if (key.custom != null && wrapper != null) {
          final PrintStream infoStream = wrapper.getInfoStream();
          if (infoStream != null) {
            printNewInsanity(infoStream, progress.value);
          }
        }
      }
      return progress.value;
    }
  }
  return value;
}