public abstract class Engine
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
static class |
Engine.CommitId |
static class |
Engine.Delete |
static class |
Engine.DeleteResult |
static interface |
Engine.EventListener |
static class |
Engine.Get |
static class |
Engine.GetResult |
static class |
Engine.Index |
static class |
Engine.IndexResult |
protected static class |
Engine.IndexThrottle
A throttling class that can be activated, causing the
acquireThrottle method to block on a lock when throttling
is enabled |
protected static class |
Engine.NoOpLock
A Lock implementation that always allows the lock to be acquired
|
static class |
Engine.Operation |
static class |
Engine.Result
Base class for index and delete operation results
Holds result meta data (e.g.
|
static class |
Engine.Searcher |
static class |
Engine.SyncedFlushResult |
static interface |
Engine.Warmer
Called for each new opened engine searcher to warm new segments
|
Modifier and Type | Field and Description |
---|---|
protected org.apache.lucene.index.SnapshotDeletionPolicy |
deletionPolicy |
protected EngineConfig |
engineConfig |
protected Engine.EventListener |
eventListener |
protected org.apache.lucene.util.SetOnce<java.lang.Exception> |
failedEngine |
protected java.util.concurrent.locks.ReentrantLock |
failEngineLock |
protected java.util.concurrent.atomic.AtomicBoolean |
isClosed |
protected long |
lastWriteNanos |
protected org.apache.logging.log4j.Logger |
logger |
protected ReleasableLock |
readLock |
protected java.util.concurrent.locks.ReentrantReadWriteLock |
rwl |
protected ShardId |
shardId |
protected Store |
store |
static java.lang.String |
SYNC_COMMIT_ID |
protected ReleasableLock |
writeLock |
Modifier | Constructor and Description |
---|---|
protected |
Engine(EngineConfig engineConfig) |
Modifier and Type | Method and Description |
---|---|
abstract org.apache.lucene.index.IndexCommit |
acquireIndexCommit(boolean flushFirst)
Snapshots the index and returns a handle to it.
|
Engine.Searcher |
acquireSearcher(java.lang.String source)
Returns a new searcher instance.
|
abstract void |
activateThrottling()
Request that this engine throttle incoming indexing requests to one thread.
|
void |
close() |
protected abstract void |
closeNoLock(java.lang.String reason,
java.util.concurrent.CountDownLatch closedLatch)
Method to close the engine while the write lock is held.
|
CommitStats |
commitStats()
get commits stats for the last commit
|
EngineConfig |
config() |
abstract void |
deactivateThrottling()
Reverses a previous
activateThrottling() call. |
abstract Engine.DeleteResult |
delete(Engine.Delete delete)
Perform document delete operation on the engine
|
protected void |
ensureOpen() |
void |
failEngine(java.lang.String reason,
java.lang.Exception failure)
fail engine due to some error.
|
abstract Engine.CommitId |
flush()
Flushes the state of the engine including the transaction log, clearing memory and persisting
documents in the lucene index to disk including a potentially heavy and durable fsync operation.
|
abstract Engine.CommitId |
flush(boolean force,
boolean waitIfOngoing)
Flushes the state of the engine including the transaction log, clearing memory.
|
void |
flushAndClose()
Flush the engine (committing segments to disk and truncating the
translog) and close it.
|
void |
forceMerge(boolean flush)
Force merges to 1 segment
|
abstract void |
forceMerge(boolean flush,
int maxNumSegments,
boolean onlyExpungeDeletes,
boolean upgrade,
boolean upgradeOnlyAncientSegments)
Triggers a forced merge on this engine
|
abstract Engine.GetResult |
get(Engine.Get get,
java.util.function.Function<java.lang.String,Engine.Searcher> searcherFactory) |
protected Engine.GetResult |
getFromSearcher(Engine.Get get,
java.util.function.Function<java.lang.String,Engine.Searcher> searcherFactory) |
abstract long |
getIndexBufferRAMBytesUsed()
How much heap is used that would be freed by a refresh.
|
abstract long |
getIndexThrottleTimeInMillis()
Returns the number of milliseconds this engine was under index throttling.
|
protected abstract org.apache.lucene.index.SegmentInfos |
getLastCommittedSegmentInfos() |
long |
getLastWriteNanos()
Returns the timestamp of the last write in nanoseconds.
|
MergeStats |
getMergeStats() |
protected abstract org.apache.lucene.search.SearcherManager |
getSearcherManager() |
protected Segment[] |
getSegmentInfo(org.apache.lucene.index.SegmentInfos lastCommittedSegmentInfos,
boolean verbose) |
abstract Translog |
getTranslog()
returns the translog for this engine
|
protected static long |
guardedRamBytesUsed(org.apache.lucene.util.Accountable a)
Returns 0 in the case where accountable is null, otherwise returns
ramBytesUsed() |
abstract Engine.IndexResult |
index(Engine.Index index)
Perform document index operation on the engine
|
protected static boolean |
isMergedSegment(org.apache.lucene.index.LeafReader reader)
Returns whether a leaf reader comes from a merge (versus flush or addIndexes).
|
boolean |
isRecovering()
Returns
true iff this engine is currently recovering from translog. |
abstract boolean |
isThrottled()
Returns the
true iff this engine is currently under index throttling. |
protected boolean |
maybeFailEngine(java.lang.String source,
java.lang.Exception e)
Check whether the engine should be failed
|
protected Engine.Searcher |
newSearcher(java.lang.String source,
org.apache.lucene.search.IndexSearcher searcher,
org.apache.lucene.search.SearcherManager manager) |
void |
onSettingsChanged() |
protected static org.apache.lucene.index.SegmentInfos |
readLastCommittedSegmentInfos(org.apache.lucene.search.SearcherManager sm,
Store store)
Read the last segments info from the commit pointed to by the searcher manager
|
abstract Engine |
recoverFromTranslog()
Performs recovery from the transaction log.
|
abstract void |
refresh(java.lang.String source)
Synchronously refreshes the engine for new search operations to reflect the latest
changes.
|
boolean |
refreshNeeded() |
protected static org.apache.lucene.index.SegmentReader |
segmentReader(org.apache.lucene.index.LeafReader reader)
Tries to extract a segment reader from the given index reader.
|
abstract java.util.List<Segment> |
segments(boolean verbose)
The list of segments in the engine.
|
SegmentsStats |
segmentsStats(boolean includeSegmentFileSizes)
Global stats on segments.
|
abstract Engine.SyncedFlushResult |
syncFlush(java.lang.String syncId,
Engine.CommitId expectedCommitId)
Attempts to do a special commit where the given syncID is put into the commit data.
|
abstract void |
writeIndexingBuffer()
Called when our engine is using too much heap and should move buffered indexed/deleted documents to disk.
|
protected void |
writerSegmentStats(SegmentsStats stats) |
public static final java.lang.String SYNC_COMMIT_ID
protected final ShardId shardId
protected final org.apache.logging.log4j.Logger logger
protected final EngineConfig engineConfig
protected final Store store
protected final java.util.concurrent.atomic.AtomicBoolean isClosed
protected final Engine.EventListener eventListener
protected final org.apache.lucene.index.SnapshotDeletionPolicy deletionPolicy
protected final java.util.concurrent.locks.ReentrantLock failEngineLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock rwl
protected final ReleasableLock readLock
protected final ReleasableLock writeLock
protected final org.apache.lucene.util.SetOnce<java.lang.Exception> failedEngine
protected volatile long lastWriteNanos
protected Engine(EngineConfig engineConfig)
protected static long guardedRamBytesUsed(org.apache.lucene.util.Accountable a)
ramBytesUsed()
protected static org.apache.lucene.index.SegmentReader segmentReader(org.apache.lucene.index.LeafReader reader)
IllegalStateException
is thrown.protected static boolean isMergedSegment(org.apache.lucene.index.LeafReader reader)
protected Engine.Searcher newSearcher(java.lang.String source, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.SearcherManager manager)
public final EngineConfig config()
protected abstract org.apache.lucene.index.SegmentInfos getLastCommittedSegmentInfos()
public MergeStats getMergeStats()
public abstract long getIndexThrottleTimeInMillis()
public abstract boolean isThrottled()
true
iff this engine is currently under index throttling.getIndexThrottleTimeInMillis()
public abstract Engine.IndexResult index(Engine.Index index) throws java.io.IOException
index
- operation to performEngine.IndexResult
containing updated translog location, version and
document specific failures
Note: engine level failures (i.e. persistent engine failures) are thrownjava.io.IOException
public abstract Engine.DeleteResult delete(Engine.Delete delete) throws java.io.IOException
delete
- operation to performEngine.DeleteResult
containing updated translog location, version and
document specific failures
Note: engine level failures (i.e. persistent engine failures) are thrownjava.io.IOException
public abstract Engine.SyncedFlushResult syncFlush(java.lang.String syncId, Engine.CommitId expectedCommitId) throws EngineException
syncId
- id of this syncexpectedCommitId
- the expected value ofEngineException
protected final Engine.GetResult getFromSearcher(Engine.Get get, java.util.function.Function<java.lang.String,Engine.Searcher> searcherFactory) throws EngineException
EngineException
public abstract Engine.GetResult get(Engine.Get get, java.util.function.Function<java.lang.String,Engine.Searcher> searcherFactory) throws EngineException
EngineException
public final Engine.Searcher acquireSearcher(java.lang.String source) throws EngineException
EngineException
Engine.Searcher.close()
public abstract Translog getTranslog()
protected void ensureOpen()
public CommitStats commitStats()
protected static org.apache.lucene.index.SegmentInfos readLastCommittedSegmentInfos(org.apache.lucene.search.SearcherManager sm, Store store) throws java.io.IOException
java.io.IOException
public final SegmentsStats segmentsStats(boolean includeSegmentFileSizes)
protected void writerSegmentStats(SegmentsStats stats)
public abstract long getIndexBufferRAMBytesUsed()
AlreadyClosedException
.protected Segment[] getSegmentInfo(org.apache.lucene.index.SegmentInfos lastCommittedSegmentInfos, boolean verbose)
public abstract java.util.List<Segment> segments(boolean verbose)
public final boolean refreshNeeded()
@Nullable public abstract void refresh(java.lang.String source) throws EngineException
EngineException
public abstract void writeIndexingBuffer() throws EngineException
EngineException
public abstract Engine.CommitId flush(boolean force, boolean waitIfOngoing) throws EngineException
force
- if true
a lucene commit is executed even if no changes need to be committed.waitIfOngoing
- if true
this call will block until all currently running flushes have finished.
Otherwise this call will return without blocking.EngineException
public abstract Engine.CommitId flush() throws EngineException
EngineException
public void forceMerge(boolean flush) throws java.io.IOException
java.io.IOException
public abstract void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments) throws EngineException, java.io.IOException
EngineException
java.io.IOException
public abstract org.apache.lucene.index.IndexCommit acquireIndexCommit(boolean flushFirst) throws EngineException
flushFirst
- indicates whether the engine should flush before returning the snapshotEngineException
public void failEngine(java.lang.String reason, @Nullable java.lang.Exception failure)
protected boolean maybeFailEngine(java.lang.String source, java.lang.Exception e)
protected abstract org.apache.lucene.search.SearcherManager getSearcherManager()
protected abstract void closeNoLock(java.lang.String reason, java.util.concurrent.CountDownLatch closedLatch)
public void flushAndClose() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void onSettingsChanged()
public long getLastWriteNanos()
Engine.Operation.startTime()
is used which might be
slightly inaccurate.System.nanoTime()
,
Engine.Operation.startTime()
public abstract void activateThrottling()
deactivateThrottling()
.public abstract void deactivateThrottling()
activateThrottling()
call.public abstract Engine recoverFromTranslog() throws java.io.IOException
java.io.IOException
public boolean isRecovering()
true
iff this engine is currently recovering from translog.