You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "FewJuho (via GitHub)" <gi...@apache.org> on 2025/07/03 10:11:27 UTC

[PR] Ignite 23856 thin cln channels duplication + connection retry logic [ignite]

FewJuho opened a new pull request, #12169:
URL: https://github.com/apache/ignite/pull/12169

   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ignite 23856 thin cln channels duplication + connection retry logic [ignite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #12169:
URL: https://github.com/apache/ignite/pull/12169#issuecomment-3056218645

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12169) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [2 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12169) (required ≤ 1)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12169)
   
   ##   
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png '') Catch issues before they fail your Quality Gate with our IDE extension ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png '') [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
   
   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ignite 23856 thin cln channels duplication + connection retry logic [ignite]

Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim commented on code in PR #12169:
URL: https://github.com/apache/ignite/pull/12169#discussion_r2192884360


##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -243,27 +247,29 @@ private <T> void handleServiceAsync(
         List<ClientConnectionException> failures
     ) {
         try {
-            applyOnDefaultChannel(
-                channel -> applyOnClientChannelAsync(fut, channel, op, payloadWriter, payloadReader, failures),
-                null,
-                failures
-            );
+            ClientChannel ch = applyOnDefaultChannel(Function.identity(), null, failures);
+
+            applyOnClientChannelAsync(fut, ch, op, payloadWriter, payloadReader, failures);
         }
         catch (Throwable ex) {
             fut.completeExceptionally(ex);
         }
     }
 
