Java Code Examples for org.apache.lucene.search.ReferenceManager

The following examples show how to use org.apache.lucene.search.ReferenceManager. 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: vscode-extension   Source File: test.java    License: MIT License 5 votes vote down vote up
@Override
protected final ReferenceManager<IndexSearcher> getReferenceManager(SearcherScope scope) {
    switch (scope) {
        case INTERNAL:
            return internalSearcherManager;
        case EXTERNAL:
            return externalSearcherManager;
        default:
            throw new IllegalStateException("unknown scope: " + scope);
    }
}
 
Example 2
Source Project: Elasticsearch   Source File: LiveVersionMap.java    License: Apache License 2.0 5 votes vote down vote up
/** Sync'd because we replace old mgr. */
synchronized void setManager(ReferenceManager newMgr) {
    if (mgr != null) {
        mgr.removeListener(this);
    }
    mgr = newMgr;

    // In case InternalEngine closes & opens a new IndexWriter/SearcherManager, all deletes are made visible, so we clear old and
    // current here.  This is safe because caller holds writeLock here (so no concurrent adds/deletes can be happeninge):
    maps = new Maps();

    // So we are notified when reopen starts and finishes
    mgr.addListener(this);
}
 
Example 3
Source Project: lucene-solr   Source File: TestSearcherTaxonomyManager.java    License: Apache License 2.0 5 votes vote down vote up
public IndexerThread(IndexWriter w, FacetsConfig config, TaxonomyWriter tw,
    ReferenceManager<SearcherAndTaxonomy> mgr, int ordLimit, AtomicBoolean stop) {
  this.w = w;
  this.config = config;
  this.tw = tw;
  this.mgr = mgr;
  this.ordLimit = ordLimit;
  this.stop = stop;
}
 
Example 4
Source Project: crate   Source File: InternalEngine.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected final ReferenceManager<IndexSearcher> getReferenceManager(SearcherScope scope) {
    switch (scope) {
        case INTERNAL:
            return internalSearcherManager;
        case EXTERNAL:
            return externalSearcherManager;
        default:
            throw new IllegalStateException("unknown scope: " + scope);
    }
}
 
Example 5
Source Project: lucene-solr   Source File: Node.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the {@link ReferenceManager} to use for acquiring and releasing searchers */
public ReferenceManager<IndexSearcher> getSearcherManager() {
  return mgr;
}
 
Example 6
Source Project: lucene-solr   Source File: TestTryDelete.java    License: Apache License 2.0 4 votes vote down vote up
public void testTryDeleteDocument ()
  throws IOException
{
  Directory directory = createIndex();

  IndexWriter writer = getWriter(directory);

  ReferenceManager<IndexSearcher> mgr = new SearcherManager(writer,
                                                            new SearcherFactory());

  IndexSearcher searcher = mgr.acquire();

  TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")),
                                    100);
  assertEquals(1, topDocs.totalHits.value);

  long result;
  if (random().nextBoolean()) {
    IndexReader r = DirectoryReader.open(writer);
    result = writer.tryDeleteDocument(r, 0);
    r.close();
  } else {
    result = writer.tryDeleteDocument(searcher.getIndexReader(), 0);
  }

  // The tryDeleteDocument should have succeeded:
  assertTrue(result != -1);

  assertTrue(writer.hasDeletions());

  if (random().nextBoolean()) {
    writer.commit();
  }

  assertTrue(writer.hasDeletions());

  mgr.maybeRefresh();

  searcher = mgr.acquire();

  topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);

  assertEquals(0, topDocs.totalHits.value);
}
 
Example 7
Source Project: crate   Source File: EngineConfig.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new {@link org.elasticsearch.index.engine.EngineConfig}
 */
public EngineConfig(ShardId shardId,
                    String allocationId,
                    ThreadPool threadPool,
                    IndexSettings indexSettings,
                    Store store,
                    MergePolicy mergePolicy,
                    Analyzer analyzer,
                    CodecService codecService,
                    Engine.EventListener eventListener,
                    QueryCache queryCache,
                    QueryCachingPolicy queryCachingPolicy,
                    TranslogConfig translogConfig,
                    TimeValue flushMergesAfter,
                    List<ReferenceManager.RefreshListener> externalRefreshListener,
                    List<ReferenceManager.RefreshListener> internalRefreshListener,
                    CircuitBreakerService circuitBreakerService,
                    LongSupplier globalCheckpointSupplier,
                    LongSupplier primaryTermSupplier,
                    TombstoneDocSupplier tombstoneDocSupplier) {
    this.shardId = shardId;
    this.allocationId = allocationId;
    this.indexSettings = indexSettings;
    this.threadPool = threadPool;
    this.store = store;
    this.mergePolicy = mergePolicy;
    this.analyzer = analyzer;
    this.codecService = codecService;
    this.eventListener = eventListener;
    codecName = indexSettings.getValue(INDEX_CODEC_SETTING);
    // We need to make the indexing buffer for this shard at least as large
    // as the amount of memory that is available for all engines on the
    // local node so that decisions to flush segments to disk are made by
    // IndexingMemoryController rather than Lucene.
    // Add an escape hatch in case this change proves problematic - it used
    // to be a fixed amound of RAM: 256 MB.
    // TODO: Remove this escape hatch in 8.x
    final String escapeHatchProperty = "es.index.memory.max_index_buffer_size";
    String maxBufferSize = System.getProperty(escapeHatchProperty);
    if (maxBufferSize != null) {
        indexingBufferSize = MemorySizeValue.parseBytesSizeValueOrHeapRatio(maxBufferSize, escapeHatchProperty);
    } else {
        indexingBufferSize = IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.get(indexSettings.getNodeSettings());
    }
    this.queryCache = queryCache;
    this.queryCachingPolicy = queryCachingPolicy;
    this.translogConfig = translogConfig;
    this.flushMergesAfter = flushMergesAfter;
    this.externalRefreshListener = externalRefreshListener;
    this.internalRefreshListener = internalRefreshListener;
    this.circuitBreakerService = circuitBreakerService;
    this.globalCheckpointSupplier = globalCheckpointSupplier;
    this.primaryTermSupplier = primaryTermSupplier;
    this.tombstoneDocSupplier = tombstoneDocSupplier;
}
 
