Skip to content

Commit 35fc56e

Browse files
committed
default LBP: warn on preferred DC misconfiguration
DefaultPolicy now issues respective warnings: 1. if the preferred datacenter is not present in the cluster; 2. if all nodes in the preferred datacenter are disabled by the HostFilter. This helps avoid confusion when the user expects requests to be sent to a specific datacenter, but it is not available. As warnings are going to be emitted on every request (because the configuration is most likely session-wide), the messages will quickly flood the logs and the user should notice. Alternatively, we could implement some frequency limiting of those warnings, but we rather prefer to: - keep it simple for now, - let the user notice the misconfiguration as quickly as possible.
1 parent 837e274 commit 35fc56e

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

scylla/src/policies/load_balancing/default.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,9 @@ impl DefaultPolicy {
589589
}
590590

591591
/// Checks for misconfiguration and warns if any is discovered.
592-
fn pick_sanity_checks(&self, routing_info: &ProcessedRoutingInfo, _cluster: &ClusterState) {
593-
if let Some(_preferred_dc) = self.preferences.datacenter() {
592+
fn pick_sanity_checks(&self, routing_info: &ProcessedRoutingInfo, cluster: &ClusterState) {
593+
if let Some(preferred_dc) = self.preferences.datacenter() {
594+
// Preferred DC + no datacenter failover + SimpleStrategy is an anti-pattern.
594595
if let Some(ref token_with_strategy) = routing_info.token_with_strategy {
595596
if !self.permit_dc_failover
596597
&& matches!(
@@ -606,6 +607,55 @@ or refrain from preferring datacenters (which may ban all other datacenters, if
606607
);
607608
}
608609
}
610+
611+
// Verify that the preferred datacenter is actually present in the cluster.
612+
// If not, shout a warning.
613+
if !cluster.all_nodes.iter().any(|node| {
614+
node.datacenter
615+
.as_deref()
616+
.is_some_and(|dc| dc == preferred_dc)
617+
}) {
618+
if self.permit_dc_failover {
619+
warn!(
620+
"\
621+
The preferred datacenter (\"{preferred_dc}\") is not present in the cluster! \
622+
Datacenter failover is enabled, so the request will be always sent to remote DCs. \
623+
This is most likely not what you want!"
624+
);
625+
} else {
626+
warn!(
627+
"\
628+
The preferred datacenter (\"{preferred_dc}\") is not present in the cluster! \
629+
Datacenter failover is disabled, so the query plans will be empty! \
630+
You won't be able to execute any requests!"
631+
);
632+
}
633+
}
634+
// Verify that there exist any enabled nodes in the preferred datacenter.
635+
// If not, shout a warning.
636+
else if !cluster.all_nodes.iter().any(|node| {
637+
node.is_enabled()
638+
&& node
639+
.datacenter
640+
.as_deref()
641+
.is_some_and(|dc| dc == preferred_dc)
642+
}) {
643+
if self.permit_dc_failover {
644+
warn!(
645+
"\
646+
All nodes in the preferred datacenter (\"{preferred_dc}\") are disabled by the HostFilter! \
647+
Datacenter failover is enabled, so the request will be always sent to remote DCs. \
648+
This is most likely a misconfiguration!"
649+
);
650+
} else {
651+
warn!(
652+
"\
653+
All nodes in the preferred datacenter (\"{preferred_dc}\") are disabled by the HostFilter! \
654+
Datacenter failover is disabled, so the query plans will be empty! \
655+
You won't be able to execute any requests! This is most likely a misconfiguration!"
656+
);
657+
}
658+
}
609659
}
610660
}
611661

0 commit comments

Comments
 (0)