You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by yo...@apache.org on 2022/02/22 00:42:19 UTC
[bookkeeper] branch master updated: set Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time (#3012)
This is an automated email from the ASF dual-hosted git repository.
yong 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 894b32a set Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time (#3012)
894b32a is described below
commit 894b32a1dafd4aebd7916b7a889a4aa57dbd48ee
Author: StevenLuMT <42...@users.noreply.github.com>
AuthorDate: Tue Feb 22 08:42:13 2022 +0800
set Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time (#3012)
Descriptions of the changes in this PR:
### Motivation
when number of ledger's Dir are more than 1,the same of GarbageCollectorThread will do the same thing,
Especially:
1) deleting ledger, then SyncThread will be timed to do rocksDB compact
2) compact: entry, cost cpu.
### Changes
set a Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time
---
.../bookkeeper/bookie/GarbageCollectorThread.java | 18 +++++++++++++++++-
.../org/apache/bookkeeper/test/LedgerDeleteTest.java | 4 ++--
2 files changed, 19 insertions(+), 3 deletions(-)
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 ba02864..6b559e0 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
@@ -125,6 +125,7 @@ public class GarbageCollectorThread extends SafeRunnable {
final ServerConfiguration conf;
final LedgerDirsManager ledgerDirsManager;
+ private static final AtomicLong threadNum = new AtomicLong(0);
/**
* Create a garbage collector thread.
*
@@ -349,7 +350,22 @@ public class GarbageCollectorThread extends SafeRunnable {
if (scheduledFuture != null) {
scheduledFuture.cancel(false);
}
- scheduledFuture = gcExecutor.scheduleAtFixedRate(this, gcWaitTime, gcWaitTime, TimeUnit.MILLISECONDS);
+ long initialDelay = getModInitialDelay();
+ scheduledFuture = gcExecutor.scheduleAtFixedRate(this, initialDelay, gcWaitTime, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * when number of ledger's Dir are more than 1,the same of GarbageCollectorThread will do the same thing,
+ * Especially
+ * 1) deleting ledger, then SyncThread will be timed to do rocksDB compact
+ * 2) compact: entry, cost cpu.
+ * then get Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time
+ */
+ public long getModInitialDelay() {
+ int ledgerDirsNum = conf.getLedgerDirs().length;
+ long splitTime = gcWaitTime / ledgerDirsNum;
+ long currentThreadNum = threadNum.incrementAndGet();
+ return gcWaitTime + currentThreadNum * splitTime;
}
@Override
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java
index 65a7035..bd78a43 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java
@@ -129,7 +129,7 @@ public class LedgerDeleteTest extends BookKeeperClusterTestCase {
bkc.deleteLedger(lh.getId());
}
LOG.info("Finished deleting all ledgers so waiting for the GC thread to clean up the entryLogs");
- Thread.sleep(2000);
+ Thread.sleep(5000);
// Verify that the first entry log (0.log) has been deleted from all of the Bookie Servers.
for (File ledgerDirectory : ledgerDirectories) {
@@ -163,7 +163,7 @@ public class LedgerDeleteTest extends BookKeeperClusterTestCase {
bkc.deleteLedger(lh.getId());
}
LOG.info("Finished deleting all ledgers so waiting for the GC thread to clean up the entryLogs");
- Thread.sleep(2 * baseConf.getGcWaitTime());
+ Thread.sleep(5000);
/*
* Verify that the first two entry logs ([0,1].log) have been deleted