java.lang.Object
org.apache.lucene.index.MergePolicy.OneMerge
- Enclosing class:
MergePolicy
OneMerge provides the information necessary to perform an individual primitive merge operation,
resulting in a single new segment. The merge spec includes the subset of segments to be merged
as well as whether the new segment should use the compound file format.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Throwable
long
Estimated size in bytes of the merged segment.(package private) SegmentCommitInfo
(package private) boolean
(package private) int
private final CompletableFuture
<Boolean> (package private) long
private final MergePolicy.OneMergeProgress
Control used to pause/stop/resume the merge thread.private List
<MergePolicy.MergeReader> (package private) long
(package private) boolean
final List
<SegmentCommitInfo> Segments to be merged.(package private) final int
Total number of documents in segments to be merged, not accounting for deletions.(package private) long
(package private) boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionOneMerge
(List<SegmentCommitInfo> segments) Sole constructor.OneMerge
(CodecReader... codecReaders) Create a OneMerge directly from CodecReaders.protected
OneMerge
(MergePolicy.OneMerge oneMerge) Constructor for wrapping. -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
Waits for this merge to be completedvoid
Checks if merge has been aborted and throws a merge exception if so.(package private) final void
close
(boolean success, boolean segmentDropped, IOConsumer<MergePolicy.MergeReader> readerConsumer) Closes this merge and releases all merge readers(package private) Throwable
Retrieve previous exception set bysetException(java.lang.Throwable)
.Returns theSegmentCommitInfo
for the merged segment, or null if it hasn't been set yet.Returns aMergePolicy.OneMergeProgress
instance for this merge, which provides statistics of the merge threads (run time vs.(package private) List
<MergePolicy.MergeReader> Returns the merge readers or an empty list if the readers were not initialized yet.ReturnMergeInfo
describing this merge.Returns true iff the merge completed successfully or false if the merge succeeded with a failure.(package private) boolean
Returns true if the merge has finished or false if it's still running or has not been started.(package private) void
initMergeReaders
(IOFunction<SegmentCommitInfo, MergePolicy.MergeReader> readerFactory) Sets the merge readers for this merge.boolean
Returns true if this merge was or should be aborted.void
mergeFinished
(boolean success, boolean segmentDropped) Called byIndexWriter
after the merge is done and all readers have been closed.void
Called byIndexWriter
after the merge started and from the thread that will be executing the merge.(package private) void
Called just before the merge is applied to IndexWriter's SegmentInfosreorder
(CodecReader reader, Directory dir, Executor executor) Extend this method if you wish to renumber doc IDs.Returns a readable description of the current merge state.void
Marks this merge as aborted.(package private) void
setException
(Throwable error) Record that an exception occurred while executing this mergevoid
Expert: Sets theSegmentCommitInfo
of the merged segment.long
Returns the total size in bytes of this merge.int
Returns the total number of documents that are included with this merge.wrapForMerge
(CodecReader reader) Wrap a reader prior to merging in order to add/remove fields or documents.
-
Field Details
-
mergeCompleted
-
info
SegmentCommitInfo info -
registerDone
boolean registerDone -
mergeGen
long mergeGen -
isExternal
boolean isExternal -
maxNumSegments
int maxNumSegments -
usesPooledReaders
boolean usesPooledReaders -
estimatedMergeBytes
public volatile long estimatedMergeBytesEstimated size in bytes of the merged segment. -
totalMergeBytes
volatile long totalMergeBytes -
mergeReaders
-
segments
Segments to be merged. -
mergeProgress
Control used to pause/stop/resume the merge thread. -
mergeStartNS
volatile long mergeStartNS -
totalMaxDoc
final int totalMaxDocTotal number of documents in segments to be merged, not accounting for deletions. -
error
Throwable error
-
-
Constructor Details
-
OneMerge
Sole constructor.- Parameters:
segments
- List ofSegmentCommitInfo
s to be merged.
-
OneMerge
Create a OneMerge directly from CodecReaders. Used to merge incoming readers inIndexWriter.addIndexes(CodecReader...)
. This OneMerge works directly on readers and has an empty segments list.- Parameters:
codecReaders
- Codec readers to merge
-
OneMerge
Constructor for wrapping.
-
-
Method Details
-
mergeInit
Called byIndexWriter
after the merge started and from the thread that will be executing the merge.- Throws:
IOException
-
mergeFinished
Called byIndexWriter
after the merge is done and all readers have been closed.- Parameters:
success
- true iff the merge finished successfully i.e. was committedsegmentDropped
- true iff the merged segment was dropped since it was fully deleted- Throws:
IOException
-
close
final void close(boolean success, boolean segmentDropped, IOConsumer<MergePolicy.MergeReader> readerConsumer) throws IOException Closes this merge and releases all merge readers- Throws:
IOException
-
wrapForMerge
Wrap a reader prior to merging in order to add/remove fields or documents.NOTE: It is illegal to reorder doc IDs here, use
reorder(CodecReader,Directory,Executor)
instead.- Throws:
IOException
-
reorder
public Sorter.DocMap reorder(CodecReader reader, Directory dir, Executor executor) throws IOException Extend this method if you wish to renumber doc IDs. This method will be called when index sorting is disabled on a merged view of theMergePolicy.OneMerge
. Anull
return value indicates that doc IDs should not be reordered.NOTE: Returning a non-null value here disables several optimizations and increases the merging overhead.
- Parameters:
reader
- The reader to reorder.dir
- TheDirectory
of the index, which may be used to create temporary files.executor
- An executor that can be used to parallelize the reordering logic. May benull
if no concurrency is supported.- Throws:
IOException
-
setMergeInfo
Expert: Sets theSegmentCommitInfo
of the merged segment. Allows sub-classes to e.g.add diagnostic
properties. -
getMergeInfo
Returns theSegmentCommitInfo
for the merged segment, or null if it hasn't been set yet. -
setException
Record that an exception occurred while executing this merge -
getException
Throwable getException()Retrieve previous exception set bysetException(java.lang.Throwable)
. -
segString
Returns a readable description of the current merge state. -
totalBytesSize
public long totalBytesSize()Returns the total size in bytes of this merge. Note that this does not indicate the size of the merged segment, but the input total size. This is only set once the merge is initialized by IndexWriter. -
totalNumDocs
public int totalNumDocs()Returns the total number of documents that are included with this merge. Note that this does not indicate the number of documents after the merge. -
getStoreMergeInfo
ReturnMergeInfo
describing this merge. -
isAborted
public boolean isAborted()Returns true if this merge was or should be aborted. -
setAborted
public void setAborted()Marks this merge as aborted. The merge thread should terminate at the soonest possible moment. -
checkAborted
Checks if merge has been aborted and throws a merge exception if so. -
getMergeProgress
Returns aMergePolicy.OneMergeProgress
instance for this merge, which provides statistics of the merge threads (run time vs. sleep time) if merging is throttled. -
await
Waits for this merge to be completed- Returns:
- true if the merge finished within the specified timeout
-
hasFinished
boolean hasFinished()Returns true if the merge has finished or false if it's still running or has not been started. This method will not block. -
hasCompletedSuccessfully
Returns true iff the merge completed successfully or false if the merge succeeded with a failure. This method will not block and return an empty Optional if the merge has not finished yet -
onMergeComplete
Called just before the merge is applied to IndexWriter's SegmentInfos- Throws:
IOException
-
initMergeReaders
void initMergeReaders(IOFunction<SegmentCommitInfo, MergePolicy.MergeReader> readerFactory) throws IOExceptionSets the merge readers for this merge.- Throws:
IOException
-
getMergeReader
List<MergePolicy.MergeReader> getMergeReader()Returns the merge readers or an empty list if the readers were not initialized yet.
-