codelipenghui commented on a change in pull request #14664:
URL: https://github.com/apache/pulsar/pull/14664#discussion_r825535957



##########
File path: 
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -1670,8 +1670,8 @@ boolean isNeededCreateNewLedgerAfterCloseLedger() {
     @Override
     public void rollCurrentLedgerIfFull() {
         log.info("[{}] Start checking if current ledger is full", name);
-        if (currentLedgerEntries > 0 && currentLedgerIsFull()) {
-            STATE_UPDATER.set(this, State.ClosingLedger);
+        if (currentLedgerEntries > 0 && currentLedgerIsFull()
+                && STATE_UPDATER.compareAndSet(this, State.LedgerOpened, 
State.ClosingLedger)) {

Review comment:
       For other states, we don't need to roll over the ledger. For example, if 
the state == `State.ClosingLedger`, means others already started the ledger 
rollover, we can skip the ledger full check at this time.




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