You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "lhotari (via GitHub)" <gi...@apache.org> on 2023/05/11 04:16:40 UTC

[GitHub] [pulsar] lhotari commented on a diff in pull request #20276: [fix][ml] Fix ledger left in OPEN state when enable `inactiveLedgerRollOverTimeMs`

lhotari commented on code in PR #20276:
URL: https://github.com/apache/pulsar/pull/20276#discussion_r1190616415


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -4353,7 +4353,21 @@ public void checkInactiveLedgerAndRollOver() {
         long currentTimeMs = System.currentTimeMillis();
         if (inactiveLedgerRollOverTimeMs > 0 && currentTimeMs > (lastAddEntryTimeMs + inactiveLedgerRollOverTimeMs)) {
             log.info("[{}] Closing inactive ledger, last-add entry {}", name, lastAddEntryTimeMs);
-            ledgerClosed(currentLedger);
+            if (STATE_UPDATER.compareAndSet(this, State.LedgerOpened, State.ClosingLedger)) {
+                currentLedger.asyncClose((rc, lh, o) -> {

Review Comment:
   please extract a local variable for `currentLedger` since there could be a race condition where a new ledger might be created while the ledger is being closed. Opening the new ledger would update the `currentLedger` field and this would make the callback code to fail.
   ```suggestion
                   LedgerHandle currentLedger = this.currentLedger;
                   currentLedger.asyncClose((rc, lh, o) -> {
   ```
   
   



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