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/19 14:10:57 UTC

[GitHub] [pulsar] tisonkun opened a new pull request, #17718: [improve][txn] reduce unnecessary nested futures

tisonkun opened a new pull request, #17718:
URL: https://github.com/apache/pulsar/pull/17718

   cc @gaoran10 @BewareMyPower @codelipenghui @eolivelli @syhily
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
   
   - [x] `doc-not-needed` 
   (Please explain why)
   
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)
   
   ### Matching PR in forked repository
   
   PR in forked repository: 
   


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


[GitHub] [pulsar] tisonkun closed pull request #17718: [improve][txn] reduce unnecessary nested futures

Posted by GitBox <gi...@apache.org>.
tisonkun closed pull request #17718: [improve][txn] reduce unnecessary nested futures
URL: https://github.com/apache/pulsar/pull/17718


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


[GitHub] [pulsar] lhotari commented on pull request #17718: [improve][txn] reduce unnecessary nested futures

Posted by GitBox <gi...@apache.org>.
lhotari commented on PR #17718:
URL: https://github.com/apache/pulsar/pull/17718#issuecomment-1251827913

   /pulsarbot rerun-failure-checks


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


[GitHub] [pulsar] tisonkun commented on pull request #17718: [improve][txn] reduce unnecessary nested futures

Posted by GitBox <gi...@apache.org>.
tisonkun commented on PR #17718:
URL: https://github.com/apache/pulsar/pull/17718#issuecomment-1251904103

   @congbobo184 Thanks for your explanation.
   
   ```java
           var f0 = new CompletableFuture<Void>();
           var f1 = f0.thenCompose((e) -> CompletableFuture.<Void>completedFuture(null));
           f1.thenAccept((e) -> System.out.println(1));
           var f2 = f1.thenCompose((e) -> CompletableFuture.<Void>completedFuture(null));
           f2.thenAccept((e) -> System.out.println(2));
           f0.complete(null);
   ```
   
   gives `1 2`; while
   
   ```java
           var f0 = new CompletableFuture<Void>();
           f0.thenAccept((e) -> System.out.println(1));
           f0.thenAccept((e) -> System.out.println(2));
           f0.complete(null);
   ```
   
   gives `2 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


[GitHub] [pulsar] syhily commented on a diff in pull request #17718: [improve][txn] reduce unnecessary nested futures

Posted by GitBox <gi...@apache.org>.
syhily commented on code in PR #17718:
URL: https://github.com/apache/pulsar/pull/17718#discussion_r974760724


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionImpl.java:
##########
@@ -133,15 +133,9 @@ public CompletableFuture<Void> registerAckedTopic(String topic, String subscript
         if (checkIfOpen(completableFuture)) {
             synchronized (TransactionImpl.this) {
                 // we need to issue the request to TC to register the acked topic
-                return registerSubscriptionMap.compute(Pair.of(topic, subscription), (key, future) -> {
-                    if (future != null) {
-                        return future.thenCompose(ignored -> CompletableFuture.completedFuture(null));
-                    } else {
-                        return tcClient.addSubscriptionToTxnAsync(
-                                new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription)
-                                .thenCompose(ignored -> CompletableFuture.completedFuture(null));
-                    }
-                });
+                return registerSubscriptionMap.computeIfAbsent(Pair.of(topic, subscription), key ->
+                        tcClient.addSubscriptionToTxnAsync(
+                                new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription));
             }
         }
         return completableFuture;

Review Comment:
   No need to `checkIfOpen`, because it will always be open.
   
   ```
       public CompletableFuture<Void> registerAckedTopic(String topic, String subscription) {
           CompletableFuture<Void> completableFuture = new CompletableFuture<>();
           synchronized (TransactionImpl.this) {
               // we need to issue the request to TC to register the acked topic
               return registerSubscriptionMap.computeIfAbsent(Pair.of(topic, subscription), key ->
                       tcClient.addSubscriptionToTxnAsync(new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription));
           }
       }
   ```



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionImpl.java:
##########
@@ -133,15 +133,9 @@ public CompletableFuture<Void> registerAckedTopic(String topic, String subscript
         if (checkIfOpen(completableFuture)) {
             synchronized (TransactionImpl.this) {
                 // we need to issue the request to TC to register the acked topic
-                return registerSubscriptionMap.compute(Pair.of(topic, subscription), (key, future) -> {
-                    if (future != null) {
-                        return future.thenCompose(ignored -> CompletableFuture.completedFuture(null));
-                    } else {
-                        return tcClient.addSubscriptionToTxnAsync(
-                                new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription)
-                                .thenCompose(ignored -> CompletableFuture.completedFuture(null));
-                    }
-                });
+                return registerSubscriptionMap.computeIfAbsent(Pair.of(topic, subscription), key ->
+                        tcClient.addSubscriptionToTxnAsync(
+                                new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription));
             }
         }
         return completableFuture;

Review Comment:
   No need to `checkIfOpen`, because it will always be open.
   
   ```
   public CompletableFuture<Void> registerAckedTopic(String topic, String subscription) {
       CompletableFuture<Void> completableFuture = new CompletableFuture<>();
       synchronized (TransactionImpl.this) {
           // we need to issue the request to TC to register the acked topic
           return registerSubscriptionMap.computeIfAbsent(Pair.of(topic, subscription), key ->
                   tcClient.addSubscriptionToTxnAsync(new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription));
       }
   }
   ```



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


[GitHub] [pulsar] syhily commented on a diff in pull request #17718: [improve][txn] reduce unnecessary nested futures

Posted by GitBox <gi...@apache.org>.
syhily commented on code in PR #17718:
URL: https://github.com/apache/pulsar/pull/17718#discussion_r974760724


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionImpl.java:
##########
@@ -133,15 +133,9 @@ public CompletableFuture<Void> registerAckedTopic(String topic, String subscript
         if (checkIfOpen(completableFuture)) {
             synchronized (TransactionImpl.this) {
                 // we need to issue the request to TC to register the acked topic
-                return registerSubscriptionMap.compute(Pair.of(topic, subscription), (key, future) -> {
-                    if (future != null) {
-                        return future.thenCompose(ignored -> CompletableFuture.completedFuture(null));
-                    } else {
-                        return tcClient.addSubscriptionToTxnAsync(
-                                new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription)
-                                .thenCompose(ignored -> CompletableFuture.completedFuture(null));
-                    }
-                });
+                return registerSubscriptionMap.computeIfAbsent(Pair.of(topic, subscription), key ->
+                        tcClient.addSubscriptionToTxnAsync(
+                                new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription));
             }
         }
         return completableFuture;

Review Comment:
   No need to `checkIfOpen`, because it will always be open.
   
   ```suggestion
       public CompletableFuture<Void> registerAckedTopic(String topic, String subscription) {
           CompletableFuture<Void> completableFuture = new CompletableFuture<>();
           synchronized (TransactionImpl.this) {
               // we need to issue the request to TC to register the acked topic
               return registerSubscriptionMap.computeIfAbsent(Pair.of(topic, subscription), key ->
                       tcClient.addSubscriptionToTxnAsync(new TxnID(txnIdMostBits, txnIdLeastBits), topic, subscription));
           }
       }
   ```



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


[GitHub] [pulsar] tisonkun commented on pull request #17718: [improve][txn] reduce unnecessary nested futures

Posted by GitBox <gi...@apache.org>.
tisonkun commented on PR #17718:
URL: https://github.com/apache/pulsar/pull/17718#issuecomment-1251753729

   /pulsarbot run-failure-checks


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