Class TieredMergePolicy

java.lang.Object
org.apache.lucene.index.MergePolicy
org.apache.lucene.index.TieredMergePolicy

public class TieredMergePolicy extends MergePolicy
Merges segments of approximately equal size, subject to an allowed number of segments per tier. This is similar to LogByteSizeMergePolicy, except this merge policy is able to merge non-adjacent segment, and separates how many segments are merged at once (setMaxMergeAtOnce(int)) from how many segments are allowed per tier (setSegmentsPerTier(double)). This merge policy also does not over-merge (i.e. cascade merges).

For normal merging, this policy first computes a "budget" of how many segments are allowed to be in the index. If the index is over-budget, then the policy sorts segments by decreasing size (pro-rating by percent deletes), and then finds the least-cost merge. Merge cost is measured by a combination of the "skew" of the merge (size of largest segment divided by smallest segment), total merge size and percent deletes reclaimed, so that merges with lower skew, smaller size and those reclaiming more deletes, are favored.

If a merge will produce a segment that's larger than setMaxMergedSegmentMB(double), then the policy will merge fewer segments (down to 1 at once, if that one has deletions) to keep the segment size under budget.

NOTE: this policy freely merges non-adjacent segments; if this is a problem, use LogMergePolicy.

NOTE: This policy always merges by byte size of the segments, always pro-rates by percent deletes

NOTE Starting with Lucene 7.5, if you call IndexWriter.forceMerge(int) with this (default) merge policy, if setMaxMergedSegmentMB(double) is in conflict with maxNumSegments passed to IndexWriter.forceMerge(int) then maxNumSegments wins. For example, if your index has 50 1 GB segments, and you have setMaxMergedSegmentMB(double) at 1024 (1 GB), and you call forceMerge(10), the two settings are clearly in conflict. TieredMergePolicy will choose to break the setMaxMergedSegmentMB(double) constraint and try to merge down to at most ten segments, each up to 5 * 1.25 GB in size (since an extra 25% buffer increase in the expected segment size is targetted).

findForcedDeletesMerges should never produce segments greater than maxSegmentSize.

NOTE: This policy returns natural merges whose size is below the floor segment size for full-flush merges.

  • Field Details

    • DEFAULT_NO_CFS_RATIO

      public static final double DEFAULT_NO_CFS_RATIO
      Default noCFSRatio. If a merge's size is >= 10% of the index, then we disable compound file for it.
      See Also:
    • maxMergeAtOnce

      private int maxMergeAtOnce
    • maxMergedSegmentBytes

      private long maxMergedSegmentBytes
    • floorSegmentBytes

      private long floorSegmentBytes
    • segsPerTier

      private double segsPerTier
    • forceMergeDeletesPctAllowed

      private double forceMergeDeletesPctAllowed
    • deletesPctAllowed

      private double deletesPctAllowed
  • Constructor Details

    • TieredMergePolicy

      public TieredMergePolicy()
      Sole constructor, setting all settings to their defaults.
  • Method Details