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
com.datastax.oss:java-driver-core:4.10.0
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);
}
}
question from:
https://stackoverflow.com/questions/65854740/micro-service-with-spring-cassandra-doesnt-failover-to-remote-cluster 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…