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 2018/07/23 14:35:14 UTC

[GitHub] eolivelli closed pull request #1557: ISSUE #1541: Fix ReadOnlyBookie constructor

eolivelli closed pull request #1557: ISSUE #1541: Fix ReadOnlyBookie constructor
URL: https://github.com/apache/bookkeeper/pull/1557
 
 
   

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/Bookie.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
index 2b893876e5..79153dc6c8 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
@@ -138,7 +138,7 @@
     protected StateManager stateManager;
 
     // Expose Stats
-    private final StatsLogger statsLogger;
+    final StatsLogger statsLogger;
     private final Counter writeBytes;
     private final Counter readBytes;
     private final Counter forceLedgerOps;
@@ -641,7 +641,7 @@ public Bookie(ServerConfiguration conf, StatsLogger statsLogger)
         } catch (MetadataException e) {
             throw new MetadataStoreException("Failed to initialize ledger manager", e);
         }
-        stateManager = new BookieStateManager(conf, statsLogger, metadataDriver, ledgerDirsManager);
+        stateManager = initializeStateManager();
         // register shutdown handler using trigger mode
         stateManager.setShutdownHandler(exitCode -> triggerBookieShutdown(exitCode));
         // Initialise ledgerDirMonitor. This would look through all the
@@ -745,6 +745,10 @@ public void start() {
         readBytesStats = statsLogger.getOpStatsLogger(BOOKIE_READ_ENTRY_BYTES);
     }
 
+    StateManager initializeStateManager() throws IOException {
+        return new BookieStateManager(conf, statsLogger, metadataDriver, ledgerDirsManager);
+    }
+
     void readJournal() throws IOException, BookieException {
         long startTs = MathUtils.now();
         JournalScanner scanner = new JournalScanner() {
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ReadOnlyBookie.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ReadOnlyBookie.java
index 4bd36640f7..5125c077fe 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ReadOnlyBookie.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ReadOnlyBookie.java
@@ -41,7 +41,19 @@
     public ReadOnlyBookie(ServerConfiguration conf, StatsLogger statsLogger)
             throws IOException, KeeperException, InterruptedException, BookieException {
         super(conf, statsLogger);
-        stateManager = new BookieStateManager(conf, statsLogger, metadataDriver, getLedgerDirsManager()) {
+        if (conf.isReadOnlyModeEnabled()) {
+            stateManager.forceToReadOnly();
+        } else {
+            String err = "Try to init ReadOnly Bookie, while ReadOnly mode is not enabled";
+            LOG.error(err);
+            throw new IOException(err);
+        }
+        LOG.info("Running bookie in force readonly mode.");
+    }
+
+    @Override
+    StateManager initializeStateManager() throws IOException {
+        return new BookieStateManager(conf, statsLogger, metadataDriver, getLedgerDirsManager()) {
 
             @Override
             public void doTransitionToWritableMode() {
@@ -55,13 +67,5 @@ public void doTransitionToReadOnlyMode() {
                 LOG.info("Skip transition to readonly mode for readonly bookie");
             }
         };
-        if (conf.isReadOnlyModeEnabled()) {
-            stateManager.forceToReadOnly();
-        } else {
-            String err = "Try to init ReadOnly Bookie, while ReadOnly mode is not enabled";
-            LOG.error(err);
-            throw new IOException(err);
-        }
-        LOG.info("Running bookie in force readonly mode.");
     }
 }


 

----------------------------------------------------------------
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