Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBuilder.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBuilder.java (revision 1689672) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBuilder.java (working copy) @@ -43,6 +43,7 @@ private int retryCount; private boolean forceAfterFail; private boolean persistCompactionMap; + private byte gainThreshold; private CompactionStrategy compactionStrategy; static SegmentNodeStoreBuilder newSegmentNodeStore(SegmentStore store) { @@ -56,7 +57,7 @@ public SegmentNodeStoreBuilder withCompactionStrategy( boolean pauseCompaction, boolean cloneBinaries, String cleanup, long cleanupTs, byte memoryThreshold, final int lockWaitTime, - int retryCount, boolean forceAfterFail, boolean persistCompactionMap) { + int retryCount, boolean forceAfterFail, boolean persistCompactionMap, byte gainThreshold) { this.hasCompactionStrategy = true; this.pauseCompaction = pauseCompaction; this.cloneBinaries = cloneBinaries; @@ -67,6 +68,7 @@ this.retryCount = retryCount; this.forceAfterFail = forceAfterFail; this.persistCompactionMap = persistCompactionMap; + this.gainThreshold = gainThreshold; return this; } @@ -96,6 +98,7 @@ compactionStrategy.setRetryCount(retryCount); compactionStrategy.setForceAfterFail(forceAfterFail); compactionStrategy.setPersistCompactionMap(persistCompactionMap); + compactionStrategy.setGainThreshold(gainThreshold); } else { compactionStrategy = NO_COMPACTION; } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java (revision 1689672) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java (working copy) @@ -25,6 +25,7 @@ import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.CLEANUP_DEFAULT; import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.CLONE_BINARIES_DEFAULT; import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.FORCE_AFTER_FAIL_DEFAULT; +import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.GAIN_THRESHOLD_DEFAULT; import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.MEMORY_THRESHOLD_DEFAULT; import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.PAUSE_DEFAULT; import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.PERSIST_COMPACTION_MAP_DEFAULT; @@ -169,6 +170,14 @@ public static final String COMPACTION_MEMORY_THRESHOLD = "compaction.memoryThreshold"; @Property( + byteValue = GAIN_THRESHOLD_DEFAULT, + label = "Compaction gain threshold", + description = "TarMK compaction gain threshold. The gain estimation prevents compaction from running " + + "if the provided threshold is not met. Value represents a percentage so an input beween 0 and 100 is expected." + ) + public static final String COMPACTION_GAIN_THRESHOLD = "compaction.gainThreshold"; + + @Property( boolValue = PAUSE_DEFAULT, label = "Pause Compaction", description = "When enabled compaction would not be performed" @@ -354,6 +363,12 @@ memoryThreshold = Byte.valueOf(memoryThresholdS); } + String gainThresholdS = fallbackLookup(context, COMPACTION_GAIN_THRESHOLD); + byte gainThreshold = GAIN_THRESHOLD_DEFAULT; + if (gainThresholdS != null) { + gainThreshold = Byte.valueOf(gainThresholdS); + } + final long blobGcMaxAgeInSecs = toLong(fallbackLookup(context, PROP_BLOB_GC_MAX_AGE), DEFAULT_BLOB_GC_MAX_AGE); OsgiWhiteboard whiteboard = new OsgiWhiteboard(context.getBundleContext()); @@ -374,7 +389,7 @@ .newSegmentNodeStore(store); nodeStoreBuilder.withCompactionStrategy(pauseCompaction, cloneBinaries, cleanup, cleanupTs, memoryThreshold, lockWaitTime, retryCount, - forceCommit, persistCompactionMap); + forceCommit, persistCompactionMap, gainThreshold); delegate = nodeStoreBuilder.create(); CompactionStrategy compactionStrategy = nodeStoreBuilder Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/CompactionStrategy.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/CompactionStrategy.java (revision 1689672) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/CompactionStrategy.java (working copy) @@ -76,6 +76,8 @@ public static final boolean PERSIST_COMPACTION_MAP_DEFAULT = true; + public static final byte GAIN_THRESHOLD_DEFAULT = 10; + /** * Default value for {@link #getRetryCount()} */ @@ -122,6 +124,11 @@ private long compactionStart = currentTimeMillis(); + /** + * Compaction gain estimate threshold beyond which compaction should run + */ + private byte gainThreshold = GAIN_THRESHOLD_DEFAULT; + protected CompactionStrategy(boolean paused, boolean cloneBinaries, @Nonnull CleanupType cleanupType, long olderThan, byte memoryThreshold) { checkArgument(olderThan >= 0); @@ -251,6 +258,24 @@ this.retryCount = retryCount; } + /** + * Get the compaction gain estimate threshold beyond which compaction should + * run + * @return gainThreshold + */ + public byte getGainThreshold() { + return gainThreshold; + } + + /** + * Set the compaction gain estimate threshold beyond which compaction should + * run + * @param gainThreshold + */ + public void setGainThreshold(byte gainThreshold) { + this.gainThreshold = gainThreshold; + } + public abstract boolean compacted(@Nonnull Callable setHead) throws Exception; } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/CompactionStrategyMBean.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/CompactionStrategyMBean.java (revision 1689672) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/CompactionStrategyMBean.java (working copy) @@ -72,4 +72,19 @@ * @param retryCount */ void setRetryCount(int retryCount); + + /** + * Get the compaction gain estimate threshold beyond which compaction should + * run + * @return gainThreshold + */ + byte getGainThreshold(); + + /** + * Set the compaction gain estimate threshold beyond which compaction should + * run + * @param gainThreshold + */ + void setGainThreshold(byte gainThreshold); + } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/DefaultCompactionStrategyMBean.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/DefaultCompactionStrategyMBean.java (revision 1689672) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/compaction/DefaultCompactionStrategyMBean.java (working copy) @@ -102,4 +102,15 @@ public void setRetryCount(int retryCount) { strategy.setRetryCount(retryCount); } + + @Override + public byte getGainThreshold() { + return strategy.getGainThreshold(); + } + + @Override + public void setGainThreshold(byte gainThreshold) { + strategy.setGainThreshold(gainThreshold); + } + } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java (revision 1689672) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java (working copy) @@ -461,7 +461,7 @@ CompactionGainEstimate estimate = estimateCompactionGain(); long gain = estimate.estimateCompactionGain(offset); - if (gain >= 10) { + if (gain >= compactionStrategy.getGainThreshold()) { gcMonitor.info( "Estimated compaction in {}, gain is {}% ({}/{}) or ({}/{}), so running compaction", watch, gain, estimate.getReachableSize(),