From 4e427c63599ceb55e2e33a64df7b20f7952d10e0 Mon Sep 17 00:00:00 2001 From: yma Date: Tue, 15 Oct 2024 11:26:31 +0800 Subject: [PATCH] Update Cassandra reconnect policy and default delay value --- .../indy/subsys/cassandra/CassandraClient.java | 3 +++ .../subsys/cassandra/config/CassandraConfig.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/CassandraClient.java b/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/CassandraClient.java index e70fc3edff..8401878313 100644 --- a/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/CassandraClient.java +++ b/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/CassandraClient.java @@ -18,6 +18,7 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; import com.datastax.driver.core.SocketOptions; +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; import org.commonjava.indy.subsys.cassandra.config.CassandraConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,6 +76,8 @@ private void init() socketOptions.setReadTimeoutMillis( config.getReadTimeoutMillis() ); Cluster.Builder builder = Cluster.builder() .withoutJMXReporting() + .withReconnectionPolicy( + new ConstantReconnectionPolicy( config.getConstantDelayMs() ) ) .withRetryPolicy( new ConfigurableRetryPolicy( config.getReadRetries(), config.getWriteRetries() ) ) .addContactPoint( host ) diff --git a/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/config/CassandraConfig.java b/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/config/CassandraConfig.java index eac31b1e18..612f1c41bc 100644 --- a/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/config/CassandraConfig.java +++ b/subsys/cassandra/src/main/java/org/commonjava/indy/subsys/cassandra/config/CassandraConfig.java @@ -45,6 +45,8 @@ public class CassandraConfig private int writeRetries = 3; + private long constantDelayMs = 60000; + public CassandraConfig() { } @@ -152,6 +154,17 @@ public void setWriteRetries( int writeRetries ) this.writeRetries = writeRetries; } + public long getConstantDelayMs() + { + return constantDelayMs; + } + + @ConfigName( "cassandra.reconnect.delay" ) + public void setConstantDelayMs( long constantDelayMs ) + { + this.constantDelayMs = constantDelayMs; + } + @Override public String getDefaultConfigFileName() {