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 2022/09/08 14:19:35 UTC

[GitHub] [pulsar] codelipenghui commented on a diff in pull request #17228: [fix][storage] refresh the ledgers map when the offload complete failed

codelipenghui commented on code in PR #17228:
URL: https://github.com/apache/pulsar/pull/17228#discussion_r966028335


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -2357,6 +2357,42 @@ private void maybeOffloadInBackground(CompletableFuture<PositionImpl> promise) {
         }
     }
 
+    // Although we have caught the connection loss exception on the meta store, to avoid other exceptions cause
+    // the mismatch between meta store and in memory, we refresh the ledger info list when the offload execute
+    // failed by badversion
+    private void asyncRefreshLedgersInfoOnBadVersion(ManagedLedgerException exception) {
+        if (!(exception instanceof BadVersionException)) {
+            return;
+        }
+        if (!metadataMutex.tryLock()) {
+            scheduledExecutor.schedule(
+                () -> asyncRefreshLedgersInfoOnBadVersion(exception), 100, TimeUnit.MILLISECONDS);
+            return;
+        }
+        store.getManagedLedgerInfo(name, false, new MetaStoreCallback<>() {
+            @Override
+            public void operationComplete(ManagedLedgerInfo mlInfo, Stat stat) {
+                ledgersStat = stat;
+                try {
+                    synchronized (ManagedLedgerImpl.this) {

Review Comment:
   I think here should be an issue because maybe there is another operation that updated the ledger list (take the lock first), and then here takes the lock which will mess up the ledger list again.



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -2366,6 +2402,9 @@ private void maybeOffload(CompletableFuture<PositionImpl> finalPromise) {
             unlockingPromise.whenComplete((res, ex) -> {
                     offloadMutex.unlock();
                     if (ex != null) {
+                        if (FutureUtil.unwrapCompletionException(ex) instanceof ManagedLedgerException) {

Review Comment:
   Looks like we don't need check here? `asyncRefreshLedgersInfoOnBadVersion` already checked exception type



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