Author: alexparvulescu
Date: Mon Nov  7 16:19:53 2016
New Revision: 1768546

URL: http://svn.apache.org/viewvc?rev=1768546&view=rev
Log:
OAK-5046 Remove the old estimation OSGi setting (compaction.gainThreshold)
 - patch provided by Andrei Dulceanu


Removed:
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/CompactionGainEstimate.java
Modified:
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentGCOptions.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGC.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGCMBean.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionEstimatorTest.java

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
 Mon Nov  7 16:19:53 2016
@@ -26,12 +26,12 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.osgi.OsgiUtil.lookupConfigurationThenFramework;
 import static 
org.apache.jackrabbit.oak.segment.SegmentNotFoundExceptionListener.IGNORE_SNFE;
 import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.FORCE_TIMEOUT_DEFAULT;
-import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.GAIN_THRESHOLD_DEFAULT;
 import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.MEMORY_THRESHOLD_DEFAULT;
 import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.PAUSE_DEFAULT;
 import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.RETAINED_GENERATIONS_DEFAULT;
 import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.RETRY_COUNT_DEFAULT;
 import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.SIZE_DELTA_ESTIMATION_DEFAULT;
+import static 
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.DISABLE_ESTIMATION_DEFAULT;
 import static 
org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
 import static 
org.apache.jackrabbit.oak.spi.blob.osgi.SplitBlobStoreService.ONLY_STANDALONE_TARGET;
 import static 
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
@@ -188,14 +188,6 @@ public class SegmentNodeStoreService ext
     public static final String NODE_DEDUPLICATION_CACHE_SIZE = 
"nodeDeduplicationCache.size";
 
     @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 between 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"
@@ -228,6 +220,13 @@ public class SegmentNodeStoreService ext
     public static final String COMPACTION_SIZE_DELTA_ESTIMATION = 
