Author: mduerig
Date: Thu Oct  6 09:04:04 2016
New Revision: 1763539

URL: http://svn.apache.org/viewvc?rev=1763539&view=rev
Log:
OAK-4621: External invocation of background operations
Remove the gc scheduler in favour of external invocation

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/file/FileStore.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/HeavyWriteIT.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/SegmentOverflowExceptionIT.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=1763539&r1=1763538&r2=1763539&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
 Thu Oct  6 09:04:04 2016
@@ -465,19 +465,10 @@ public class SegmentNodeStoreService ext
 
         // Expose an MBean to trigger garbage collection
 
-        Runnable triggerGarbageCollection = new Runnable() {
-
-            @Override
-            public void run() {
-                store.gc();
-            }
-
-        };
-
         registrations.add(registerMBean(
                 whiteboard,
                 RevisionGCMBean.class,
-                new RevisionGC(triggerGarbageCollection, executor),
+                new RevisionGC(store.getGCRunner(), executor),
                 RevisionGCMBean.TYPE,
                 "Segment node store revision garbage collection"
         ));

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=1763539&r1=1763538&r2=1763539&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
 Thu Oct  6 09:04:04 2016
@@ -180,11 +180,6 @@ public class FileStore implements Segmen
     private final TarRevisions revisions;
 
     /**
-     * Scheduler for running compaction and cleanup in the background
-     */
-    private final Scheduler gcScheduler = new Scheduler("GC Scheduler");
-
-    /**
      * Scheduler for running <em>short</em> background operations
      */
     private final Scheduler fileStoreScheduler = new Scheduler("FileStore 
background tasks");
@@ -330,13 +325,6 @@ public class FileStore implements Segmen
             this.tarWriter = null;
         }
 
-        // FIXME OAK-4621: External invocation of background operations
-        // The following background operations are historically part of
-        // the implementation of the FileStore, but they should better be
-        // scheduled and invoked by an external agent. The code deploying the
-        // FileStore might have better insights on when and how these 
background
-        // operations should be invoked. See also OAK-3468.
-
         sufficientDiskSpace = new AtomicBoolean(true);
 
         if (!readOnly) {
@@ -482,7 +470,27 @@ public class FileStore implements Segmen
         return segmentWriter.getNodeCacheStats();
     }
 
