Commit f59b678ef71253199116ee8b7dfba449c49ea41a
1 parent
2f6cc376
Fix retry logic on startup when Cassandra is down
Showing
1 changed file
with
10 additions
and
10 deletions
... | ... | @@ -75,6 +75,7 @@ public abstract class AbstractCassandraCluster { |
75 | 75 | private Environment environment; |
76 | 76 | |
77 | 77 | private Cluster cluster; |
78 | + private Cluster.Builder clusterBuilder; | |
78 | 79 | |
79 | 80 | @Getter(AccessLevel.NONE) private Session session; |
80 | 81 | |
... | ... | @@ -88,29 +89,27 @@ public abstract class AbstractCassandraCluster { |
88 | 89 | |
89 | 90 | protected void init(String keyspaceName) { |
90 | 91 | this.keyspaceName = keyspaceName; |
91 | - Cluster.Builder builder = Cluster.builder() | |
92 | + this.clusterBuilder = Cluster.builder() | |
92 | 93 | .addContactPointsWithPorts(getContactPoints(url)) |
93 | 94 | .withClusterName(clusterName) |
94 | 95 | .withSocketOptions(socketOpts.getOpts()) |
95 | 96 | .withPoolingOptions(new PoolingOptions() |
96 | 97 | .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768) |
97 | 98 | .setMaxRequestsPerConnection(HostDistance.REMOTE, 32768)); |
98 | - builder.withQueryOptions(queryOpts.getOpts()); | |
99 | - builder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase())); | |
99 | + this.clusterBuilder.withQueryOptions(queryOpts.getOpts()); | |
100 | + this.clusterBuilder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase())); | |
100 | 101 | if (ssl) { |
101 | - builder.withSSL(); | |
102 | + this.clusterBuilder.withSSL(); | |
102 | 103 | } |
103 | 104 | if (!jmx) { |
104 | - builder.withoutJMXReporting(); | |
105 | + this.clusterBuilder.withoutJMXReporting(); | |
105 | 106 | } |
106 | 107 | if (!metrics) { |
107 | - builder.withoutMetrics(); | |
108 | + this.clusterBuilder.withoutMetrics(); | |
108 | 109 | } |
109 | 110 | if (credentials) { |
110 | - builder.withCredentials(username, password); | |
111 | + this.clusterBuilder.withCredentials(username, password); | |
111 | 112 | } |
112 | - cluster = builder.build(); | |
113 | - cluster.init(); | |
114 | 113 | if (!isInstall()) { |
115 | 114 | initSession(); |
116 | 115 | } |
... | ... | @@ -139,7 +138,8 @@ public abstract class AbstractCassandraCluster { |
139 | 138 | long endTime = System.currentTimeMillis() + initTimeout; |
140 | 139 | while (System.currentTimeMillis() < endTime) { |
141 | 140 | try { |
142 | - | |
141 | + cluster = clusterBuilder.build(); | |
142 | + cluster.init(); | |
143 | 143 | if (this.keyspaceName != null) { |
144 | 144 | session = cluster.connect(keyspaceName); |
145 | 145 | } else { | ... | ... |