ptupitsyn commented on a change in pull request #9863:
URL: https://github.com/apache/ignite/pull/9863#discussion_r822606629



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
##########
@@ -705,9 +727,68 @@ private ClientException handleIOError(String chInfo, 
@Nullable IOException ex) {
         return new ClientConnectionException("Ignite cluster is unavailable [" 
+ chInfo + ']', ex);
     }
 
+    /**
+     * Initializes heartbeats.
+     *
+     * @param configuredInterval Configured heartbeat interval, in 
milliseconds.
+     * @return Heartbeat timer.
+     */
+    private Timer initHeartbeat(long configuredInterval) {
+        long heartbeatInterval = getHeartbeatInterval(configuredInterval);
+
+        Timer timer = new Timer("tcp-client-channel-heartbeats-" + hashCode());
+
+        timer.schedule(new HeartbeatTask(heartbeatInterval), 
heartbeatInterval, heartbeatInterval);
+
+        return timer;
+    }
+
+    /**
+     * Gets the heartbeat interval based on the configured value and 
served-side idle timeout.
+     *
+     * @param configuredInterval Configured interval.
+     * @return Resolved interval.
+     */
+    private long getHeartbeatInterval(long configuredInterval) {
+        long serverIdleTimeoutMs = service(ClientOperation.GET_IDLE_TIMEOUT, 
null, in -> in.in().readLong());
+
+        if (serverIdleTimeoutMs <= 0)
+            return configuredInterval;
+
+        long recommendedHeartbeatInterval = serverIdleTimeoutMs / 3;
+
+        if (recommendedHeartbeatInterval < MIN_RECOMMENDED_HEARTBEAT_INTERVAL)
+            recommendedHeartbeatInterval = MIN_RECOMMENDED_HEARTBEAT_INTERVAL;
+
+        return Math.min(configuredInterval, recommendedHeartbeatInterval);

Review comment:
       Then it is what it is. We do what the user says.




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