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 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

      protected abstract Translog.Operation nextOperation() throws IOException
      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

      public List<org.apache.lucene.index.LeafReaderContext> 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 interface Translog.Snapshot
    • next

      public final Translog.Operation next() throws IOException
      Description copied from interface: Translog.Snapshot
      Returns the next operation in the snapshot or null if we reached the end.
      Specified by:
      next in interface Translog.Snapshot
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • nextTopDocs

      protected org.apache.lucene.search.TopDocs nextTopDocs() throws IOException
      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 the sourceMetadataFetcher with the provided LeafReaderContext, 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 new Source object by combining the provided originalSource with additional metadata fields. If the sourceMetadataFetcher is null or no metadata fields are fetched, the original source is returned unchanged.
      Parameters:
      originalSourceBytes - the original source bytes
      segmentDocID - 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