-    public void maybeCompact(boolean cleanup) throws IOException {
+    /**
+     * @return  a runnable for running garbage collection
+     */
+    public Runnable getGCRunner() {
+        return new SafeRunnable(format("TarMK revision gc [%s]", directory), 
new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    gc();
+                } catch (IOException e) {
+                    log.error("Error running compaction", e);
+                }
+            }
+        });
+    }
+
+    /**
+     * Run garbage collection: estimation, compaction, cleanup
+     * @throws IOException
+     */
+    public void gc() throws IOException {
         gcListener.info("TarMK GC #{}: started", GC_COUNT.incrementAndGet());
         Stopwatch watch = Stopwatch.createStarted();
 
@@ -1190,8 +1198,7 @@ public class FileStore implements Segmen
         shutdown = true;
 
         // avoid deadlocks by closing (and joining) the background
-        // threads before acquiring the synchronization lock
-        gcScheduler.close();
+        // thread before acquiring the synchronization lock
         fileStoreScheduler.close();
 
         try {
@@ -1442,22 +1449,6 @@ public class FileStore implements Segmen
         return blobStore;
     }
 
-    /**
-     * Trigger a garbage collection cycle
-     */
-    public void gc() {
-        gcScheduler.execute(format("TarMK compaction [%s]", directory), new 
Runnable() {
-            @Override
-            public void run() {
-                try {
-                    maybeCompact(true);
-                } catch (IOException e) {
-                    log.error("Error running compaction", e);
-                }
-            }
-        });
-    }
-
     public Map<String, Set<UUID>> getTarReaderIndex() {
         Map<String, Set<UUID>> index = new HashMap<String, Set<UUID>>();
         for (TarReader reader : readers) {
@@ -1593,7 +1584,7 @@ public class FileStore implements Segmen
         }
 
         @Override
-        public void gc() {
+        public SafeRunnable getGCRunner() {
             throw new UnsupportedOperationException("Read Only Store");
         }
 
@@ -1603,7 +1594,7 @@ public class FileStore implements Segmen
         }
 
         @Override
-        public void maybeCompact(boolean cleanup) {
+        public void gc() {
             throw new UnsupportedOperationException("Read Only Store");
         }
     }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/HeavyWriteIT.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/HeavyWriteIT.java?rev=1763539&r1=1763538&r2=1763539&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/HeavyWriteIT.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/HeavyWriteIT.java
 Thu Oct  6 09:04:04 2016
@@ -70,12 +70,14 @@ public class HeavyWriteIT {
             @Override
             public void run() {
                 for (int k = 1; run.get(); k++) {
-                    store.gc();
                     try {
+                        store.gc();
                         Thread.sleep(5000);
                     } catch (InterruptedException e) {
                         Thread.currentThread().interrupt();
                         break;
+                    } catch (IOException e) {
+                        e.printStackTrace();
                     }
                 }
             }

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=1763539&r1=1763538&r2=1763539&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
 Thu Oct  6 09:04:04 2016
@@ -147,8 +147,8 @@ public class SegmentCompactionIT {
     private volatile int maxWriters = 10;
     private volatile long maxStoreSize = 200000000000L;
     private volatile int maxBlobSize = 1000000;
-    private volatile int maxStringSize = 10000;
-    private volatile int maxReferences = 10;
+    private volatile int maxStringSize = 100;
+    private volatile int maxReferences = 0;
     private volatile int maxWriteOps = 10000;
     private volatile int maxNodeCount = 1000;
     private volatile int maxPropertyCount = 1000;
@@ -156,8 +156,8 @@ public class SegmentCompactionIT {
     private volatile int propertyRemoveRatio = 10;
     private volatile int nodeAddRatio = 40;
     private volatile int addStringRatio = 20;
-    private volatile int addBinaryRatio = 20;
-    private volatile int compactionInterval = 1;
+    private volatile int addBinaryRatio = 0;
+    private volatile int compactionInterval = 60;
     private volatile boolean stopping;
     private volatile Reference rootReference;
     private volatile long fileStoreSize;
@@ -221,8 +221,10 @@ public class SegmentCompactionIT {
     public void setUp() throws Exception {
         assumeTrue(ENABLED);
 
-        SegmentGCOptions gcOptions = defaultGCOptions();
         ScheduledExecutorService executor = 
Executors.newSingleThreadScheduledExecutor();
+        SegmentGCOptions gcOptions = defaultGCOptions()
+                .setGainThreshold(0)
+                .setForceTimeout(3600);
         fileStore = fileStoreBuilder(folder.getRoot())
                 .withMemoryMapping(true)
                 .withGCMonitor(gcMonitor)
@@ -664,7 +666,7 @@ public class SegmentCompactionIT {
                         @Override
                         public Void call() throws Exception {
                             gcMonitor.resetCleaned();
-                            fileStore.maybeCompact(true);
+                            fileStore.getGCRunner().run();
                             return null;
                         }
                     });

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java?rev=1763539&r1=1763538&r2=1763539&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentOverflowExceptionIT.java
 Thu Oct  6 09:04:04 2016
@@ -30,7 +30,6 @@ import java.util.Random;
 
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Blob;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.segment.file.FileStore;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
@@ -109,7 +108,7 @@ public class SegmentOverflowExceptionIT
 
                     if (compact) {
                         compact = false;
-                        fileStore.maybeCompact(true);
+                        fileStore.gc();
                     }
                 } catch (SegmentNotFoundException snfe) {
                     // Usually this can be ignored as SNFEs are somewhat 
expected here


Reply via email to