diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 8cac92d6e5..be0937528c 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -594,7 +594,7 @@ impl DefaultPolicy { vec.into_iter() } - fn is_alive(node: &NodeRef<'_>) -> bool { + pub(crate) fn is_alive(node: &NodeRef<'_>) -> bool { // For now, we leave this as stub, until we have time to improve node events. // node.is_enabled() && !node.is_down() node.is_enabled() diff --git a/scylla/src/transport/load_balancing/enforce_node.rs b/scylla/src/transport/load_balancing/enforce_node.rs index 12c17bbcbf..8a22534025 100644 --- a/scylla/src/transport/load_balancing/enforce_node.rs +++ b/scylla/src/transport/load_balancing/enforce_node.rs @@ -1,7 +1,9 @@ -use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; +use super::{DefaultPolicy, FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::transport::{cluster::ClusterData, Node}; use std::sync::Arc; +/// This policy will always return the same node, unless it is not available anymore, in which case it will +/// fallback to the provided policy. #[derive(Debug)] pub struct EnforceTargetNodePolicy { target_node: uuid::Uuid, @@ -21,6 +23,7 @@ impl LoadBalancingPolicy for EnforceTargetNodePolicy { cluster .known_peers .get(&self.target_node) + .filter(DefaultPolicy::is_alive) .or_else(|| self.fallback.pick(query, cluster)) }