"compaction.sizeDeltaEstimation";
 
     @Property(
+            boolValue = DISABLE_ESTIMATION_DEFAULT,
+            label = "Disable Compaction Estimation Phase",
+            description = "Disables compaction estimation phase, thus allowing 
compaction to run every time."
+    )
+    public static final String COMPACTION_DISABLE_ESTIMATION = 
"compaction.disableEstimation";
+
+    @Property(
             intValue = RETAINED_GENERATIONS_DEFAULT,
             label = "Compaction retained generations",
             description = "Number of segment generations to retain."
@@ -632,14 +631,20 @@ public class SegmentNodeStoreService ext
         int forceTimeout = toInteger(property(COMPACTION_FORCE_TIMEOUT), 
FORCE_TIMEOUT_DEFAULT);
         int retainedGenerations = toInteger(property(RETAINED_GENERATIONS), 
RETAINED_GENERATIONS_DEFAULT);
 
-        byte gainThreshold = getGainThreshold();
         long sizeDeltaEstimation = 
toLong(property(COMPACTION_SIZE_DELTA_ESTIMATION), 
SIZE_DELTA_ESTIMATION_DEFAULT);
         int memoryThreshold = toInteger(property(MEMORY_THRESHOLD), 
MEMORY_THRESHOLD_DEFAULT);
+        boolean disableEstimation = 
toBoolean(property(COMPACTION_DISABLE_ESTIMATION), DISABLE_ESTIMATION_DEFAULT);
 
-        return new SegmentGCOptions(pauseCompaction, gainThreshold, 
retryCount, forceTimeout)
+        if (property("compaction.gainThreshold") != null) {
+            log.warn("Deprecated property compaction.gainThreshold was 
detected. In order to configure compaction please use the new property "
+                    + "compaction.sizeDeltaEstimation. For turning off 
estimation, the new property compaction.disableEstimation should be used.");
+        }
+
+        return new SegmentGCOptions(pauseCompaction, retryCount, forceTimeout)
                 .setRetainedGenerations(retainedGenerations)
                 .setGcSizeDeltaEstimation(sizeDeltaEstimation)
-                .setMemoryThreshold(memoryThreshold);
+                .setMemoryThreshold(memoryThreshold)
+                .setEstimationDisabled(disableEstimation);
     }
 
     private void unregisterNodeStore() {
@@ -732,16 +737,6 @@ public class SegmentNodeStoreService ext
         return Integer.parseInt(getMaxFileSizeProperty());
     }
 
-    private byte getGainThreshold() {
-        String gt = property(COMPACTION_GAIN_THRESHOLD);
-
-        if (gt == null) {
-            return GAIN_THRESHOLD_DEFAULT;
-        }
-
-        return Byte.valueOf(gt);
-    }
-
     private String property(String name) {
         return lookupConfigurationThenFramework(context, name);
     }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentGCOptions.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentGCOptions.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentGCOptions.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentGCOptions.java
 Mon Nov  7 16:19:53 2016
@@ -32,9 +32,9 @@ public class SegmentGCOptions {
     public static final boolean PAUSE_DEFAULT = false;
 
     /**
-     * Default value for {@link #getGainThreshold()}
+     * Default value for {@link #isEstimationDisabled()}
      */
-    public static final byte GAIN_THRESHOLD_DEFAULT = 10;
+    public static final boolean DISABLE_ESTIMATION_DEFAULT = false;
 
     /**
      * Default value for {@link #getRetryCount()}
@@ -52,9 +52,9 @@ public class SegmentGCOptions {
     public static final int RETAINED_GENERATIONS_DEFAULT = 2;
 
     /**
-     * Default value for {@link #getGcSizeDeltaEstimation()}
+     * Default value for {@link #getGcSizeDeltaEstimation()} set to 10GB
      */
-    public static final long SIZE_DELTA_ESTIMATION_DEFAULT = -1;
+    public static final long SIZE_DELTA_ESTIMATION_DEFAULT = 10737418240L;
 
     /**
      * Default value for {@link #getMemoryThreshold()}
@@ -63,7 +63,10 @@ public class SegmentGCOptions {
 
     private boolean paused = PAUSE_DEFAULT;
 
-    private int gainThreshold = GAIN_THRESHOLD_DEFAULT;
+    /**
+     * Flag controlling whether the estimation phase will run before a GC cycle
+     */
+    private boolean estimationDisabled = DISABLE_ESTIMATION_DEFAULT;
 
     private int retryCount = RETRY_COUNT_DEFAULT;
 
@@ -86,15 +89,14 @@ public class SegmentGCOptions {
             "oak.segment.compaction.gcSizeDeltaEstimation",
             SIZE_DELTA_ESTIMATION_DEFAULT);
 
-    public SegmentGCOptions(boolean paused, int gainThreshold, int retryCount, 
int forceTimeout) {
+    public SegmentGCOptions(boolean paused, int retryCount, int forceTimeout) {
         this.paused = paused;
-        this.gainThreshold = gainThreshold;
         this.retryCount = retryCount;
         this.forceTimeout = forceTimeout;
     }
 
     public SegmentGCOptions() {
-        this(PAUSE_DEFAULT, GAIN_THRESHOLD_DEFAULT, RETRY_COUNT_DEFAULT, 
FORCE_TIMEOUT_DEFAULT);
+        this(PAUSE_DEFAULT, RETRY_COUNT_DEFAULT, FORCE_TIMEOUT_DEFAULT);
     }
 
     /**
@@ -123,24 +125,6 @@ public class SegmentGCOptions {
     }
 
     /**
-     * Get the gain estimate threshold beyond which revision gc should run
-     * @return gainThreshold
-     */
-    public int getGainThreshold() {
-        return gainThreshold;
-    }
-
-    /**
-     * Set the revision gain estimate threshold beyond which revision gc 
should run
-     * @param gainThreshold
-     * @return this instance
-     */
-    public SegmentGCOptions setGainThreshold(int gainThreshold) {
-        this.gainThreshold = gainThreshold;
-        return this;
-    }
-
-    /**
      * Get the number of tries to compact concurrent commits on top of already
      * compacted commits
      * @return  retry count
@@ -220,7 +204,8 @@ public class SegmentGCOptions {
         } else {
             return getClass().getSimpleName() + "{" +
                     "paused=" + paused +
-                    ", gainThreshold=" + gainThreshold +
+                    ", estimationDisabled=" + estimationDisabled +
+                    ", gcSizeDeltaEstimation=" + gcSizeDeltaEstimation +
                     ", retryCount=" + retryCount +
                     ", forceTimeout=" + forceTimeout +
                     ", retainedGenerations=" + retainedGenerations +
@@ -288,10 +273,6 @@ public class SegmentGCOptions {
         return this.ocBinMaxSize;
     }
 
-    public boolean isGcSizeDeltaEstimation() {
-        return gcSizeDeltaEstimation >= 0;
-    }
-
     public long getGcSizeDeltaEstimation() {
         return gcSizeDeltaEstimation;
     }
@@ -323,4 +304,17 @@ public class SegmentGCOptions {
         this.memoryThreshold = memoryThreshold;
         return this;
     }
+
+    public boolean isEstimationDisabled() {
+        return estimationDisabled;
+    }
+
+    /**
+     * Disables the estimation phase, thus allowing GC to run every time.
+     * @return this instance
+     */
+    public SegmentGCOptions setEstimationDisabled(boolean disabled) {
+        this.estimationDisabled = disabled;
+        return this;
+    }
 }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGC.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGC.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGC.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGC.java
 Mon Nov  7 16:19:53 2016
@@ -43,18 +43,6 @@ public interface SegmentRevisionGC {
     void setPausedCompaction(boolean paused);
 
     /**
-     * Get the gain estimate threshold beyond which revision gc should run
-     * @return gainThreshold
-     */
-    int getGainThreshold();
-
-    /**
-     * Set the revision gain estimate threshold beyond which revision gc 
should run
-     * @param gainThreshold
-     */
-    void setGainThreshold(int gainThreshold);
-
-    /**
      * Get the number of tries to compact concurrent commits on top of already
      * compacted commits
      * @return  retry count
@@ -107,6 +95,14 @@ public interface SegmentRevisionGC {
 
     void setGcSizeDeltaEstimation(long gcSizeDeltaEstimation);
 
+    boolean isEstimationDisabled();
+
+    /**
+     * Disables the estimation phase, thus allowing GC to run every time.
+     * @param disabled
+     */
+    void setEstimationDisabled(boolean disabled);
+
     /**
      * Initiate a revision garbage collection operation
      */

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGCMBean.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGCMBean.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGCMBean.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/SegmentRevisionGCMBean.java
 Mon Nov  7 16:19:53 2016
@@ -64,16 +64,6 @@ public class SegmentRevisionGCMBean
     }
 
     @Override
-    public int getGainThreshold() {
-        return gcOptions.getGainThreshold();
-    }
-
-    @Override
-    public void setGainThreshold(int gainThreshold) {
-        gcOptions.setGainThreshold(gainThreshold);
-    }
-
-    @Override
     public int getRetryCount() {
         return gcOptions.getRetryCount();
     }
@@ -114,6 +104,16 @@ public class SegmentRevisionGCMBean
     }
 
     @Override
+    public boolean isEstimationDisabled() {
+        return gcOptions.isEstimationDisabled();
+    }
+
+    @Override
+    public void setEstimationDisabled(boolean disabled)  {
+        gcOptions.setEstimationDisabled(disabled);
+    }
+
+    @Override
     public void startRevisionGC() {
         fileStore.getGCRunner().run();
     }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
 Mon Nov  7 16:19:53 2016
@@ -347,27 +347,6 @@ public class FileStore extends AbstractF
         }
     }
 
