From f59b678ef71253199116ee8b7dfba449c49ea41a Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Tue, 9 Jan 2018 15:49:34 +0200 Subject: [PATCH] Fix retry logic on startup when Cassandra is down --- .../cassandra/AbstractCassandraCluster.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java b/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java index 36d1b783ea..f37fa93106 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java +++ b/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java @@ -75,6 +75,7 @@ public abstract class AbstractCassandraCluster { private Environment environment; private Cluster cluster; + private Cluster.Builder clusterBuilder; @Getter(AccessLevel.NONE) private Session session; @@ -88,29 +89,27 @@ public abstract class AbstractCassandraCluster { protected void init(String keyspaceName) { this.keyspaceName = keyspaceName; - Cluster.Builder builder = Cluster.builder() + this.clusterBuilder = Cluster.builder() .addContactPointsWithPorts(getContactPoints(url)) .withClusterName(clusterName) .withSocketOptions(socketOpts.getOpts()) .withPoolingOptions(new PoolingOptions() .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768) .setMaxRequestsPerConnection(HostDistance.REMOTE, 32768)); - builder.withQueryOptions(queryOpts.getOpts()); - builder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase())); + this.clusterBuilder.withQueryOptions(queryOpts.getOpts()); + this.clusterBuilder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase())); if (ssl) { - builder.withSSL(); + this.clusterBuilder.withSSL(); } if (!jmx) { - builder.withoutJMXReporting(); + this.clusterBuilder.withoutJMXReporting(); } if (!metrics) { - builder.withoutMetrics(); + this.clusterBuilder.withoutMetrics(); } if (credentials) { - builder.withCredentials(username, password); + this.clusterBuilder.withCredentials(username, password); } - cluster = builder.build(); - cluster.init(); if (!isInstall()) { initSession(); } @@ -139,7 +138,8 @@ public abstract class AbstractCassandraCluster { long endTime = System.currentTimeMillis() + initTimeout; while (System.currentTimeMillis() < endTime) { try { - + cluster = clusterBuilder.build(); + cluster.init(); if (this.keyspaceName != null) { session = cluster.connect(keyspaceName); } else {