Package org.apache.lucene.search
Class ControlledRealTimeReopenThread<T>
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.lucene.search.ControlledRealTimeReopenThread<T>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Runnable
public class ControlledRealTimeReopenThread<T> extends java.lang.Thread implements java.io.CloseableUtility class that runs a thread to manage periodicc reopens of aReferenceManager, with methods to wait for a specific index changes to become visible. When a given search request needs to see a specific index change, call the {#waitForGeneration} to wait for that change to be visible. Note that this will only scale well if most searches do not need to wait for a specific index generation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classControlledRealTimeReopenThread.HandleRefresh
-
Field Summary
Fields Modifier and Type Field Description private booleanfinishprivate ReferenceManager<T>managerprivate longrefreshStartGenprivate java.util.concurrent.locks.ConditionreopenCondprivate java.util.concurrent.locks.ReentrantLockreopenLockprivate longsearchingGenprivate longtargetMaxStaleNSprivate longtargetMinStaleNSprivate longwaitingGenprivate IndexWriterwriter
-
Constructor Summary
Constructors Constructor Description ControlledRealTimeReopenThread(IndexWriter writer, ReferenceManager<T> manager, double targetMaxStaleSec, double targetMinStaleSec)Create ControlledRealTimeReopenThread, to periodically reopen theReferenceManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetSearchingGen()Returns whichgenerationthe current searcher is guaranteed to include.voidrun()voidwaitForGeneration(long targetGen)Waits for the target generation to become visible in the searcher.booleanwaitForGeneration(long targetGen, int maxMS)Waits for the target generation to become visible in the searcher, up to a maximum specified milli-seconds.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
manager
private final ReferenceManager<T> manager
-
targetMaxStaleNS
private final long targetMaxStaleNS
-
targetMinStaleNS
private final long targetMinStaleNS
-
writer
private final IndexWriter writer
-
finish
private volatile boolean finish
-
waitingGen
private volatile long waitingGen
-
searchingGen
private volatile long searchingGen
-
refreshStartGen
private long refreshStartGen
-
reopenLock
private final java.util.concurrent.locks.ReentrantLock reopenLock
-
reopenCond
private final java.util.concurrent.locks.Condition reopenCond
-
-
Constructor Detail
-
ControlledRealTimeReopenThread
public ControlledRealTimeReopenThread(IndexWriter writer, ReferenceManager<T> manager, double targetMaxStaleSec, double targetMinStaleSec)
Create ControlledRealTimeReopenThread, to periodically reopen theReferenceManager.- Parameters:
targetMaxStaleSec- Maximum time until a new reader must be opened; this sets the upper bound on how slowly reopens may occur, when no caller is waiting for a specific generation to become visible.targetMinStaleSec- Mininum time until a new reader can be opened; this sets the lower bound on how quickly reopens may occur, when a caller is waiting for a specific generation to become visible.
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
waitForGeneration
public void waitForGeneration(long targetGen) throws java.lang.InterruptedExceptionWaits for the target generation to become visible in the searcher. If the current searcher is older than the target generation, this method will block until the searcher is reopened, by another viaReferenceManager.maybeRefresh()or until theReferenceManageris closed.- Parameters:
targetGen- the generation to wait for- Throws:
java.lang.InterruptedException
-
waitForGeneration
public boolean waitForGeneration(long targetGen, int maxMS) throws java.lang.InterruptedExceptionWaits for the target generation to become visible in the searcher, up to a maximum specified milli-seconds. If the current searcher is older than the target generation, this method will block until the searcher has been reopened by another thread viaReferenceManager.maybeRefresh(), the given waiting time has elapsed, or until theReferenceManageris closed.NOTE: if the waiting time elapses before the requested target generation is available the current
SearcherManageris returned instead.- Parameters:
targetGen- the generation to wait formaxMS- maximum milliseconds to wait, or -1 to wait indefinitely- Returns:
- true if the targetGeneration is now available, or false if maxMS wait time was exceeded
- Throws:
java.lang.InterruptedException
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
getSearchingGen
public long getSearchingGen()
Returns whichgenerationthe current searcher is guaranteed to include.
-
-