-    /** */
-    private <T> Object applyOnClientChannelAsync(
+    /**
+     * Performs the operation asynchronously, retrying on the same channel first
+     * if a ClientConnectionException occurs, then falls back to other channels

Review Comment:
   {@code ClientConnectionException}



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23856 Fix java thin client duplicates channels [ignite]

Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim merged PR #12169:
URL: https://github.com/apache/ignite/pull/12169


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ignite 23856 thin cln channels duplication + connection retry logic [ignite]

Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim commented on code in PR #12169:
URL: https://github.com/apache/ignite/pull/12169#discussion_r2183186319


##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -68,8 +68,8 @@ final class ReliableChannel implements AutoCloseable {
     /** Client channel holders for each configured address. */
     private volatile List<ClientChannelHolder> channels;
 
-    /** Limit of attempts to execute each service. */
-    private volatile int attemptsLimit;
+    /** Limit of channels to execute each {@link #service}. */

Review Comment:
   Let's mention that each channel is tried twice, and these attempts counts as 1.



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -272,36 +273,87 @@ private <T> Object applyOnClientChannelAsync(
                     return null;
                 }
 
-                if (err instanceof ClientConnectionException) {
-                    ClientConnectionException failure0 = (ClientConnectionException)err;
+                if (!(err instanceof ClientConnectionException)) {
+                    fut.completeExceptionally(err instanceof ClientException ? err : new ClientException(err));
 
-                    failures.add(failure0);
+                    return null;
+                }
 
-                    try {
-                        // Will try to reinit channels if topology changed.
-                        onChannelFailure(ch, err, failures);
-                    }
-                    catch (Throwable ex) {
-                        fut.completeExceptionally(ex);
+                ClientConnectionException connEx = (ClientConnectionException)err;
 
-                        return null;
-                    }
+                if (!shouldRetry(op, failures.size() - 1, connEx)) {
+                    failures.add(connEx);
 
-                    if (failures.size() < attemptsLimit && shouldRetry(op, failures.size() - 1, failure0)) {
-                        handleServiceAsync(fut, op, payloadWriter, payloadReader, failures);
+                    fut.completeExceptionally(composeException(failures));
 
-                        return null;
-                    }
+                    return null;
+                }
 
-                    fut.completeExceptionally(composeException(failures));
+                // Retry use same channel in case of connection exception.
+                UUID nodeId = ch.serverNodeId();
+
+                ClientChannel retryCh = null;
+
+                ClientChannelHolder hld;
+
+                try {
+                    hld = (nodeId != null) ? nodeChannels.get(nodeId) : null;

Review Comment:
   `ClientChannelHolder hld = ...`



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -272,36 +273,87 @@ private <T> Object applyOnClientChannelAsync(
                     return null;
                 }
 
-                if (err instanceof ClientConnectionException) {
-                    ClientConnectionException failure0 = (ClientConnectionException)err;
+                if (!(err instanceof ClientConnectionException)) {
+                    fut.completeExceptionally(err instanceof ClientException ? err : new ClientException(err));
 
-                    failures.add(failure0);
+                    return null;
+                }
 
-                    try {
-                        // Will try to reinit channels if topology changed.
-                        onChannelFailure(ch, err, failures);
-                    }
-                    catch (Throwable ex) {
-                        fut.completeExceptionally(ex);
+                ClientConnectionException connEx = (ClientConnectionException)err;
 
-                        return null;
-                    }
+                if (!shouldRetry(op, failures.size() - 1, connEx)) {
+                    failures.add(connEx);
 
-                    if (failures.size() < attemptsLimit && shouldRetry(op, failures.size() - 1, failure0)) {
-                        handleServiceAsync(fut, op, payloadWriter, payloadReader, failures);
+                    fut.completeExceptionally(composeException(failures));
 
-                        return null;
-                    }
+                    return null;
+                }
 
-                    fut.completeExceptionally(composeException(failures));
+                // Retry use same channel in case of connection exception.
+                UUID nodeId = ch.serverNodeId();
+
+                ClientChannel retryCh = null;

Review Comment:
   This is no need to initialize this variable



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -68,8 +68,8 @@ final class ReliableChannel implements AutoCloseable {
     /** Client channel holders for each configured address. */
     private volatile List<ClientChannelHolder> channels;
 
-    /** Limit of attempts to execute each service. */
-    private volatile int attemptsLimit;
+    /** Limit of channels to execute each {@link #service}. */
+    private volatile int srvcChannelsLimit;

Review Comment:
   let's revert naming.



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -243,27 +243,28 @@ private <T> void handleServiceAsync(
         List<ClientConnectionException> failures
     ) {
         try {
-            applyOnDefaultChannel(
-                channel -> applyOnClientChannelAsync(fut, channel, op, payloadWriter, payloadReader, failures),
-                null,
-                failures
-            );
+            ClientChannel ch = applyOnDefaultChannel(Function.identity(), null, failures);
+
+            applyOnClientChannelAsync(fut, ch, op, payloadWriter, payloadReader, failures);
         }
         catch (Throwable ex) {
             fut.completeExceptionally(ex);
         }
     }
 
-    /** */
-    private <T> Object applyOnClientChannelAsync(
+    /**
+     * Retries an async operation on the same channel if it fails with a connection exception

Review Comment:
   Let's mention that this method performs operation asynchronously, and in case of ClientConnectionException tries the same channel first.



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -922,19 +964,46 @@ private <T> T applyOnNodeChannelWithFallback(UUID tryNodeId, Function<ClientChan
                 return function.apply(channel);
             }
             catch (ClientConnectionException e) {
-                failures = new ArrayList<>();
-                failures.add(e);
+                if (!shouldRetry(op, 0, e))
+                    throw e;
+
+                try {
+                    channel = getRetryChannel(hld, channel);
 
-                onChannelFailure(hld, channel, e, failures);
+                    return function.apply(channel);
+                }
 
-                if (attemptsLimit == 1 || !shouldRetry(op, 0, e))
-                    throw e;
+                catch (ClientConnectionException err) {
+                    failures = new ArrayList<>();
+
+                    failures.add(err);
+
+                    onChannelFailure(hld, channel, err, failures);
+
+                    if (srvcChannelsLimit == 1 || !shouldRetry(op, 1, e))
+                        throw err;
+                }
             }
         }
 
         return applyOnDefaultChannel(function, op, failures);
     }
 
+    /**
+     * Returns the client channel that should be used to retry sending the request.
+     * Unlike onChannelFailure, invoked only for a reconnection attempt on the same channel without channels initialization.
+     */
+    private ClientChannel getRetryChannel(ClientChannelHolder hld, ClientChannel ch) {

Review Comment:
   Code duplication with `onChannelFailure`



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -272,36 +273,87 @@ private <T> Object applyOnClientChannelAsync(
                     return null;
                 }
 
-                if (err instanceof ClientConnectionException) {
-                    ClientConnectionException failure0 = (ClientConnectionException)err;
+                if (!(err instanceof ClientConnectionException)) {
+                    fut.completeExceptionally(err instanceof ClientException ? err : new ClientException(err));
 
-                    failures.add(failure0);
+                    return null;
+                }
 
-                    try {
-                        // Will try to reinit channels if topology changed.
-                        onChannelFailure(ch, err, failures);
-                    }
-                    catch (Throwable ex) {
-                        fut.completeExceptionally(ex);
+                ClientConnectionException connEx = (ClientConnectionException)err;
 
-                        return null;
-                    }
+                if (!shouldRetry(op, failures.size() - 1, connEx)) {
+                    failures.add(connEx);
 
-                    if (failures.size() < attemptsLimit && shouldRetry(op, failures.size() - 1, failure0)) {
-                        handleServiceAsync(fut, op, payloadWriter, payloadReader, failures);
+                    fut.completeExceptionally(composeException(failures));
 
-                        return null;
-                    }
+                    return null;
+                }
 
-                    fut.completeExceptionally(composeException(failures));
+                // Retry use same channel in case of connection exception.
+                UUID nodeId = ch.serverNodeId();

Review Comment:
   Move nodeId definition inside the following try block (closer to place where it's used).



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -272,36 +273,87 @@ private <T> Object applyOnClientChannelAsync(
                     return null;
                 }
 
-                if (err instanceof ClientConnectionException) {
-                    ClientConnectionException failure0 = (ClientConnectionException)err;
+                if (!(err instanceof ClientConnectionException)) {
+                    fut.completeExceptionally(err instanceof ClientException ? err : new ClientException(err));
 
-                    failures.add(failure0);
+                    return null;
+                }
 
-                    try {
-                        // Will try to reinit channels if topology changed.
-                        onChannelFailure(ch, err, failures);

Review Comment:
   Now the method `onChannelFailure(ClientChannel, Throwable, List)` is unused



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ignite 23856 thin cln channels duplication + connection retry logic [ignite]

Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim commented on code in PR #12169:
URL: https://github.com/apache/ignite/pull/12169#discussion_r2192878478


##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -68,7 +68,11 @@ final class ReliableChannel implements AutoCloseable {
     /** Client channel holders for each configured address. */
     private volatile List<ClientChannelHolder> channels;
 
-    /** Limit of attempts to execute each service. */
+    /**
+     * Limit of attempts to execute each {@link #service}.
+     * Each channel is tried twice, and both attempts count as a single value

Review Comment:
   1. single value -> single attempt.
   2. move "toward this limit" on the previous line.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org