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,6 +75,7 @@ public abstract class AbstractCassandraCluster { | ||
75 | private Environment environment; | 75 | private Environment environment; |
76 | 76 | ||
77 | private Cluster cluster; | 77 | private Cluster cluster; |
78 | + private Cluster.Builder clusterBuilder; | ||
78 | 79 | ||
79 | @Getter(AccessLevel.NONE) private Session session; | 80 | @Getter(AccessLevel.NONE) private Session session; |
80 | 81 | ||
@@ -88,29 +89,27 @@ public abstract class AbstractCassandraCluster { | @@ -88,29 +89,27 @@ public abstract class AbstractCassandraCluster { | ||
88 | 89 | ||
89 | protected void init(String keyspaceName) { | 90 | protected void init(String keyspaceName) { |
90 | this.keyspaceName = keyspaceName; | 91 | this.keyspaceName = keyspaceName; |
91 | - Cluster.Builder builder = Cluster.builder() | 92 | + this.clusterBuilder = Cluster.builder() |
92 | .addContactPointsWithPorts(getContactPoints(url)) | 93 | .addContactPointsWithPorts(getContactPoints(url)) |
93 | .withClusterName(clusterName) | 94 | .withClusterName(clusterName) |
94 | .withSocketOptions(socketOpts.getOpts()) | 95 | .withSocketOptions(socketOpts.getOpts()) |
95 | .withPoolingOptions(new PoolingOptions() | 96 | .withPoolingOptions(new PoolingOptions() |
96 | .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768) | 97 | .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768) |
97 | .setMaxRequestsPerConnection(HostDistance.REMOTE, 32768)); | 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 | if (ssl) { | 101 | if (ssl) { |
101 | - builder.withSSL(); | 102 | + this.clusterBuilder.withSSL(); |
102 | } | 103 | } |
103 | if (!jmx) { | 104 | if (!jmx) { |
104 | - builder.withoutJMXReporting(); | 105 | + this.clusterBuilder.withoutJMXReporting(); |
105 | } | 106 | } |
106 | if (!metrics) { | 107 | if (!metrics) { |
107 | - builder.withoutMetrics(); | 108 | + this.clusterBuilder.withoutMetrics(); |
108 | } | 109 | } |
109 | if (credentials) { | 110 | if (credentials) { |
110 | - builder.withCredentials(username, password); | 111 | + this.clusterBuilder.withCredentials(username, password); |
111 | } | 112 | } |
112 | - cluster = builder.build(); | ||
113 | - cluster.init(); | ||
114 | if (!isInstall()) { | 113 | if (!isInstall()) { |
115 | initSession(); | 114 | initSession(); |
116 | } | 115 | } |
@@ -139,7 +138,8 @@ public abstract class AbstractCassandraCluster { | @@ -139,7 +138,8 @@ public abstract class AbstractCassandraCluster { | ||
139 | long endTime = System.currentTimeMillis() + initTimeout; | 138 | long endTime = System.currentTimeMillis() + initTimeout; |
140 | while (System.currentTimeMillis() < endTime) { | 139 | while (System.currentTimeMillis() < endTime) { |
141 | try { | 140 | try { |
142 | - | 141 | + cluster = clusterBuilder.build(); |
142 | + cluster.init(); | ||
143 | if (this.keyspaceName != null) { | 143 | if (this.keyspaceName != null) { |
144 | session = cluster.connect(keyspaceName); | 144 | session = cluster.connect(keyspaceName); |
145 | } else { | 145 | } else { |