javaspringcassandradatastax-java-driver

Cassandra datastax ipv6 connection


When I try to connect to the Cassandra instance on a machine with an ipv6 address, I get this error.

Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /2600:xxxx:2500:yyyy:zzzz:qwq:1143:6a0d:9042 (com.datastax.driver.core.exceptions.TransportException: [/2600:xxxx:2500:yyyy:zzzz:qwq:1143:6a0d:9042] Cannot connect))
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:233)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1483)
    at com.datastax.driver.core.Cluster.init(Cluster.java:159)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:280)
    at org.springframework.cassandra.config.CassandraCqlSessionFactoryBean.connect(CassandraCqlSessionFactoryBean.java:100)
    at org.springframework.cassandra.config.CassandraCqlSessionFactoryBean.afterPropertiesSet(CassandraCqlSessionFactoryBean.java:94)
    at org.springframework.data.cassandra.config.CassandraSessionFactoryBean.afterPropertiesSet(CassandraSessionFactoryBean.java:103)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1677)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1615)
    ... 159 more

I give endpoints like that: cassandra_contactpoints: [2600:xxxx:2500:yyyy:zzzz:qwq:1143:6a0d]

@Bean
public Cluster cluster() {
    return Cluster.builder()
        .addContactPoints(getContactPoints())
        .withPort(getPort())
        .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
        .withQueryOptions(getQueryOptions())
        .withPoolingOptions(getPoolingOptions())
        .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
        .withCredentials(environment.getProperty("cassandra.username"), environment.getProperty("cassandra.password"))
        .build();
}

Does the datastax driver support ipv6? My driver version is com.datastax.cassandra:cassandra-driver-core:3.1.4

I changed IP address in the logs


Solution

  • You have not provided what version of Cassandra® you're using in your question so we will make some guesses here.

    Also, 3.1.4 version was first released back in Feb 14, 2017 which is already over 6.5+ years old and does not contain the support for IPv6 which was introduced in https://datastax-oss.atlassian.net/browse/JAVA-2226 beginning 4.0.1 version. 3.x version was on maintenance support only for many years.

    Refer to the upgrade guide to upgrade to the latest 4.x series.

    Also, note that DataStax has graciously donated the Cassandra Java Driver to the ASF C* community (via CEP-8 on Nov 7, 2023) and you could leverage the latest beginning the 4.18.0 here.

    Maven Coordinates are below with latest as of this writing as 4.18.0:

    <dependency>
      <groupId>org.apache.cassandra</groupId>
      <artifactId>java-driver-core</artifactId>
      <version>${driver.version}</version>
    </dependency>
    
    <dependency>
      <groupId>org.apache.cassandra</groupId>
      <artifactId>java-driver-query-builder</artifactId>
      <version>${driver.version}</version>
    </dependency>
    
    <dependency>
      <groupId>org.apache.cassandra</groupId>
      <artifactId>java-driver-mapper-runtime</artifactId>
      <version>${driver.version}</version>
    </dependency>