Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

Micro-service with Spring Cassandra doesn't failover to remote cluster

I setup two data centers (DC1, DC2) with 3 nodes each. consistency-level is local_quorum and serial-consistency-level is LOCAL_SERIAL. The local-datacenter is DC1. The micro-service doesn't failover to DC2 automatically when there is only one node alive in the local data center, instead it keeps complaining "Not enough replicas available for query at consistency LOCAL_QUORUM (2 required but only 1 alive". Any advice will be appreciated.

Maven dependencies:

org.springframework.boot:spring-boot:jar:2.3.7.RELEASE
org.springframework.boot:spring-boot-starter-data-cassandra:jar:2.3.7.RELEASE
org.springframework.data:spring-data-cassandra:jar:3.0.6.RELEASE

YAML:


spring:
  data:
    cassandra:
      consistency-level: local_quorum
      serial-consistency-level: LOCAL_SERIAL
      local-datacenter: DC1
      other configs: ...

Code:

public class CassandraConfig {

    @Bean
    public CqlSessionBuilderCustomizer sessionBuilderConfigurer() {
        return cqlSessionBuilder ->
                cqlSessionBuilder
                        .withAuthCredentials("username", "pwd");
    }

    @Bean
    public DriverConfigLoaderBuilderCustomizer driverConfigLoaderBuilderCustomizer() {
        return loaderBuilder -> loaderBuilder
                .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(10000))
                .withBoolean(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_ALLOW_FOR_LOCAL_CONSISTENCY_LEVELS, true)
                .withInt(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_MAX_NODES_PER_REMOTE_DC, 3);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...