From 91c403bc467b6526c7e41af5a82b13b1d2fcf160 Mon Sep 17 00:00:00 2001 From: yma Date: Tue, 15 Oct 2024 10:26:08 +0800 Subject: [PATCH] Update Cassandra reconnect policy and default delay value --- .../data/cassandra/CassandraClient.java | 9 ++++++--- .../data/cassandra/CassandraConfiguration.java | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraClient.java b/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraClient.java index 121d068..ca2e628 100644 --- a/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraClient.java +++ b/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraClient.java @@ -18,12 +18,13 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; import com.datastax.driver.core.SocketOptions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -75,6 +76,8 @@ public 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/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraConfiguration.java b/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraConfiguration.java index 27dba18..ad24713 100644 --- a/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraConfiguration.java +++ b/src/main/java/org/commonjava/indy/service/tracking/data/cassandra/CassandraConfiguration.java @@ -16,10 +16,10 @@ package org.commonjava.indy.service.tracking.data.cassandra; import io.quarkus.runtime.Startup; -import org.eclipse.microprofile.config.inject.ConfigProperty; - import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; + import java.util.Optional; import static java.util.Optional.of; @@ -65,6 +65,10 @@ public class CassandraConfiguration @ConfigProperty( name = "cassandra.retries.write", defaultValue = "3" ) int writeRetries; + @Inject + @ConfigProperty( name = "cassandra.reconnect.delay", defaultValue = "60000" ) + long constantDelayMs; + @Inject @ConfigProperty( name = "cassandra.keyspace" ) Optional keyspace; @@ -167,6 +171,16 @@ public void setWriteRetries( int writeRetries ) this.writeRetries = writeRetries; } + public long getConstantDelayMs() + { + return constantDelayMs; + } + + public void setConstantDelayMs( long constantDelayMs ) + { + this.constantDelayMs = constantDelayMs; + } + public String getKeyspace() { return keyspace.orElse( "" );