Class LogMergePolicy
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Cloneable
- Direct Known Subclasses:
- LogByteSizeMergePolicy,- LogDocMergePolicy
This class implements a MergePolicy that tries
 to merge segments into levels of exponentially
 increasing size, where each level has fewer segments than
 the value of the merge factor. Whenever extra segments
 (beyond the merge factor upper bound) are encountered,
 all segments within the level are merged. You can get or
 set the merge factor using getMergeFactor() and
 setMergeFactor(int) respectively.
This class is abstract and requires a subclass to
 define the MergePolicy.size(org.apache.lucene.index.SegmentCommitInfo) method which specifies how a
 segment's size is determined.  LogDocMergePolicy
 is one subclass that measures size by document count in
 the segment.  LogByteSizeMergePolicy is another
 subclass that measures size as the total byte size of the
 file(s) for the segment.
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.lucene.index.MergePolicyMergePolicy.DocMap, MergePolicy.MergeAbortedException, MergePolicy.MergeException, MergePolicy.MergeSpecification, MergePolicy.MergeTrigger, MergePolicy.OneMerge
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected booleanIf true, we pro-rate a segment's size by the percentage of non-deleted documents.static final intDefault maximum segment size.static final intDefault merge factor, which is how many segments are merged at a timestatic final doubleDefault noCFSRatio.static final doubleDefines the allowed range of log(size) for each level.protected intIf a segment has more than this many documents then it will never be merged.protected longIf the size of a segment exceeds this value then it will never be merged.protected longIf the size of a segment exceeds this value then it will never be merged duringIndexWriter.forceMerge(int).protected intHow many segments to merge at a time.protected longAny segments whose size is smaller than this value will be rounded up to this value.Fields inherited from class org.apache.lucene.index.MergePolicyDEFAULT_MAX_CFS_SEGMENT_SIZE, maxCFSSegmentSize, noCFSRatio, writer
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Release all resources for the policy.findForcedDeletesMerges(SegmentInfos segmentInfos) Finds merges necessary to force-merge all deletes from the index.findForcedMerges(SegmentInfos infos, int maxNumSegments, Map<SegmentCommitInfo, Boolean> segmentsToMerge) Returns the merges necessary to merge the index down to a specified number of segments.findMerges(MergePolicy.MergeTrigger mergeTrigger, SegmentInfos infos) Checks if any merges are now necessary and returns aMergePolicy.MergeSpecificationif so.booleanReturns true if the segment size should be calibrated by the number of deletes when choosing segments for merge.intReturns the largest segment (measured by document count) that may be merged with other segments.intReturns the number of segments that are merged at once and also controls the total number of segments allowed to accumulate in the index.protected booleanisMerged(SegmentInfos infos, int maxNumSegments, Map<SegmentCommitInfo, Boolean> segmentsToMerge) Returns true if the number of segments eligible for merging is less than or equal to the specifiedmaxNumSegments.protected voidPrint a debug message toIndexWriter'sinfoStream.voidsetCalibrateSizeByDeletes(boolean calibrateSizeByDeletes) Sets whether the segment size should be calibrated by the number of deletes when choosing segments for merge.voidsetMaxMergeDocs(int maxMergeDocs) Determines the largest segment (measured by document count) that may be merged with other segments.voidsetMergeFactor(int mergeFactor) Determines how often segment indices are merged by addDocument().protected longsizeBytes(SegmentCommitInfo info) Return the byte size of the providedSegmentCommitInfo, pro-rated by percentage of non-deleted documents ifsetCalibrateSizeByDeletes(boolean)is set.protected longsizeDocs(SegmentCommitInfo info) Return the number of documents in the providedSegmentCommitInfo, pro-rated by percentage of non-deleted documents ifsetCalibrateSizeByDeletes(boolean)is set.toString()protected booleanverbose()Methods inherited from class org.apache.lucene.index.MergePolicyclone, getMaxCFSSegmentSizeMB, getNoCFSRatio, isMerged, setIndexWriter, setMaxCFSSegmentSizeMB, setNoCFSRatio, size, useCompoundFile
- 
Field Details- 
LEVEL_LOG_SPANpublic static final double LEVEL_LOG_SPANDefines the allowed range of log(size) for each level. A level is computed by taking the max segment log size, minus LEVEL_LOG_SPAN, and finding all segments falling within that range.- See Also:
 
- 
DEFAULT_MERGE_FACTORpublic static final int DEFAULT_MERGE_FACTORDefault merge factor, which is how many segments are merged at a time- See Also:
 
- 
DEFAULT_MAX_MERGE_DOCSpublic static final int DEFAULT_MAX_MERGE_DOCSDefault maximum segment size. A segment of this size or larger will never be merged. @see setMaxMergeDocs- See Also:
 
- 
DEFAULT_NO_CFS_RATIOpublic static final double DEFAULT_NO_CFS_RATIODefault noCFSRatio. If a merge's size is >= 10% of the index, then we disable compound file for it.
- 
mergeFactorprotected int mergeFactorHow many segments to merge at a time.
- 
minMergeSizeprotected long minMergeSizeAny segments whose size is smaller than this value will be rounded up to this value. This ensures that tiny segments are aggressively merged.
- 
maxMergeSizeprotected long maxMergeSizeIf the size of a segment exceeds this value then it will never be merged.
- 
maxMergeSizeForForcedMergeprotected long maxMergeSizeForForcedMergeIf the size of a segment exceeds this value then it will never be merged duringIndexWriter.forceMerge(int).
- 
maxMergeDocsprotected int maxMergeDocsIf a segment has more than this many documents then it will never be merged.
- 
calibrateSizeByDeletesprotected boolean calibrateSizeByDeletesIf true, we pro-rate a segment's size by the percentage of non-deleted documents.
 
