Skip to content

Commit

Permalink
Don't close cluster when shutting down driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
acabezas committed Jun 28, 2019
1 parent 166ba6f commit 8e04770
Showing 1 changed file with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class CassandraPhotonDriver implements PhotonDriver {

private final Properties properties;
private final PartitionHelper partitionHelper;
private Cluster cluster;
private Session session;
private Session multiRegionSession;
private BeamDao beamDao;
Expand All @@ -94,9 +93,6 @@ public void shutDown() {
Optional.ofNullable(multiRegionSession)
.filter(s -> !s.isClosed())
.ifPresent(Session::close);
Optional.ofNullable(cluster)
.filter(c -> !c.isClosed())
.ifPresent(Cluster::close);
beamDao = null;
beamDataDao = null;
beamDataManifestDao = null;
Expand Down Expand Up @@ -174,16 +170,7 @@ public PartitionHelper getPartitionHelper() {
return partitionHelper;
}

private Cluster getCluster(String[] contactPoints, String userName, String password, SSLOptions sslOptions) {
return Optional.ofNullable(cluster)
.filter(c -> !c.isClosed())
.orElseGet(() -> {
cluster = buildCluster(contactPoints, userName, password, sslOptions);
return cluster;
});
}

private Cluster buildCluster(String[] contactPoints, String userName, String password, SSLOptions sslOptions) {
private Session buildSession(String[] contactPoints, String userName, String password, String keySpace, SSLOptions sslOptions) {
Cluster.Builder builder = new Cluster.Builder()
.addContactPoints(contactPoints)
.withAuthProvider(new PlainTextAuthProvider(userName, password))
Expand All @@ -196,7 +183,7 @@ private Cluster buildCluster(String[] contactPoints, String userName, String pas
}

try {
return builder.build();
return builder.build().connect(keySpace);
} catch (NoHostAvailableException e) {
log.warn("Failed to connect to the cassandra DB with SSL enabled, trying again without SSL: {}", e.getMessage());
return new Cluster.Builder()
Expand All @@ -205,12 +192,10 @@ private Cluster buildCluster(String[] contactPoints, String userName, String pas
.withLoadBalancingPolicy(getLoadBalancingPolicy())
.withPoolingOptions(getPoolingOptions())
.withoutJMXReporting()
.build();
.build()
.connect(keySpace);
}
}

private Session buildSession(String[] contactPoints, String userName, String password, String keySpace, SSLOptions sslOptions) {
return getCluster(contactPoints, userName, password, sslOptions).connect(keySpace);
}

private Session getSession(final Properties properties) {
Expand Down

0 comments on commit 8e04770

Please sign in to comment.