sijie commented on a change in pull request #1201: ISSUE #570: Entrylog per 
ledger
URL: https://github.com/apache/bookkeeper/pull/1201#discussion_r170562880
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java
 ##########
 @@ -406,98 +457,39 @@ File getCurCompactionLogFile() {
         }
     }
 
-    protected void initialize() throws IOException {
-        // Register listener for disk full notifications.
-        ledgerDirsManager.addLedgerDirsListener(getLedgerDirsListener());
-        // create a new log to write
-        createNewLog();
-    }
-
-    private LedgerDirsListener getLedgerDirsListener() {
-        return new LedgerDirsListener() {
-            @Override
-            public void diskFull(File disk) {
-                // If the current entry log disk is full, then create new entry
-                // log.
-                if (currentDir != null && currentDir.equals(disk)) {
-                    shouldCreateNewEntryLog.set(true);
-                }
-            }
-
-            @Override
-            public void diskAlmostFull(File disk) {
-                // If the current entry log disk is almost full, then create 
new entry
-                // log.
-                if (currentDir != null && currentDir.equals(disk)) {
-                    shouldCreateNewEntryLog.set(true);
-                }
-            }
-
-            @Override
-            public void diskFailed(File disk) {
-                // Nothing to handle here. Will be handled in Bookie
-            }
-
-            @Override
-            public void allDisksFull() {
-                // Nothing to handle here. Will be handled in Bookie
-            }
-
-            @Override
-            public void fatalError() {
-                // Nothing to handle here. Will be handled in Bookie
-            }
-
-            @Override
-            public void diskWritable(File disk) {
-                // Nothing to handle here. Will be handled in Bookie
-            }
-
-            @Override
-            public void diskJustWritable(File disk) {
-                // Nothing to handle here. Will be handled in Bookie
-            }
-        };
-    }
-
-    /**
-     * Rolling a new log file to write.
-     */
-    synchronized void rollLog() throws IOException {
-        createNewLog();
-    }
-
     /**
      * Creates a new log file.
      */
-    void createNewLog() throws IOException {
-        // first tried to create a new log channel. add current log channel to 
ToFlush list only when
-        // there is a new log channel. it would prevent that a log channel is 
referenced by both
-        // *logChannel* and *ToFlush* list.
-        if (null != logChannel) {
-            if (null == logChannelsToFlush) {
-                logChannelsToFlush = new LinkedList<BufferedLogChannel>();
-            }
-
-            // flush the internal buffer back to filesystem but not sync disk
-            // so the readers could access the data from filesystem.
-            logChannel.flush(false);
-
-            // Append ledgers map at the end of entry log
-            appendLedgersMap(logChannel);
-
-            BufferedLogChannel newLogChannel = 
entryLoggerAllocator.createNewLog();
-            logChannelsToFlush.add(logChannel);
-            LOG.info("Flushing entry logger {} back to filesystem, pending for 
syncing entry loggers : {}.",
-                    logChannel.getLogId(), logChannelsToFlush);
-            for (EntryLogListener listener : listeners) {
-                listener.onRotateEntryLog();
+    void createNewLog(Long ledgerId) throws IOException {
+        entryLogManager.acquireLock(ledgerId);
+        try {
+            BufferedLogChannel logChannel = 
entryLogManager.getCurrentLogForLedger(ledgerId);
+            // first tried to create a new log channel. add current log 
channel to ToFlush list only when
+            // there is a new log channel. it would prevent that a log channel 
is referenced by both
+            // *logChannel* and *ToFlush* list.
+            if (null != logChannel) {
+
+                // flush the internal buffer back to filesystem but not sync 
disk
+                logChannel.flush(false);
+
+                // Append ledgers map at the end of entry log
+                appendLedgersMap(ledgerId);
+
+                BufferedLogChannel newLogChannel = 
entryLoggerAllocator.createNewLog();
+                entryLogManager.setCurrentLogForLedger(ledgerId, 
newLogChannel);
+                LOG.info("Flushing entry logger {} back to filesystem, pending 
for syncing entry loggers : {}.",
+                        logChannel.getLogId(), 
entryLogManager.getCopyOfRotatedLogChannels());
+                if (!entryLogPerLedgerEnabled) {
 
 Review comment:
   if you have an interface `createNewLog` at `EntyLogManager`, you don't need 
to do such branch logic here. because the simple entry log manager can do the 
roate entry log, while the per ledger entry log manager doesn't have to.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to