You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2017/11/03 16:13:42 UTC

[GitHub] eolivelli closed pull request #690: ISSUE #501: Fix race in CompactionTest

eolivelli closed pull request #690: ISSUE #501: Fix race in CompactionTest
URL: https://github.com/apache/bookkeeper/pull/690
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
index ebebca231..5dcd4a055 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
@@ -278,7 +278,8 @@ public void clean(long ledgerId) {
     public void enableForceGC() {
         if (forceGarbageCollection.compareAndSet(false, true)) {
             LOG.info("Forced garbage collection triggered by thread: {}", Thread.currentThread().getName());
-            triggerGC();
+            triggerGC(true, suspendMajorCompaction.get(),
+                      suspendMinorCompaction.get());
         }
     }
 
@@ -289,11 +290,22 @@ public void disableForceGC() {
         }
     }
 
-    /**
-     * Manually trigger GC (for testing).
-     */
+    Future<?> triggerGC(final boolean force,
+                        final boolean suspendMajor,
+                        final boolean suspendMinor) {
+        return gcExecutor.submit(() -> {
+                runWithFlags(force, suspendMajor, suspendMinor);
+            });
+    }
+
     Future<?> triggerGC() {
-        return gcExecutor.submit(this);
+        final boolean force = forceGarbageCollection.get();
+        final boolean suspendMajor = suspendMajorCompaction.get();
+        final boolean suspendMinor = suspendMinorCompaction.get();
+
+        return gcExecutor.submit(() -> {
+                runWithFlags(force, suspendMajor, suspendMinor);
+            });
     }
 
     public void suspendMajorGC() {
@@ -332,6 +344,19 @@ public void start() {
     @Override
     public void safeRun() {
         boolean force = forceGarbageCollection.get();
+        boolean suspendMajor = suspendMajorCompaction.get();
+        boolean suspendMinor = suspendMinorCompaction.get();
+
+        runWithFlags(force, suspendMajor, suspendMinor);
+
+        if (force) {
+            // only set force to false if it had been true when the garbage
+            // collection cycle started
+            forceGarbageCollection.set(false);
+        }
+    }
+
+    public void runWithFlags(boolean force, boolean suspendMajor, boolean suspendMinor) {
         if (force) {
             LOG.info("Garbage collector thread forced to perform GC before expiry of wait time.");
         }
@@ -346,8 +371,6 @@ public void safeRun() {
         // gc entry logs
         doGcEntryLogs();
 
-        boolean suspendMajor = suspendMajorCompaction.get();
-        boolean suspendMinor = suspendMinorCompaction.get();
         if (suspendMajor) {
             LOG.info("Disk almost full, suspend major compaction to slow down filling disk.");
         }
@@ -364,7 +387,6 @@ public void safeRun() {
             lastMajorCompactionTime = MathUtils.now();
             // and also move minor compaction time
             lastMinorCompactionTime = lastMajorCompactionTime;
-            forceGarbageCollection.set(false);
             return;
         }
 
@@ -375,7 +397,6 @@ public void safeRun() {
             doCompactEntryLogs(minorCompactionThreshold);
             lastMinorCompactionTime = MathUtils.now();
         }
-        forceGarbageCollection.set(false);
     }
 
     /**
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
index 9fcba8f13..57b9404ed 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
@@ -397,8 +397,7 @@ public void testMinorCompactionWithNoWritableLedgerDirsButIsForceGCAllowWhenNoSp
         bkc.deleteLedger(lhs[2].getId());
 
         LOG.info("Finished deleting the ledgers contains most entries.");
-        getGCThread().enableForceGC();
-        getGCThread().triggerGC().get();
+        getGCThread().triggerGC(true, false, false).get();
 
         // after garbage collection, major compaction should not be executed
         assertEquals(lastMajorCompactionTime, getGCThread().lastMajorCompactionTime);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services