-    /**
-     * Returns the number of segments in this TarMK instance.
-     *
-     * @return number of segments
-     */
-    private int count() {
-        fileStoreLock.readLock().lock();
-        try {
-            int count = 0;
-            if (tarWriter != null) {
-                count += tarWriter.count();
-            }
-            for (TarReader reader : readers) {
-                count += reader.count();
-            }
-            return count;
-        } finally {
-            fileStoreLock.readLock().unlock();
-        }
-    }
-
     public FileStoreStats getStats() {
         return stats;
     }
@@ -747,11 +726,9 @@ public class FileStore extends AbstractF
             GCMemoryBarrier gcMemoryBarrier = new GCMemoryBarrier(
                     sufficientMemory, gcListener, GC_COUNT.get(), gcOptions);
 
-            int gainThreshold = gcOptions.getGainThreshold();
             boolean sufficientEstimatedGain = true;
-            if (gainThreshold <= 0) {
-                gcListener.info("TarMK GC #{}: estimation skipped because gain 
threshold value ({} <= 0)",
-                        GC_COUNT, gainThreshold);
+            if (gcOptions.isEstimationDisabled()) {
+                gcListener.info("TarMK GC #{}: estimation skipped because it 
was explicitly disabled", GC_COUNT);
             } else if (gcOptions.isPaused()) {
                 gcListener.info("TarMK GC #{}: estimation skipped because 
compaction is paused", GC_COUNT);
             } else {
@@ -805,26 +782,8 @@ public class FileStore extends AbstractF
          * @return compaction gain estimate
          */
         synchronized GCEstimation estimateCompactionGain(Supplier<Boolean> 
stop) {
-            if (gcOptions.isGcSizeDeltaEstimation()) {
-                SizeDeltaGcEstimation e = new SizeDeltaGcEstimation(gcOptions,
-                        gcJournal, stats.getApproximateSize());
-                return e;
-            }
-
-            CompactionGainEstimate estimate = new 
CompactionGainEstimate(getHead(),
-                    count(), stop, gcOptions.getGainThreshold());
-            fileStoreLock.readLock().lock();
-            try {
-                for (TarReader reader : readers) {
-                    reader.accept(estimate);
-                    if (stop.get()) {
-                        break;
-                    }
-                }
-            } finally {
-                fileStoreLock.readLock().unlock();
-            }
-            return estimate;
+            return new SizeDeltaGcEstimation(gcOptions, gcJournal,
+                    stats.getApproximateSize());
         }
 
         private void logAndClear(

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
 Mon Nov  7 16:19:53 2016
@@ -221,7 +221,7 @@ public class SegmentCompactionIT {
 
         ScheduledExecutorService executor = 
Executors.newSingleThreadScheduledExecutor();
         SegmentGCOptions gcOptions = defaultGCOptions()
-                .setGainThreshold(0)
+                .setEstimationDisabled(true)
                 .setForceTimeout(3600);
         fileStore = fileStoreBuilder(folder.getRoot())
                 .withMemoryMapping(true)

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionEstimatorTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionEstimatorTest.java?rev=1768546&r1=1768545&r2=1768546&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionEstimatorTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionEstimatorTest.java
 Mon Nov  7 16:19:53 2016
@@ -81,10 +81,6 @@ public class CompactionEstimatorTest {
         try {
             GCEstimation est = fileStore.estimateCompactionGain();
             assertTrue(est.gcNeeded());
-            if (est instanceof CompactionGainEstimate) {
-                // should be at 66%
-                assertTrue(((CompactionGainEstimate) 
est).estimateCompactionGain() > 60);
-            }
         } finally {
             fileStore.close();
         }


Reply via email to