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


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -4353,7 +4353,22 @@ 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)) {
+                LedgerHandle currentLedger = this.currentLedger;
+                currentLedger.asyncClose((rc, lh, o) -> {
+                    checkArgument(currentLedger.getId() == lh.getId(), 
"ledgerId %s doesn't match with "
+                            + "acked ledgerId %s", currentLedger.getId(), 
lh.getId());
+
+                    if (rc == Code.OK) {
+                        log.debug("Successfully closed ledger {}", lh.getId());
+                    } else {
+                        log.warn("Error when closing ledger {}. Status={}", 
lh.getId(), BKException.getMessage(rc));
+                    }
+
+                    ledgerClosed(lh);
+                    // we do not create ledger here, since topic is inactive 
for a long time.
+                }, System.nanoTime());

Review Comment:
   The context `System.nanoTime()` is not used. Can we set this param to `null`?



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -4353,7 +4353,22 @@ 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)) {
+                LedgerHandle currentLedger = this.currentLedger;
+                currentLedger.asyncClose((rc, lh, o) -> {
+                    checkArgument(currentLedger.getId() == lh.getId(), 
"ledgerId %s doesn't match with "
+                            + "acked ledgerId %s", currentLedger.getId(), 
lh.getId());
+
+                    if (rc == Code.OK) {
+                        log.debug("Successfully closed ledger {}", lh.getId());
+                    } else {
+                        log.warn("Error when closing ledger {}. Status={}", 
lh.getId(), BKException.getMessage(rc));

Review Comment:
   The log should include the name of this managed ledger object, such as 
   
   ```java
   log.warn("[{}] Error when closing ledger...", name,...);
   ```
   
   BTW, can you also change `rollCurrentLedgerIfFull`'s log in this PR? And it 
is better to make these two logs are not the same, so it is easier to 
troubleshoot problems based on logs.
   
   



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to