liangyepianzhou commented on a change in pull request #13348:
URL: https://github.com/apache/pulsar/pull/13348#discussion_r776747678



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionImpl.java
##########
@@ -148,8 +152,32 @@ public synchronized void 
registerSendOp(CompletableFuture<MessageId> sendFuture)
         }
     }
 
+    public synchronized <T> void registerInternal(CompletableFuture<T> 
completableFuture) {
+        //There have been an exception, it means this transaction should not 
be commit,
+        //so there is no need to record the execution of other operations
+        if (!executedFuture.isCompletedExceptionally()) {
+            opsExecutingInTxn.incrementAndGet();
+            executedFuture = new CompletableFuture<>();
+            completableFuture.thenRun(() -> {
+                synchronized (this) {
+                    opsExecutingInTxn.decrementAndGet();
+                    // This is the last operation so far.
+                    if (opsExecutingInTxn.get() == 0) {
+                        executedFuture.complete(null);
+                    }
+                }
+            }).exceptionally(e -> {
+                //Complete this future exceptionally and there is no need to 
executed this method again.
+                synchronized (this) {

Review comment:
       When a thread passes the if judgment and prepares  to new a future, if 
an exception completely here, it will be ignored.




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