Illustration Image

Spring Data CassandraDriverTimeoutException

I'm getting sporadic timeout exceptions from the Cassandra driver in a Spring Boot project, in spite of having what I think are the appropriate yml configuration properties.

spring:
  cassandra:
    contact-points: localhost
    local-datacenter: datacenter1
    keyspace-name: my_keyspace
    request:
      consistency: quorum
      serial-consistency: quorum
      page-size: 2500
      timeout: 20s
    connection:
      init-query-timeout: 20s
      connect-timeout: 20s
    controlconnection:
      timeout: 20s

As a workaround, I am able to prevent timeouts by configuring properties in Java code.

public class CassandraConfig extends AbstractCassandraConfiguration {
    @Bean
    public CqlSessionFactoryBean cassandraSession() {
        CqlSessionFactoryBean sessionFactoryBean = super.cassandraSession();
        setProperties(sessionFactoryBean);
        return sessionFactoryBean;
    }
    private void setProperties(CqlSessionFactoryBean sessionFactoryBean) {
        sessionFactoryBean.setUsername(...);
        sessionFactoryBean.setPassword(...);
        sessionFactoryBean.setPort(...);
        sessionFactoryBean.setLocalDatacenter(...);
 
//      These timeouts should already be configured in application.yml but seem to be ignored?
//
        sessionFactoryBean.setSessionBuilderConfigurer(config -> config.withConfigLoader(
                DriverConfigLoader.programmaticBuilder()
                        .withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(20))
                        .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(20))
                        .build()
        ));
    }
}

I've found a tantalizing hint of what might be happening, in a comment.

It may be a side-effect of you trying to solve your problem, but in its current form your project is mostly configuring Cassandra itself. This means that Spring Boot's auto-configuration has largely backed off. As a result any spring.data.cassandra.* properties that you have set won't have any effect unless you're using them in your own code.

So my question is, what exactly are the Cassandra configurations that can cause Spring Boot's configurations to "back off"? For example, does any occurrence of a CqlSessionFactoryBean have this effect, regardless of its properties?

Dependencies:

  • org.springframework.data:spring-data-cassandra:4.3.0
  • com.datastax.cassandra:cassandra-driver-core:3.10.0
Become part of our
growing community!
Welcome to Planet Cassandra, a community for Apache Cassandra®! We're a passionate and dedicated group of users, developers, and enthusiasts who are working together to make Cassandra the best it can be. Whether you're just getting started with Cassandra or you're an experienced user, there's a place for you in our community.
A dinosaur
Planet Cassandra is a service for the Apache Cassandra® user community to share with each other. From tutorials and guides, to discussions and updates, we're here to help you get the most out of Cassandra. Connect with us and become part of our growing community today.
© 2009-2023 The Apache Software Foundation under the terms of the Apache License 2.0. Apache, the Apache feather logo, Apache Cassandra, Cassandra, and the Cassandra logo, are either registered trademarks or trademarks of The Apache Software Foundation. Sponsored by Anant Corporation and Datastax, and Developed by Anant Corporation.

Get Involved with Planet Cassandra!

We believe that the power of the Planet Cassandra community lies in the contributions of its members. Do you have content, articles, videos, or use cases you want to share with the world?