Module org.elasticsearch.server
Package org.elasticsearch.index.engine
Class SearchBasedChangesSnapshot
java.lang.Object
org.elasticsearch.index.engine.SearchBasedChangesSnapshot
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Translog.Snapshot
- Direct Known Subclasses:
LuceneChangesSnapshot
,LuceneSyntheticSourceChangesSnapshot
public abstract class SearchBasedChangesSnapshot
extends Object
implements Translog.Snapshot, Closeable
Abstract class that provides a snapshot mechanism to retrieve operations from a live Lucene index
within a specified range of sequence numbers. Subclasses are expected to define the
method to fetch the next batch of operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected final long
protected final boolean
protected final int
protected final long
Fields inherited from interface org.elasticsearch.index.translog.Translog.Snapshot
EMPTY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SearchBasedChangesSnapshot
(MapperService mapperService, Engine.Searcher engineSearcher, int searchBatchSize, long fromSeqNo, long toSeqNo, boolean requiredFullRange, boolean accessStats, IndexVersion indexVersionCreated) Constructs a new snapshot for fetching changes within a sequence number range. -
Method Summary
Modifier and TypeMethodDescriptionprotected BytesReference
addSourceMetadata
(BytesReference originalSourceBytes, int segmentDocID) Creates a newSource
object by combining the providedoriginalSource
with additional metadata fields.protected static boolean
assertDocSoftDeleted
(org.apache.lucene.index.LeafReader leafReader, int segmentDocId) void
close()
List
<org.apache.lucene.index.LeafReaderContext> leaves()
Returns the list of index leaf reader contexts.final Translog.Operation
next()
Returns the next operation in the snapshot ornull
if we reached the end.protected abstract Translog.Operation
Abstract method for retrieving the next operation.protected org.apache.lucene.search.TopDocs
Retrieves the next batch of top documents based on the sequence range.protected void
setNextSourceMetadataReader
(org.apache.lucene.index.LeafReaderContext context) Sets the reader context to enable reading metadata that was removed from the_source
.int
The total estimated number of operations in the snapshot.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.index.translog.Translog.Snapshot
skippedOperations
-
Field Details
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZE- See Also:
-
fromSeqNo
protected final long fromSeqNo -
toSeqNo
protected final long toSeqNo -
requiredFullRange
protected final boolean requiredFullRange -
searchBatchSize
protected final int searchBatchSize
-
-
Constructor Details
-
SearchBasedChangesSnapshot
protected SearchBasedChangesSnapshot(MapperService mapperService, Engine.Searcher engineSearcher, int searchBatchSize, long fromSeqNo, long toSeqNo, boolean requiredFullRange, boolean accessStats, IndexVersion indexVersionCreated) throws IOException Constructs a new snapshot for fetching changes within a sequence number range.- Parameters:
engineSearcher
- Engine searcher instance.searchBatchSize
- Number of documents to retrieve per batch.fromSeqNo
- Starting sequence number.toSeqNo
- Ending sequence number.requiredFullRange
- Whether the full range is required.accessStats
- If true, enable access statistics for counting total operations.indexVersionCreated
- Version of the index when it was created.- Throws:
IOException
-
-
Method Details
-
nextOperation
Abstract method for retrieving the next operation. Should be implemented by subclasses.- Returns:
- The next Translog.Operation in the snapshot.
- Throws:
IOException
- If an I/O error occurs.
-
leaves
Returns the list of index leaf reader contexts.- Returns:
- List of LeafReaderContext.
-
totalOperations
public int totalOperations()Description copied from interface:Translog.Snapshot
The total estimated number of operations in the snapshot.- Specified by:
totalOperations
in interfaceTranslog.Snapshot
-
next
Description copied from interface:Translog.Snapshot
Returns the next operation in the snapshot ornull
if we reached the end.- Specified by:
next
in interfaceTranslog.Snapshot
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
nextTopDocs
Retrieves the next batch of top documents based on the sequence range.- Returns:
- TopDocs instance containing the documents in the current batch.
- Throws:
IOException
-
setNextSourceMetadataReader
protected void setNextSourceMetadataReader(org.apache.lucene.index.LeafReaderContext context) Sets the reader context to enable reading metadata that was removed from the_source
. This method sets up thesourceMetadataFetcher
with the providedLeafReaderContext
, ensuring it is ready to fetch metadata for subsequent operations.Note: This method should be called before
addSourceMetadata(BytesReference, int)
at the start of every leaf to ensure the metadata fetcher is properly initialized. -
addSourceMetadata
protected BytesReference addSourceMetadata(BytesReference originalSourceBytes, int segmentDocID) throws IOException Creates a newSource
object by combining the providedoriginalSource
with additional metadata fields. If thesourceMetadataFetcher
is null or no metadata fields are fetched, the original source is returned unchanged.- Parameters:
originalSourceBytes
- the original source bytessegmentDocID
- the document ID used to fetch metadata fields- Returns:
- a new
Source
instance containing the original data and additional metadata, or the original source if no metadata is added - Throws:
IOException
- if an error occurs while fetching metadata values
-
assertDocSoftDeleted
protected static boolean assertDocSoftDeleted(org.apache.lucene.index.LeafReader leafReader, int segmentDocId) throws IOException - Throws:
IOException
-