From d7fffac47f013a6902f9b61e8f8ffcb3ed29abff Mon Sep 17 00:00:00 2001 From: Sijie Guo Date: Wed, 28 Nov 2018 12:07:29 -0800 Subject: [PATCH] [LEDGER STORAGE] DbLedgerStorage should do periodical flush Descriptions of the changes in this PR: *Motivation* DbLedgerStorage doesn't drive checkpoint itself. so currently DbLedgerStorage flush only happens either when write-cache is full or entry log file rotated. The correctness is still maintained. However the behavior is different from original yahoo behavior. *Changes* Revert the behavior back to original periodical flush Reviewers: Matteo Merli , Jia Zhai This closes #1843 from sijie/dbledgerstorage_sync --- .../org/apache/bookkeeper/bookie/Bookie.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java index f91bf285b4f..ffb92ed2d76 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java @@ -63,6 +63,7 @@ import org.apache.bookkeeper.bookie.LedgerDirsManager.LedgerDirsListener; import org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException; import org.apache.bookkeeper.bookie.stats.BookieStats; +import org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage; import org.apache.bookkeeper.common.util.Watcher; import org.apache.bookkeeper.conf.ServerConfiguration; import org.apache.bookkeeper.discover.RegistrationManager; @@ -681,14 +682,22 @@ public Bookie(ServerConfiguration conf, StatsLogger statsLogger) LOG.info("Using ledger storage: {}", ledgerStorageClass); ledgerStorage = LedgerStorageFactory.createLedgerStorage(ledgerStorageClass); + boolean isDbLedgerStorage = ledgerStorage instanceof DbLedgerStorage; + /* * with this change https://github.com/apache/bookkeeper/pull/677, - * LedgerStorage drives the checkpoint logic. But with multiple entry - * logs, checkpoint logic based on a entry log is not possible, hence it - * needs to be timebased recurring thing and it is driven by SyncThread. - * SyncThread.start does that and it is started in Bookie.start method. + * LedgerStorage drives the checkpoint logic. + * + *

There are two exceptions: + * + * 1) with multiple entry logs, checkpoint logic based on a entry log is + * not possible, hence it needs to be timebased recurring thing and + * it is driven by SyncThread. SyncThread.start does that and it is + * started in Bookie.start method. + * + * 2) DbLedgerStorage */ - if (entryLogPerLedgerEnabled) { + if (entryLogPerLedgerEnabled || isDbLedgerStorage) { syncThread = new SyncThread(conf, getLedgerDirsListener(), ledgerStorage, checkpointSource) { @Override public void startCheckpoint(Checkpoint checkpoint) {