我设置了两个数据中心(DC1、DC2),每个数据中心有 3 个节点。一致性级别是 local_quorum,串行一致性级别是 LOCAL_SERIAL。本地数据中心是 DC1。当本地数据中心只有一个节点活着时,微服务不会自动故障转移到 DC2,而是一直抱怨“没有足够的副本可用于一致性查询 LOCAL_QUORUM(需要 2 个但只有 1 个活着”。任何建议都会不胜感激。
Maven 依赖项:
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: ...
代码:
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);
}
}