diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java index 3120663f21a72..f6c9fb3bfd806 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java @@ -1554,16 +1554,16 @@ public void operationComplete(Void v, Stat stat) { log.debug("[{}] Updating of ledgers list after create complete. version={}", name, stat); } ledgersStat = stat; - ledgers.put(lh.getId(), newLedger); - currentLedger = lh; - currentLedgerEntries = 0; - currentLedgerSize = 0; - metadataMutex.unlock(); - updateLedgersIdsComplete(); synchronized (ManagedLedgerImpl.this) { + ledgers.put(lh.getId(), newLedger); + currentLedger = lh; + currentLedgerEntries = 0; + currentLedgerSize = 0; + updateLedgersIdsComplete(); mbean.addLedgerSwitchLatencySample(System.currentTimeMillis() - lastLedgerCreationInitiationTimestamp, TimeUnit.MILLISECONDS); } + metadataMutex.unlock(); // May need to update the cursor position maybeUpdateCursorBeforeTrimmingConsumedLedger();