Package org.elasticsearch.index.engine
Class InternalEngine
- java.lang.Object
-
- org.elasticsearch.index.engine.Engine
-
- org.elasticsearch.index.engine.InternalEngine
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class InternalEngine extends Engine
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.index.engine.Engine
Engine.CommitId, Engine.Delete, Engine.DeleteResult, Engine.EventListener, Engine.Get, Engine.GetResult, Engine.Index, Engine.IndexCommitRef, Engine.IndexResult, Engine.IndexThrottle, Engine.NoOp, Engine.NoOpLock, Engine.NoOpResult, Engine.Operation, Engine.Result, Engine.Searcher, Engine.SearcherScope, Engine.SyncedFlushResult, Engine.Warmer
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID-
Fields inherited from class org.elasticsearch.index.engine.Engine
allocationId, engineConfig, eventListener, failedEngine, failEngineLock, HISTORY_UUID_KEY, isClosed, lastWriteNanos, logger, readLock, rwl, shardId, store, SYNC_COMMIT_ID, writeLock
-
-
Constructor Summary
Constructors Constructor Description InternalEngine(EngineConfig engineConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Engine.IndexCommitRefacquireLastIndexCommit(boolean flushFirst)Snapshots the most recent index and returns a handle to it.Engine.IndexCommitRefacquireSafeIndexCommit()Snapshots the most recent safe index commit from the engine.Engine.SearcheracquireSearcher(java.lang.String source, Engine.SearcherScope scope)Returns a new searcher instance.java.io.CloseableacquireTranslogRetentionLock()voidactivateThrottling()Request that this engine throttle incoming indexing requests to one thread.protected booleanassertOriginPrimarySequenceNumber(long seqNo)protected voidcloseNoLock(java.lang.String reason, java.util.concurrent.CountDownLatch closedLatch)Closes the engine without acquiring the write lock.protected voidcommitIndexWriter(org.apache.lucene.index.IndexWriter writer, Translog translog, java.lang.String syncId)Commits the specified index writer.voiddeactivateThrottling()Reverses a previousEngine.activateThrottling()call.Engine.DeleteResultdelete(Engine.Delete delete)Perform document delete operation on the engineprotected longdoGenerateSeqNoForOperation(Engine.Operation operation)Generate the sequence number for the specified operation.booleanensureTranslogSynced(java.util.stream.Stream<Translog.Location> locations)Ensures that all locations in the given stream have been written to the underlying storage.intestimateTranslogOperationsFromMinSeq(long minSeqNo)Returns the estimated number of translog operations in this engine whose seq# at least the provided seq#.intfillSeqNoGaps(long primaryTerm)Fills up the local checkpoints history with no-ops until the local checkpoint and the max seen sequence ID are identical.Engine.CommitIdflush()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.Engine.CommitIdflush(boolean force, boolean waitIfOngoing)Flushes the state of the engine including the transaction log, clearing memory.voidforceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments)Triggers a forced merge on this engineEngine.GetResultget(Engine.Get get, java.util.function.BiFunction<java.lang.String,Engine.SearcherScope,Engine.Searcher> searcherFactory)java.lang.StringgetHistoryUUID()returns the history uuid for the enginelonggetIndexBufferRAMBytesUsed()How much heap is used that would be freed by a refresh.longgetIndexThrottleTimeInMillis()Returns the number of milliseconds this engine was under index throttling.protected org.apache.lucene.index.SegmentInfosgetLastCommittedSegmentInfos()longgetLastSyncedGlobalCheckpoint()Returns the latest global checkpoint value that has been persisted in the underlying storage (i.e.longgetLocalCheckpoint()MergeStatsgetMergeStats()SeqNoStatsgetSeqNoStats(long globalCheckpoint)Translog.LocationgetTranslogLastWriteLocation()Returns the last location that the translog of this engine has written into.TranslogStatsgetTranslogStats()longgetWritingBytes()Returns how many bytes we are currently moving from indexing buffer to segments on diskEngine.IndexResultindex(Engine.Index index)Perform document index operation on the enginebooleanisRecovering()Returnstrueiff this engine is currently recovering from translog.booleanisThrottled()Returns thetrueiff this engine is currently under index throttling.booleanisTranslogSyncNeeded()Checks if the underlying storage sync is required.protected booleanmaybeFailEngine(java.lang.String source, java.lang.Exception e)Check whether the engine should be failedvoidmaybePruneDeletes()Tries to prune buffered deletes from the version map.Translog.SnapshotnewTranslogSnapshotFromMinSeqNo(long minSeqNo)Creates a new translog snapshot from this engine for reading translog operations whose seq# at least the provided seq#.Engine.NoOpResultnoOp(Engine.NoOp noOp)voidonSettingsChanged()InternalEnginerecoverFromTranslog()Performs recovery from the transaction log.voidrefresh(java.lang.String source)Synchronously refreshes the engine for new search operations to reflect the latest changes.voidresetLocalCheckpoint(long localCheckpoint)Reset the local checkpoint in the tracker to the given local checkpointvoidrestoreLocalCheckpointFromTranslog()Marks operations in the translog as completed.voidrollTranslogGeneration()Rolls the translog generation and cleans unneeded.java.util.List<Segment>segments(boolean verbose)The list of segments in the engine.booleanshouldPeriodicallyFlush()Checks if this engine should be flushed periodically.booleanshouldRollTranslogGeneration()Tests whether or not the translog generation should be rolled to a new generation.voidskipTranslogRecovery()Do not replay translog operations, but make the engine be ready.Engine.SyncedFlushResultsyncFlush(java.lang.String syncId, Engine.CommitId expectedCommitId)Attempts to do a special commit where the given syncID is put into the commit data.voidsyncTranslog()voidtrimOperationsFromTranslog(long belowTerm, long aboveSeqNo)Trims translog for terms belowbelowTermand seq# aboveaboveSeqNovoidtrimUnreferencedTranslogFiles()checks and removes translog files that no longer need to be retained.voidwaitForOpsToComplete(long seqNo)Waits for all operations up to the provided sequence number to complete.voidwriteIndexingBuffer()Called when our engine is using too much heap and should move buffered indexed/deleted documents to disk.protected voidwriterSegmentStats(SegmentsStats stats)-
Methods inherited from class org.elasticsearch.index.engine.Engine
acquireSearcher, close, commitStats, config, ensureOpen, ensureOpen, failEngine, flushAndClose, forceMerge, getFromSearcher, getLastWriteNanos, getSegmentInfo, guardedRamBytesUsed, isMergedSegment, refreshNeeded, segmentsStats
-
-
-
-
Field Detail
-
MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID
public static final java.lang.String MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InternalEngine
public InternalEngine(EngineConfig engineConfig)
-
-
Method Detail
-
restoreLocalCheckpointFromTranslog
public void restoreLocalCheckpointFromTranslog() throws java.io.IOExceptionDescription copied from class:EngineMarks operations in the translog as completed. This is used to restore the state of the local checkpoint tracker on primary promotion.- Specified by:
restoreLocalCheckpointFromTranslogin classEngine- Throws:
java.io.IOException- if an I/O exception occurred reading the translog
-
fillSeqNoGaps
public int fillSeqNoGaps(long primaryTerm) throws java.io.IOExceptionDescription copied from class:EngineFills up the local checkpoints history with no-ops until the local checkpoint and the max seen sequence ID are identical.- Specified by:
fillSeqNoGapsin classEngine- Parameters:
primaryTerm- the shards primary term this engine was created for- Returns:
- the number of no-ops added
- Throws:
java.io.IOException
-
recoverFromTranslog
public InternalEngine recoverFromTranslog() throws java.io.IOException
Description copied from class:EnginePerforms recovery from the transaction log. This operation will close the engine if the recovery fails.- Specified by:
recoverFromTranslogin classEngine- Throws:
java.io.IOException
-
skipTranslogRecovery
public void skipTranslogRecovery()
Description copied from class:EngineDo not replay translog operations, but make the engine be ready.- Specified by:
skipTranslogRecoveryin classEngine
-
isTranslogSyncNeeded
public boolean isTranslogSyncNeeded()
Description copied from class:EngineChecks if the underlying storage sync is required.- Specified by:
isTranslogSyncNeededin classEngine
-
ensureTranslogSynced
public boolean ensureTranslogSynced(java.util.stream.Stream<Translog.Location> locations) throws java.io.IOException
Description copied from class:EngineEnsures that all locations in the given stream have been written to the underlying storage.- Specified by:
ensureTranslogSyncedin classEngine- Throws:
java.io.IOException
-
syncTranslog
public void syncTranslog() throws java.io.IOException- Specified by:
syncTranslogin classEngine- Throws:
java.io.IOException
-
acquireTranslogRetentionLock
public java.io.Closeable acquireTranslogRetentionLock()
- Specified by:
acquireTranslogRetentionLockin classEngine
-
newTranslogSnapshotFromMinSeqNo
public Translog.Snapshot newTranslogSnapshotFromMinSeqNo(long minSeqNo) throws java.io.IOException
Description copied from class:EngineCreates a new translog snapshot from this engine for reading translog operations whose seq# at least the provided seq#. The caller has to close the returned snapshot after finishing the reading.- Specified by:
newTranslogSnapshotFromMinSeqNoin classEngine- Throws:
java.io.IOException
-
estimateTranslogOperationsFromMinSeq
public int estimateTranslogOperationsFromMinSeq(long minSeqNo)
Description copied from class:EngineReturns the estimated number of translog operations in this engine whose seq# at least the provided seq#.- Specified by:
estimateTranslogOperationsFromMinSeqin classEngine
-
getTranslogStats
public TranslogStats getTranslogStats()
- Specified by:
getTranslogStatsin classEngine
-
getTranslogLastWriteLocation
public Translog.Location getTranslogLastWriteLocation()
Description copied from class:EngineReturns the last location that the translog of this engine has written into.- Specified by:
getTranslogLastWriteLocationin classEngine
-
getHistoryUUID
public java.lang.String getHistoryUUID()
Description copied from class:Enginereturns the history uuid for the engine- Specified by:
getHistoryUUIDin classEngine
-
getWritingBytes
public long getWritingBytes()
Returns how many bytes we are currently moving from indexing buffer to segments on disk- Specified by:
getWritingBytesin classEngine
-
get
public Engine.GetResult get(Engine.Get get, java.util.function.BiFunction<java.lang.String,Engine.SearcherScope,Engine.Searcher> searcherFactory) throws EngineException
- Specified by:
getin classEngine- Throws:
EngineException
-
assertOriginPrimarySequenceNumber
protected boolean assertOriginPrimarySequenceNumber(long seqNo)
-
doGenerateSeqNoForOperation
protected long doGenerateSeqNoForOperation(Engine.Operation operation)
Generate the sequence number for the specified operation.- Parameters:
operation- the operation- Returns:
- the sequence number
-
index
public Engine.IndexResult index(Engine.Index index) throws java.io.IOException
Description copied from class:EnginePerform document index operation on the engine- Specified by:
indexin classEngine- Parameters:
index- operation to perform- Returns:
Engine.IndexResultcontaining updated translog location, version and document specific failures Note: engine level failures (i.e. persistent engine failures) are thrown- Throws:
java.io.IOException
-
delete
public Engine.DeleteResult delete(Engine.Delete delete) throws java.io.IOException
Description copied from class:EnginePerform document delete operation on the engine- Specified by:
deletein classEngine- Parameters:
delete- operation to perform- Returns:
Engine.DeleteResultcontaining updated translog location, version and document specific failures Note: engine level failures (i.e. persistent engine failures) are thrown- Throws:
java.io.IOException
-
maybePruneDeletes
public void maybePruneDeletes()
Description copied from class:EngineTries to prune buffered deletes from the version map.- Specified by:
maybePruneDeletesin classEngine
-
noOp
public Engine.NoOpResult noOp(Engine.NoOp noOp)
-
refresh
public void refresh(java.lang.String source) throws EngineExceptionDescription copied from class:EngineSynchronously refreshes the engine for new search operations to reflect the latest changes.- Specified by:
refreshin classEngine- Throws:
EngineException
-
writeIndexingBuffer
public void writeIndexingBuffer() throws EngineExceptionDescription copied from class:EngineCalled when our engine is using too much heap and should move buffered indexed/deleted documents to disk.- Specified by:
writeIndexingBufferin classEngine- Throws:
EngineException
-
syncFlush
public Engine.SyncedFlushResult syncFlush(java.lang.String syncId, Engine.CommitId expectedCommitId) throws EngineException
Description copied from class:EngineAttempts to do a special commit where the given syncID is put into the commit data. The attempt succeeds if there are not pending writes in lucene and the current point is equal to the expected one.- Specified by:
syncFlushin classEngine- Parameters:
syncId- id of this syncexpectedCommitId- the expected value of- Returns:
- true if the sync commit was made, false o.w.
- Throws:
EngineException
-
shouldPeriodicallyFlush
public boolean shouldPeriodicallyFlush()
Description copied from class:EngineChecks if this engine should be flushed periodically. This check is mainly based on the uncommitted translog size and the translog flush threshold setting.- Specified by:
shouldPeriodicallyFlushin classEngine
-
flush
public Engine.CommitId flush() throws EngineException
Description copied from class:EngineFlushes 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. This operation is not going to block if another flush operation is currently running and won't write a lucene commit if nothing needs to be committed.- Specified by:
flushin classEngine- Returns:
- the commit Id for the resulting commit
- Throws:
EngineException
-
flush
public Engine.CommitId flush(boolean force, boolean waitIfOngoing) throws EngineException
Description copied from class:EngineFlushes the state of the engine including the transaction log, clearing memory.- Specified by:
flushin classEngine- Parameters:
force- iftruea lucene commit is executed even if no changes need to be committed.waitIfOngoing- iftruethis call will block until all currently running flushes have finished. Otherwise this call will return without blocking.- Returns:
- the commit Id for the resulting commit
- Throws:
EngineException
-
rollTranslogGeneration
public void rollTranslogGeneration() throws EngineExceptionDescription copied from class:EngineRolls the translog generation and cleans unneeded.- Specified by:
rollTranslogGenerationin classEngine- Throws:
EngineException
-
trimUnreferencedTranslogFiles
public void trimUnreferencedTranslogFiles() throws EngineExceptionDescription copied from class:Enginechecks and removes translog files that no longer need to be retained. SeeTranslogDeletionPolicyfor details- Specified by:
trimUnreferencedTranslogFilesin classEngine- Throws:
EngineException
-
shouldRollTranslogGeneration
public boolean shouldRollTranslogGeneration()
Description copied from class:EngineTests whether or not the translog generation should be rolled to a new generation. This test is based on the size of the current generation compared to the configured generation threshold size.- Specified by:
shouldRollTranslogGenerationin classEngine- Returns:
trueif the current generation should be rolled to a new generation
-
trimOperationsFromTranslog
public void trimOperationsFromTranslog(long belowTerm, long aboveSeqNo) throws EngineExceptionDescription copied from class:EngineTrims translog for terms belowbelowTermand seq# aboveaboveSeqNo- Specified by:
trimOperationsFromTranslogin classEngine- Throws:
EngineException- See Also:
Translog.trimOperations(long, long)
-
forceMerge
public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments) throws EngineException, java.io.IOExceptionDescription copied from class:EngineTriggers a forced merge on this engine- Specified by:
forceMergein classEngine- Throws:
EngineExceptionjava.io.IOException
-
acquireLastIndexCommit
public Engine.IndexCommitRef acquireLastIndexCommit(boolean flushFirst) throws EngineException
Description copied from class:EngineSnapshots the most recent index and returns a handle to it. If needed will try and "commit" the lucene index to make sure we have a "fresh" copy of the files to snapshot.- Specified by:
acquireLastIndexCommitin classEngine- Parameters:
flushFirst- indicates whether the engine should flush before returning the snapshot- Throws:
EngineException
-
acquireSafeIndexCommit
public Engine.IndexCommitRef acquireSafeIndexCommit() throws EngineException
Description copied from class:EngineSnapshots the most recent safe index commit from the engine.- Specified by:
acquireSafeIndexCommitin classEngine- Throws:
EngineException
-
maybeFailEngine
protected boolean maybeFailEngine(java.lang.String source, java.lang.Exception e)Description copied from class:EngineCheck whether the engine should be failed- Overrides:
maybeFailEnginein classEngine
-
getLastCommittedSegmentInfos
protected org.apache.lucene.index.SegmentInfos getLastCommittedSegmentInfos()
- Specified by:
getLastCommittedSegmentInfosin classEngine
-
writerSegmentStats
protected final void writerSegmentStats(SegmentsStats stats)
- Overrides:
writerSegmentStatsin classEngine
-
getIndexBufferRAMBytesUsed
public long getIndexBufferRAMBytesUsed()
Description copied from class:EngineHow much heap is used that would be freed by a refresh. Note that this may throwAlreadyClosedException.- Specified by:
getIndexBufferRAMBytesUsedin classEngine
-
segments
public java.util.List<Segment> segments(boolean verbose)
Description copied from class:EngineThe list of segments in the engine.
-
closeNoLock
protected final void closeNoLock(java.lang.String reason, java.util.concurrent.CountDownLatch closedLatch)Closes the engine without acquiring the write lock. This should only be called while the write lock is hold or in a disaster condition ie. if the engine is failed.- Specified by:
closeNoLockin classEngine
-
acquireSearcher
public Engine.Searcher acquireSearcher(java.lang.String source, Engine.SearcherScope scope)
Description copied from class:EngineReturns a new searcher instance. The consumer of this API is responsible for releasing the returned searcher in a safe manner, preferably in a try/finally block.- Specified by:
acquireSearcherin classEngine- Parameters:
source- the source API or routing that triggers this searcher acquirescope- the scope of this searcher ie. if the searcher will be used for get or search purposes- See Also:
Engine.Searcher.close()
-
activateThrottling
public void activateThrottling()
Description copied from class:EngineRequest that this engine throttle incoming indexing requests to one thread. Must be matched by a later call toEngine.deactivateThrottling().- Specified by:
activateThrottlingin classEngine
-
deactivateThrottling
public void deactivateThrottling()
Description copied from class:EngineReverses a previousEngine.activateThrottling()call.- Specified by:
deactivateThrottlingin classEngine
-
isThrottled
public boolean isThrottled()
Description copied from class:EngineReturns thetrueiff this engine is currently under index throttling.- Specified by:
isThrottledin classEngine- See Also:
Engine.getIndexThrottleTimeInMillis()
-
getIndexThrottleTimeInMillis
public long getIndexThrottleTimeInMillis()
Description copied from class:EngineReturns the number of milliseconds this engine was under index throttling.- Specified by:
getIndexThrottleTimeInMillisin classEngine
-
commitIndexWriter
protected void commitIndexWriter(org.apache.lucene.index.IndexWriter writer, Translog translog, @Nullable java.lang.String syncId) throws java.io.IOExceptionCommits the specified index writer.- Parameters:
writer- the index writer to committranslog- the translogsyncId- the sync flush ID (nullif not committing a synced flush)- Throws:
java.io.IOException- if an I/O exception occurs committing the specfied writer
-
onSettingsChanged
public void onSettingsChanged()
- Overrides:
onSettingsChangedin classEngine
-
getMergeStats
public MergeStats getMergeStats()
- Overrides:
getMergeStatsin classEngine
-
getLastSyncedGlobalCheckpoint
public long getLastSyncedGlobalCheckpoint()
Description copied from class:EngineReturns the latest global checkpoint value that has been persisted in the underlying storage (i.e. translog's checkpoint)- Specified by:
getLastSyncedGlobalCheckpointin classEngine
-
getLocalCheckpoint
public long getLocalCheckpoint()
- Specified by:
getLocalCheckpointin classEngine- Returns:
- the local checkpoint for this Engine
-
waitForOpsToComplete
public void waitForOpsToComplete(long seqNo) throws java.lang.InterruptedExceptionDescription copied from class:EngineWaits for all operations up to the provided sequence number to complete.- Specified by:
waitForOpsToCompletein classEngine- Parameters:
seqNo- the sequence number that the checkpoint must advance to before this method returns- Throws:
java.lang.InterruptedException- if the thread was interrupted while blocking on the condition
-
resetLocalCheckpoint
public void resetLocalCheckpoint(long localCheckpoint)
Description copied from class:EngineReset the local checkpoint in the tracker to the given local checkpoint- Specified by:
resetLocalCheckpointin classEngine- Parameters:
localCheckpoint- the new checkpoint to be set
-
getSeqNoStats
public SeqNoStats getSeqNoStats(long globalCheckpoint)
- Specified by:
getSeqNoStatsin classEngine- Returns:
- a
SeqNoStatsobject, using local state and the supplied global checkpoint
-
isRecovering
public boolean isRecovering()
Description copied from class:EngineReturnstrueiff this engine is currently recovering from translog.- Overrides:
isRecoveringin classEngine
-
-