Example 8
Source Project: crate   Source File: EngineConfig.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * The refresh listeners to add to Lucene for externally visible refreshes
 */
public List<ReferenceManager.RefreshListener> getExternalRefreshListener() {
    return externalRefreshListener;
}
 
Example 9
Source Project: crate   Source File: EngineConfig.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * The refresh listeners to add to Lucene for internally visible refreshes. These listeners will also be invoked on external refreshes
 */
public List<ReferenceManager.RefreshListener> getInternalRefreshListener() {
    return internalRefreshListener;
}
 
Example 10
Source Project: crate   Source File: EngineTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public EngineConfig config(IndexSettings indexSettings, Store store, Path translogPath, MergePolicy mergePolicy,
                           ReferenceManager.RefreshListener refreshListener) {
    return config(indexSettings, store, translogPath, mergePolicy, refreshListener, null, () -> SequenceNumbers.NO_OPS_PERFORMED);
}
 
Example 11
Source Project: crate   Source File: EngineTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public EngineConfig config(IndexSettings indexSettings, Store store, Path translogPath, MergePolicy mergePolicy,
                           ReferenceManager.RefreshListener refreshListener, LongSupplier globalCheckpointSupplier) {
    return config(indexSettings, store, translogPath, mergePolicy, refreshListener, null, globalCheckpointSupplier);
}
 
Example 12
Source Project: crate   Source File: EngineTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public EngineConfig config(IndexSettings indexSettings, Store store, Path translogPath, MergePolicy mergePolicy,
                           ReferenceManager.RefreshListener externalRefreshListener,
                           ReferenceManager.RefreshListener internalRefreshListener,
                           LongSupplier globalCheckpointSupplier) {
    IndexWriterConfig iwc = newIndexWriterConfig();
    TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings, BigArrays.NON_RECYCLING_INSTANCE);
    Engine.EventListener listener = new Engine.EventListener() {
        @Override
        public void onFailedEngine(String reason, @Nullable Exception e) {
            // we don't need to notify anybody in this test
        }
    };
    final List<ReferenceManager.RefreshListener> extRefreshListenerList =
        externalRefreshListener == null ? emptyList() : Collections.singletonList(externalRefreshListener);
    final List<ReferenceManager.RefreshListener> intRefreshListenerList =
        internalRefreshListener == null ? emptyList() : Collections.singletonList(internalRefreshListener);

    if (globalCheckpointSupplier == null) {
        globalCheckpointSupplier = new ReplicationTracker(shardId, allocationId.getId(), indexSettings, SequenceNumbers.NO_OPS_PERFORMED, update -> {
        });
    }

    return new EngineConfig(
        shardId,
        allocationId.getId(),
        threadPool,
        indexSettings,
        store,
        mergePolicy,
        iwc.getAnalyzer(),
        new CodecService(null, logger),
        listener,
        IndexSearcher.getDefaultQueryCache(),
        IndexSearcher.getDefaultQueryCachingPolicy(),
        translogConfig,
        TimeValue.timeValueMinutes(5),
        extRefreshListenerList,
        intRefreshListenerList,
        new NoneCircuitBreakerService(),
        globalCheckpointSupplier,
        primaryTerm,
        tombstoneDocSupplier());
}
 
Example 13
Source Project: lucene-solr   Source File: TestTryDelete.java    License: Apache License 2.0 3 votes vote down vote up
public void testDeleteDocuments ()
  throws IOException
{
  Directory directory = createIndex();

  IndexWriter writer = getWriter(directory);

  ReferenceManager<IndexSearcher> mgr = new SearcherManager(writer,
                                                            new SearcherFactory());

  IndexSearcher searcher = mgr.acquire();

  TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")),
                                    100);
  assertEquals(1, topDocs.totalHits.value);

  long result = writer.deleteDocuments(new TermQuery(new Term("foo", "0")));

  assertTrue(result != -1);

  // writer.commit();

  assertTrue(writer.hasDeletions());

  mgr.maybeRefresh();

  searcher = mgr.acquire();

  topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);

  assertEquals(0, topDocs.totalHits.value);
}
 
Example 14
Source Project: crate   Source File: Engine.java    License: Apache License 2.0 votes vote down vote up
protected abstract ReferenceManager<IndexSearcher> getReferenceManager(SearcherScope scope);