diff --git a/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastConstants.java b/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastConstants.java index b179a674d..6d7471668 100644 --- a/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastConstants.java +++ b/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastConstants.java @@ -127,6 +127,17 @@ public final class HazelcastConstants */ public static final String SSL_PROTOCOLS = "hazelcast.ssl.protocols"; + /** + * Hazelcast heartbeat interval + */ + public static final int HEARTBEAT_INTERVAL_SECONDS = 5; + + /** + * Hazelcast heartbeat timeout + */ + // !Important change the value if the heartbeat timeout value of Hetu nodes changed + public static final int HEARTBEAT_TIMEOUT_SECONDS = 10; + private HazelcastConstants() { } diff --git a/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreBootstrapper.java b/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreBootstrapper.java index 23a4a83b6..978141ac9 100644 --- a/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreBootstrapper.java +++ b/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreBootstrapper.java @@ -72,6 +72,8 @@ public class HazelcastStateStoreBootstrapper { private HazelcastInstance hzInstance; private static final String MERGED_DYNAMIC_FILTERS = "merged-dynamic-filters"; + private static final String HEARTBEAT_INTERVAL_SECONDS = "hazelcast.heartbeat.interval.seconds"; + private static final String HEARTBEAT_TIMEOUT_SECONDS = "hazelcast.max.no.heartbeat.seconds"; private static final int MAXIDLESECONDS = 30; private static final int EVICTIONSIZE = 200; private static final int TIMETOLIVESECONDS = 300; @@ -103,6 +105,10 @@ public class HazelcastStateStoreBootstrapper // Set discovery port hzConfig = setPortConfigs(config, hzConfig); + // Set timeout rules + hzConfig.setProperty(HEARTBEAT_INTERVAL_SECONDS, String.valueOf(HazelcastConstants.HEARTBEAT_INTERVAL_SECONDS)); + hzConfig.setProperty(HEARTBEAT_TIMEOUT_SECONDS, String.valueOf(HazelcastConstants.HEARTBEAT_TIMEOUT_SECONDS + HazelcastConstants.HEARTBEAT_INTERVAL_SECONDS)); + // Set hazelcast authentication config if (Boolean.parseBoolean(config.get(KERBEROS_ENABLED))) { hzConfig.getSecurityConfig().setEnabled(true); diff --git a/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreFactory.java b/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreFactory.java index 286f04018..23ba30b3d 100644 --- a/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreFactory.java +++ b/hetu-state-store/src/main/java/io/hetu/core/statestore/hazelcast/HazelcastStateStoreFactory.java @@ -80,6 +80,8 @@ public class HazelcastStateStoreFactory private static final int SEED_IP_FETCHING_RETRY_TIMES = 10; private static final long SEED_IP_FETCHING_INITIAL_RETRY_INTERVAL = 500L; private static final String COMMA = ","; + private static final String CLIENT_HEARTBEAT_TIMEOUT = "hazelcast.client.heartbeat.timeout"; + private static final String CLIENT_HEARTBEAT_INTERVAL = "hazelcast.client.heartbeat.interval"; private String name = "hazelcast"; private final Map stateStoreFactories = new ConcurrentHashMap<>(0); @@ -128,6 +130,10 @@ public class HazelcastStateStoreFactory SslConfig.setProtocols(properties.get(SSL_PROTOCOLS)); } + // Set heartbeat config + clientConfig.setProperty(CLIENT_HEARTBEAT_TIMEOUT, String.valueOf(HazelcastConstants.HEARTBEAT_TIMEOUT_SECONDS * 1000)); + clientConfig.setProperty(CLIENT_HEARTBEAT_INTERVAL, String.valueOf(HazelcastConstants.HEARTBEAT_INTERVAL_SECONDS * 1000)); + final String discoveryMode = properties.get(DISCOVERY_MODE_CONFIG_NAME); if (discoveryMode == null || discoveryMode.equalsIgnoreCase(DISCOVERY_MODE_MULTICAST)) {