- 
- 
Constructor Details- 
LogMergePolicypublic LogMergePolicy()Sole constructor. (For invocation by subclass constructors, typically implicit.)
 
- 
- 
Method Details- 
verboseprotected boolean verbose()
- 
messagePrint a debug message toIndexWriter'sinfoStream.
- 
getMergeFactorpublic int getMergeFactor()Returns the number of segments that are merged at once and also controls the total number of segments allowed to accumulate in the index. 
- 
setMergeFactorpublic void setMergeFactor(int mergeFactor) Determines how often segment indices are merged by addDocument(). With smaller values, less RAM is used while indexing, and searches are faster, but indexing speed is slower. With larger values, more RAM is used during indexing, and while searches is slower, indexing is faster. Thus larger values (> 10) are best for batch index creation, and smaller values (< 10) for indices that are interactively maintained.
- 
setCalibrateSizeByDeletespublic void setCalibrateSizeByDeletes(boolean calibrateSizeByDeletes) Sets whether the segment size should be calibrated by the number of deletes when choosing segments for merge.
- 
getCalibrateSizeByDeletespublic boolean getCalibrateSizeByDeletes()Returns true if the segment size should be calibrated by the number of deletes when choosing segments for merge.
- 
closepublic void close()Description copied from class:MergePolicyRelease all resources for the policy.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein class- MergePolicy
 
- 
sizeDocsReturn the number of documents in the providedSegmentCommitInfo, pro-rated by percentage of non-deleted documents ifsetCalibrateSizeByDeletes(boolean)is set.- Throws:
- IOException
 
- 
sizeBytesReturn the byte size of the providedSegmentCommitInfo, pro-rated by percentage of non-deleted documents ifsetCalibrateSizeByDeletes(boolean)is set.- Throws:
- IOException
 
- 
isMergedprotected boolean isMerged(SegmentInfos infos, int maxNumSegments, Map<SegmentCommitInfo, Boolean> segmentsToMerge) throws IOExceptionReturns true if the number of segments eligible for merging is less than or equal to the specifiedmaxNumSegments.- Throws:
- IOException
 
- 
findForcedMergespublic MergePolicy.MergeSpecification findForcedMerges(SegmentInfos infos, int maxNumSegments, Map<SegmentCommitInfo, Boolean> segmentsToMerge) throws IOExceptionReturns the merges necessary to merge the index down to a specified number of segments. This respects themaxMergeSizeForForcedMergesetting. By default, and assumingmaxNumSegments=1, only one segment will be left in the index, where that segment has no deletions pending nor separate norms, and it is in compound file format if the current useCompoundFile setting is true. This method returns multiple merges (mergeFactor at a time) so theMergeSchedulerin use may make use of concurrency.- Specified by:
- findForcedMergesin class- MergePolicy
- Parameters:
- infos- the total set of segments in the index
- maxNumSegments- requested maximum number of segments in the index (currently this is always 1)
- segmentsToMerge- contains the specific SegmentInfo instances that must be merged away. This may be a subset of all SegmentInfos. If the value is True for a given SegmentInfo, that means this segment was an original segment present in the to-be-merged index; else, it was a segment produced by a cascaded merge.
- Throws:
- IOException
 
- 
findForcedDeletesMergespublic MergePolicy.MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos) throws IOException Finds merges necessary to force-merge all deletes from the index. We simply merge adjacent segments that have deletes, up to mergeFactor at a time.- Specified by:
- findForcedDeletesMergesin class- MergePolicy
- Parameters:
- segmentInfos- the total set of segments in the index
- Throws:
- IOException
 
- 
findMergespublic MergePolicy.MergeSpecification findMerges(MergePolicy.MergeTrigger mergeTrigger, SegmentInfos infos) throws IOException Checks if any merges are now necessary and returns aMergePolicy.MergeSpecificationif so. A merge is necessary when there are more thansetMergeFactor(int)segments at a given level. When multiple levels have too many segments, this method will return multiple merges, allowing theMergeSchedulerto use concurrency.- Specified by:
- findMergesin class- MergePolicy
- Parameters:
- mergeTrigger- the event that triggered the merge
- infos- the total set of segments in the index
- Throws:
- IOException
 
- 
setMaxMergeDocspublic void setMaxMergeDocs(int maxMergeDocs) Determines the largest segment (measured by document count) that may be merged with other segments. Small values (e.g., less than 10,000) are best for interactive indexing, as this limits the length of pauses while indexing to a few seconds. Larger values are best for batched indexing and speedier searches. The default value is Integer.MAX_VALUE.The default merge policy ( LogByteSizeMergePolicy) also allows you to set this limit by net size (in MB) of the segment, usingLogByteSizeMergePolicy.setMaxMergeMB(double).
- 
getMaxMergeDocspublic int getMaxMergeDocs()Returns the largest segment (measured by document count) that may be merged with other segments.- See Also:
 
- 
toString
 
-