Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time #3012

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class GarbageCollectorThread extends SafeRunnable {

final ServerConfiguration conf;

private static final AtomicLong threadNum = new AtomicLong(0);
/**
* Create a garbage collector thread.
*
Expand Down Expand Up @@ -339,7 +340,22 @@ public void start() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testLedgerDelete() throws Exception {
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) {
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testLedgerDeleteWithExistingEntryLogs() throws Exception {
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
Expand Down