timoninmaxim commented on a change in pull request #8206:
URL: https://github.com/apache/ignite/pull/8206#discussion_r504774568



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
##########
@@ -223,67 +203,78 @@
     ) throws ClientException, ClientError {
         CompletableFuture<T> fut = new CompletableFuture<>();
 
-        ClientChannel ch = channel();
-
-        ch.serviceAsync(op, payloadWriter, payloadReader).handle((res, err) ->
-                handleServiceAsync(op, payloadWriter, payloadReader, fut, 
null, null, ch, res, err));
+        // Use the only one attempt to avoid blocking async method.
+        handleServiceAsync(fut, op, payloadWriter, payloadReader, 1, null);
 
         return new IgniteClientFutureImpl<>(fut);
     }
 
     /**
      * Handles serviceAsync results and retries as needed.
      */
-    private <T> Object handleServiceAsync(ClientOperation op,
-                                          Consumer<PayloadOutputChannel> 
payloadWriter,
-                                          Function<PayloadInputChannel, T> 
payloadReader,
-                                          CompletableFuture<T> fut,
-                                          ClientConnectionException failure,
-                                          AtomicInteger chIdx,
-                                          ClientChannel ch,
-                                          T res,
-                                          Throwable err) {
-        if (err == null) {
-            fut.complete(res);
-            return null;
+    private <T> void handleServiceAsync(final CompletableFuture<T> fut,
+                                        ClientOperation op,
+                                        Consumer<PayloadOutputChannel> 
payloadWriter,
+                                        Function<PayloadInputChannel, T> 
payloadReader,
+                                        int attemptsLimit,
+                                        ClientConnectionException failure) {
+        T2<ClientChannel, Integer> chAndAttempts;
+
+        try {
+            chAndAttempts = applyOnDefaultChannel(channel -> channel, 
attemptsLimit);

Review comment:
       Currently master branch do work approach you describe, and it leads to:
   1. introducing additional AtomicInteger variable for attempts counter. 
Counter is required as it used in separate threads execute `handleServiceAsync` 
method;
   2. code duplication for iterating through channels (for sync and async 
methods).
   
   This is reasons to use T2. It's not pretty, but the alternative doesn't 
looks better, I think.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to