Skip to content

Commit 084f127

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 084f127

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

scylla/src/policies/load_balancing/default.rs

Lines changed: 53 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,56 @@ 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
614+
.replica_locator()
615+
.unique_nodes_in_datacenter_ring(preferred_dc)
616+
.unwrap_or(&[])
617+
.is_empty()
618+
{
619+
if self.permit_dc_failover {
620+
warn!(
621+
"\
622+
The preferred datacenter (\"{preferred_dc}\") is not present in the cluster! \
623+
Datacenter failover is enabled, so the request will be always sent to remote DCs. \
624+
This is most likely not what you want!"
625+
);
626+
} else {
627+
warn!(
628+
"\
629+
The preferred datacenter (\"{preferred_dc}\") is not present in the cluster! \
630+
Datacenter failover is disabled, so the query plans will be empty! \
631+
You won't be able to execute any requests!"
632+
);
633+
}
634+
}
635+
// Verify that there exist any enabled nodes in the preferred datacenter.
636+
// If not, shout a warning.
637+
else if !cluster
638+
.replica_locator()
639+
.unique_nodes_in_datacenter_ring(preferred_dc)
640+
.unwrap_or(&[])
641+
.iter()
642+
.any(|node| node.is_enabled())
643+
{
644+
if self.permit_dc_failover {
645+
warn!(
646+
"\
647+
All nodes in the preferred datacenter (\"{preferred_dc}\") are disabled by the HostFilter! \
648+
Datacenter failover is enabled, so the request will be always sent to remote DCs. \
649+
This is most likely a misconfiguration!"
650+
);
651+
} else {
652+
warn!(
653+
"\
654+
All nodes in the preferred datacenter (\"{preferred_dc}\") are disabled by the HostFilter! \
655+
Datacenter failover is disabled, so the query plans will be empty! \
656+
You won't be able to execute any requests! This is most likely a misconfiguration!"
657+
);
658+
}
659+
}
609660
}
610661
}
611662

0 commit comments

Comments
 (0)