You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/09/29 07:49:35 UTC

[GitHub] [pulsar] 315157973 commented on a change in pull request #12223: fix lost message issues 12221

315157973 commented on a change in pull request #12223:
URL: https://github.com/apache/pulsar/pull/12223#discussion_r718242638



##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -1592,10 +1592,21 @@ synchronized void ledgerClosed(final LedgerHandle lh) {
     }
 
     synchronized void createLedgerAfterClosed() {
-        STATE_UPDATER.set(this, State.CreatingLedger);
-        this.lastLedgerCreationInitiationTimestamp = System.currentTimeMillis();
-        mbean.startDataLedgerCreateOp();
-        asyncCreateLedger(bookKeeper, config, digestType, this, Collections.emptyMap());
+        if(isNeededCreateNewLedgerAfterCloseLedger()) {
+            log.info("[{}] Creating a new ledger after closed", name);
+            STATE_UPDATER.set(this, State.CreatingLedger);
+            this.lastLedgerCreationInitiationTimestamp = System.currentTimeMillis();
+            mbean.startDataLedgerCreateOp();
+            asyncCreateLedger(bookKeeper, config, digestType, this, Collections.emptyMap());
+        }
+    }
+
+    synchronized boolean isNeededCreateNewLedgerAfterCloseLedger() {

Review comment:
       It seems that there is no need to add `synchronized` here
   The following methods have `synchronized`, `isNeededCreateNewLedgerAfterCloseLedger()` is called inside them:
   ```
   createLedgerAfterClosed()
   ledgerClosed(final LedgerHandle lh)
   internalAsyncAddEntry(OpAddEntry addOperation)
   ```
   

##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -1581,7 +1581,7 @@ synchronized void ledgerClosed(final LedgerHandle lh) {
 
         maybeOffloadInBackground(NULL_OFFLOAD_PROMISE);
 
-        if (!pendingAddEntries.isEmpty()) {
+        if (!pendingAddEntries.isEmpty() && isNeededCreateNewLedgerAfterCloseLedger()) {
             // Need to create a new ledger to write pending entries

Review comment:
       It looks like duplicate code here




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org