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/24 09:05:47 UTC

[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #17777: [fix][txn] optimize the ack/send future in TransactionImpl

liangyepianzhou commented on code in PR #17777:
URL: https://github.com/apache/pulsar/pull/17777#discussion_r979206264


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionImpl.java:
##########
@@ -123,8 +132,25 @@ public CompletableFuture<Void> registerProducedTopic(String topic) {
         return completableFuture;
     }
 
-    public synchronized void registerSendOp(CompletableFuture<MessageId> sendFuture) {
-        sendFutureList.add(sendFuture);
+    public void registerSendOp(CompletableFuture<MessageId> newSendFuture) {
+        sendLock.lock();
+        try {
+            if (sendCount.getAndIncrement() == 0) {
+                sendFuture = new CompletableFuture<>();
+            }
+        } finally {
+            sendLock.unlock();
+        }
+        newSendFuture.thenRun(() -> {
+            sendLock.lock();

Review Comment:
   
   1. decrease the opCount 1 -> 0 
   2. check opCount == 0, and then increase the opCount 0 -> 1
   3. future = new future;
   4. future.complete
   5. finally, the future is completely and opCount is 1



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