You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by eo...@apache.org on 2022/02/11 07:16:40 UTC

[bookkeeper] branch master updated: [ISSUE 3038] Fixed flaky CompactionTest.testMinorCompactionWithMaxTimeMillis (#3039)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 0de75bc  [ISSUE 3038] Fixed flaky CompactionTest.testMinorCompactionWithMaxTimeMillis (#3039)
0de75bc is described below

commit 0de75bc1ad6521bb96e358fe69882425afe8c260
Author: Andrey Yegorov <86...@users.noreply.github.com>
AuthorDate: Thu Feb 10 23:16:30 2022 -0800

    [ISSUE 3038] Fixed flaky CompactionTest.testMinorCompactionWithMaxTimeMillis (#3039)
---
 .../apache/bookkeeper/bookie/CompactionTest.java   | 71 +++++++++++++++++++++-
 1 file changed, 68 insertions(+), 3 deletions(-)

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 1c2ee73..aef181f 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
@@ -402,7 +402,7 @@ public abstract class CompactionTest extends BookKeeperClusterTestCase {
     }
 
     @Test
-    public void testMinorCompactionWithMaxTimeMillis() throws Exception {
+    public void testMinorCompactionWithMaxTimeMillisOk() throws Exception {
         // prepare data
         LedgerHandle[] lhs = prepareData(6, false);
 
@@ -419,8 +419,10 @@ public abstract class CompactionTest extends BookKeeperClusterTestCase {
             c.setMajorCompactionInterval(240000);
 
             // Setup limit on compaction duration.
-            c.setMinorCompactionMaxTimeMillis(15);
-            c.setMajorCompactionMaxTimeMillis(15);
+            // The limit is enough to compact.
+            c.setMinorCompactionMaxTimeMillis(5000);
+            c.setMajorCompactionMaxTimeMillis(5000);
+
             return c;
         });
 
@@ -477,7 +479,70 @@ public abstract class CompactionTest extends BookKeeperClusterTestCase {
     }
 
 
+    @Test
+    public void testMinorCompactionWithMaxTimeMillisTooShort() throws Exception {
+        // prepare data
+        LedgerHandle[] lhs = prepareData(6, false);
+
+        for (LedgerHandle lh : lhs) {
+            lh.close();
+        }
+
+        // disable major compaction
+        // restart bookies
+        restartBookies(c-> {
+            c.setMajorCompactionThreshold(0.0f);
+            c.setGcWaitTime(60000);
+            c.setMinorCompactionInterval(120000);
+            c.setMajorCompactionInterval(240000);
+
+            // Setup limit on compaction duration.
+            // The limit is not enough to finish the compaction
+            c.setMinorCompactionMaxTimeMillis(1);
+            c.setMajorCompactionMaxTimeMillis(1);
+
+            return c;
+        });
+
+        getGCThread().enableForceGC();
+        getGCThread().triggerGC().get();
+        assertTrue(
+                "ACTIVE_ENTRY_LOG_COUNT should have been updated",
+                getStatsProvider(0)
+                        .getGauge("bookie.gc." + ACTIVE_ENTRY_LOG_COUNT)
+                        .getSample().intValue() > 0);
+        assertTrue(
+                "ACTIVE_ENTRY_LOG_SPACE_BYTES should have been updated",
+                getStatsProvider(0)
+                        .getGauge("bookie.gc." + ACTIVE_ENTRY_LOG_SPACE_BYTES)
+                        .getSample().intValue() > 0);
+
+        long lastMinorCompactionTime = getGCThread().lastMinorCompactionTime;
+        long lastMajorCompactionTime = getGCThread().lastMajorCompactionTime;
+        assertFalse(getGCThread().enableMajorCompaction);
+        assertTrue(getGCThread().enableMinorCompaction);
+
+        // remove ledger2 and ledger3
+        bkc.deleteLedger(lhs[1].getId());
+        bkc.deleteLedger(lhs[2].getId());
 
+        LOG.info("Finished deleting the ledgers contains most entries.");
+        getGCThread().enableForceGC();
+        getGCThread().triggerGC().get();
+
+        // after garbage collection, major compaction should not be executed
+        assertEquals(lastMajorCompactionTime, getGCThread().lastMajorCompactionTime);
+        assertTrue(getGCThread().lastMinorCompactionTime > lastMinorCompactionTime);
+
+        // entry logs ([0,1,2].log) should be compacted.
+        for (File ledgerDirectory : tmpDirs.getDirs()) {
+            // Compaction of at least one of the files should not finish up
+            assertTrue("Not found entry log file ([0,1,2].log that should not have been compacted in ledgerDirectory: "
+                    + ledgerDirectory, TestUtils.hasLogFiles(ledgerDirectory, true, 0, 1, 2));
+        }
+
+        verifyLedger(lhs[0].getId(), 0, lhs[0].getLastAddConfirmed());
+    }
 
     @Test
     public void testForceMinorCompaction() throws Exception {