boolean refreshed = false; try { final G reference = acquire(); try { notifyRefreshListenersBefore(); G newReference = refreshIfNeeded(reference); if (newReference != null) { assert newReference != reference : "refreshIfNeeded should return null if refresh wasn't needed"; try { swapReference(newReference); refreshed = true; } finally { if (!refreshed) { release(newReference); release(reference); notifyRefreshListenersRefreshed(refreshed); afterMaybeRefresh(); } finally { refreshLock.unlock();
manager.maybeRefreshBlocking(); } catch (IOException ioe) { throw new RuntimeException(ioe);
/** The missingValue must be non-null. */ public LiveFieldValues(ReferenceManager<S> mgr, T missingValue) { this.missingValue = missingValue; this.mgr = mgr; mgr.addListener(this); }
private synchronized void swapReference(G newReference) throws IOException { ensureOpen(); final G oldReference = current; current = newReference; release(oldReference); }
/** * You must call this (or {@link #maybeRefresh()}), periodically, if you want * that {@link #acquire()} will return refreshed instances. * * <p> * <b>Threads</b>: unlike {@link #maybeRefresh()}, if another thread is * currently refreshing, this method blocks until that thread completes. It is * useful if you want to guarantee that the next call to {@link #acquire()} * will return a refreshed instance. Otherwise, consider using the * non-blocking {@link #maybeRefresh()}. * @throws IOException if refreshing the resource causes an {@link IOException} * @throws AlreadyClosedException if the reference manager has been {@link #close() closed}. */ public final void maybeRefreshBlocking() throws IOException { ensureOpen(); // Ensure only 1 thread does refresh at once refreshLock.lock(); try { doMaybeRefresh(); } finally { refreshLock.unlock(); } }
public PartitionSearcher( ReferenceManager<IndexSearcher> referenceManager ) throws IOException { this.referenceManager = referenceManager; this.indexSearcher = referenceManager.acquire(); this.indexSearcher.setQueryCache( null ); }
@Override public void close() throws IOException { referenceManager.release( indexSearcher ); } }
/** 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); }
public void release(IndexWriter writer) throws IOException { if (writer != null) { try { if (autoFlush) { writer.flush(); } if (autoCommit) { writer.commit(); } } catch (Exception e) { this.writer = null; } if (this.writer != null && this.writer.isOpen()) { if (searcherManager != null) { searcherManager.maybeRefreshBlocking(); } } else { synchronized (lock) { this.writer = null; if (searcherManager != null) { searcherManager.close(); searcherManager = null; } } } } }
@Override public void close() { mgr.removeListener(this); }
/** * Release the reference previously obtained via {@link #acquire()}. * <p> * <b>NOTE:</b> it's safe to call this after {@link #close()}. * @throws IOException if the release operation on the given resource throws an {@link IOException} */ public final void release(G reference) throws IOException { assert reference != null; decRef(reference); }
try { ReferenceManager<IndexSearcher> referenceManager = getReferenceManager(scope); IndexSearcher acquire = referenceManager.acquire(); AtomicBoolean released = new AtomicBoolean(false); Searcher engineSearcher = new Searcher(source, acquire, if (released.compareAndSet(false, true)) { try { referenceManager.release(acquire); } finally { store.decRef();
private synchronized void swapReference(G newReference) throws IOException { ensureOpen(); final G oldReference = current; current = newReference; release(oldReference); }
ensureOpen(); if (doTryRefresh) { try { doMaybeRefresh(); } finally { refreshLock.unlock();
EngineSearcher(String source, ReferenceManager<IndexSearcher> searcherReferenceManager, Store store, Logger logger) throws IOException { super(source, searcherReferenceManager.acquire()); this.store = store; this.logger = logger; this.referenceManager = searcherReferenceManager; }
public void release(IndexSearcher searcher) throws IOException { if (searcher != null) { searcherManager.release(searcher); } }
swapReference(null); afterClose();
/** 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); }