Package org.apache.lucene.index
Class MergePolicy.OneMerge
- java.lang.Object
-
- org.apache.lucene.index.MergePolicy.OneMerge
-
- Enclosing class:
- MergePolicy
public static class MergePolicy.OneMerge extends java.lang.Object
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
Fields Modifier and Type Field Description (package private) java.lang.Throwable
error
long
estimatedMergeBytes
Estimated size in bytes of the merged segment.(package private) SegmentCommitInfo
info
(package private) boolean
isExternal
(package private) int
maxNumSegments
private java.util.concurrent.CompletableFuture<java.lang.Boolean>
mergeCompleted
(package private) long
mergeGen
private MergePolicy.OneMergeProgress
mergeProgress
Control used to pause/stop/resume the merge thread.private java.util.List<MergePolicy.MergeReader>
mergeReaders
(package private) long
mergeStartNS
(package private) boolean
registerDone
java.util.List<SegmentCommitInfo>
segments
Segments to be merged.(package private) int
totalMaxDoc
Total number of documents in segments to be merged, not accounting for deletions.(package private) long
totalMergeBytes
-
Constructor Summary
Constructors Constructor Description OneMerge(java.util.List<SegmentCommitInfo> segments)
Sole constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) boolean
await(long timeout, java.util.concurrent.TimeUnit timeUnit)
Waits for this merge to be completedvoid
checkAborted()
Checks if merge has been aborted and throws a merge exception if so.(package private) void
close(boolean success, boolean segmentDropped, IOUtils.IOConsumer<MergePolicy.MergeReader> readerConsumer)
Closes this merge and releases all merge readers(package private) java.lang.Throwable
getException()
Retrieve previous exception set bysetException(java.lang.Throwable)
.SegmentCommitInfo
getMergeInfo()
Returns theSegmentCommitInfo
for the merged segment, or null if it hasn't been set yet.MergePolicy.OneMergeProgress
getMergeProgress()
Returns aMergePolicy.OneMergeProgress
instance for this merge, which provides statistics of the merge threads (run time vs.(package private) java.util.List<MergePolicy.MergeReader>
getMergeReader()
Returns the merge readers or an empty list if the readers were not initialized yet.MergeInfo
getStoreMergeInfo()
ReturnMergeInfo
describing this merge.(package private) java.util.Optional<java.lang.Boolean>
hasCompletedSuccessfully()
Returns true iff the merge completed successfully or false if the merge succeeded with a failure.(package private) boolean
hasFinished()
Returns true if the merge has finished or false if it's still running or has not been started.(package private) void
initMergeReaders(IOUtils.IOFunction<SegmentCommitInfo,MergePolicy.MergeReader> readerFactory)
Sets the merge readers for this merge.boolean
isAborted()
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
mergeInit()
Called byIndexWriter
after the merge started and from the thread that will be executing the merge.(package private) void
onMergeComplete()
Called just before the merge is applied to IndexWriter's SegmentInfosjava.lang.String
segString()
Returns a readable description of the current merge state.void
setAborted()
Marks this merge as aborted.(package private) void
setException(java.lang.Throwable error)
Record that an exception occurred while executing this mergevoid
setMergeInfo(SegmentCommitInfo info)
Expert: Sets theSegmentCommitInfo
of the merged segment.long
totalBytesSize()
Returns the total size in bytes of this merge.int
totalNumDocs()
Returns the total number of documents that are included with this merge.CodecReader
wrapForMerge(CodecReader reader)
Wrap the reader in order to add/remove information to the merged segment.
-
-
-
Field Detail
-
mergeCompleted
private final java.util.concurrent.CompletableFuture<java.lang.Boolean> mergeCompleted
-
info
SegmentCommitInfo info
-
registerDone
boolean registerDone
-
mergeGen
long mergeGen
-
isExternal
boolean isExternal
-
maxNumSegments
int maxNumSegments
-
estimatedMergeBytes
public volatile long estimatedMergeBytes
Estimated size in bytes of the merged segment.
-
totalMergeBytes
volatile long totalMergeBytes
-
mergeReaders
private java.util.List<MergePolicy.MergeReader> mergeReaders
-
segments
public final java.util.List<SegmentCommitInfo> segments
Segments to be merged.
-
mergeProgress
private final MergePolicy.OneMergeProgress mergeProgress
Control used to pause/stop/resume the merge thread.
-
mergeStartNS
volatile long mergeStartNS
-
totalMaxDoc
final int totalMaxDoc
Total number of documents in segments to be merged, not accounting for deletions.
-
error
java.lang.Throwable error
-
-
Constructor Detail
-
OneMerge
public OneMerge(java.util.List<SegmentCommitInfo> segments)
Sole constructor.- Parameters:
segments
- List ofSegmentCommitInfo
s to be merged.
-
-
Method Detail
-
mergeInit
public void mergeInit() throws java.io.IOException
Called byIndexWriter
after the merge started and from the thread that will be executing the merge.- Throws:
java.io.IOException
-
mergeFinished
public void mergeFinished(boolean success, boolean segmentDropped) throws java.io.IOException
Called byIndexWriter
after the merge is done and all readers have been closed.- Parameters:
success
- true iff the merge finished successfully ie. was committedsegmentDropped
- true iff the merged segment was dropped since it was fully deleted- Throws:
java.io.IOException
-
close
final void close(boolean success, boolean segmentDropped, IOUtils.IOConsumer<MergePolicy.MergeReader> readerConsumer) throws java.io.IOException
Closes this merge and releases all merge readers- Throws:
java.io.IOException
-
wrapForMerge
public CodecReader wrapForMerge(CodecReader reader) throws java.io.IOException
Wrap the reader in order to add/remove information to the merged segment.- Throws:
java.io.IOException
-
setMergeInfo
public void setMergeInfo(SegmentCommitInfo info)
Expert: Sets theSegmentCommitInfo
of the merged segment. Allows sub-classes to e.g. set diagnostics properties.
-
getMergeInfo
public SegmentCommitInfo getMergeInfo()
Returns theSegmentCommitInfo
for the merged segment, or null if it hasn't been set yet.
-
setException
void setException(java.lang.Throwable error)
Record that an exception occurred while executing this merge
-
getException
java.lang.Throwable getException()
Retrieve previous exception set bysetException(java.lang.Throwable)
.
-
segString
public java.lang.String 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.
-
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
public void checkAborted() throws MergePolicy.MergeAbortedException
Checks if merge has been aborted and throws a merge exception if so.
-
getMergeProgress
public MergePolicy.OneMergeProgress 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
boolean await(long timeout, java.util.concurrent.TimeUnit timeUnit)
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
java.util.Optional<java.lang.Boolean> 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
void onMergeComplete() throws java.io.IOException
Called just before the merge is applied to IndexWriter's SegmentInfos- Throws:
java.io.IOException
-
initMergeReaders
void initMergeReaders(IOUtils.IOFunction<SegmentCommitInfo,MergePolicy.MergeReader> readerFactory) throws java.io.IOException
Sets the merge readers for this merge.- Throws:
java.io.IOException
-
getMergeReader
java.util.List<MergePolicy.MergeReader> getMergeReader()
Returns the merge readers or an empty list if the readers were not initialized yet.
-
-