Skip to content

Commit

Permalink
Breaking changes: renamed ClusterConnectionNotFound to AllConnections…
Browse files Browse the repository at this point in the history
…Unavailable, added new error ConnectionNotFoundForRoute
  • Loading branch information
barshaul committed Aug 15, 2024
1 parent 2266116 commit 07ad7dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
16 changes: 8 additions & 8 deletions redis/src/cluster_async/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl<C> Future for Request<C> {
let request = this.request.as_mut().unwrap();
// TODO - would be nice if we didn't need to repeat this code twice, with & without retries.
if request.retry >= this.retry_params.number_of_retries {
let next = if err.kind() == ErrorKind::ClusterConnectionNotFound {
let next = if err.kind() == ErrorKind::AllConnectionsUnavailable {
Next::ReconnectToInitialNodes { request: None }.into()
} else if matches!(err.retry_method(), crate::types::RetryMethod::MovedRedirect)
|| matches!(target, OperationTarget::NotFound)
Expand Down Expand Up @@ -836,7 +836,7 @@ impl<C> Future for Request<C> {
}
request.retry = request.retry.saturating_add(1);

if err.kind() == ErrorKind::ClusterConnectionNotFound {
if err.kind() == ErrorKind::AllConnectionsUnavailable {
return Next::ReconnectToInitialNodes {
request: Some(this.request.take().unwrap()),
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ where
} else {
Err(last_err.unwrap_or_else(|| {
(
ErrorKind::ClusterConnectionNotFound,
ErrorKind::AllConnectionsUnavailable,
"Couldn't find any connection",
)
.into()
Expand Down Expand Up @@ -1651,7 +1651,7 @@ where
return OperationResult::Err((
OperationTarget::FanOut,
(
ErrorKind::ClusterConnectionNotFound,
ErrorKind::AllConnectionsUnavailable,
"No connections found for multi-node operation",
)
.into(),
Expand Down Expand Up @@ -1695,7 +1695,7 @@ where
)
} else {
let _ = sender.send(Err((
ErrorKind::ClusterConnectionNotFound,
ErrorKind::ConnectionNotFoundForRoute,
"Connection not found",
)
.into()));
Expand Down Expand Up @@ -1866,7 +1866,7 @@ where
&& !RoutingInfo::is_key_routing_command(&routable_cmd.unwrap())
{
return Err((
ErrorKind::ClusterConnectionNotFound,
ErrorKind::ConnectionNotFoundForRoute,
"Requested connection not found for route",
format!("{route:?}"),
)
Expand All @@ -1887,7 +1887,7 @@ where
return Ok((address, conn.await));
} else {
return Err((
ErrorKind::ClusterConnectionNotFound,
ErrorKind::ConnectionNotFoundForRoute,
"Requested connection not found",
address,
)
Expand Down Expand Up @@ -1933,7 +1933,7 @@ where
.random_connections(1, ConnectionType::User)
.next()
.ok_or(RedisError::from((
ErrorKind::ClusterConnectionNotFound,
ErrorKind::AllConnectionsUnavailable,
"No random connection found",
)))?;
return Ok((random_address, random_conn_future.await));
Expand Down
4 changes: 3 additions & 1 deletion redis/src/commands/cluster_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ where
// the connection to the address cant be reached from different reasons, we will check we want to check if
// the problem is problem that we can recover from like failover or scale down or some network issue
// that we can retry the scan command to an address that own the next slot we are at.
ErrorKind::IoError | ErrorKind::ClusterConnectionNotFound => {
ErrorKind::IoError
| ErrorKind::AllConnectionsUnavailable
| ErrorKind::ConnectionNotFoundForRoute => {
let retry =
retry_scan(&scan_state, &core, match_pattern, count, object_type).await?;
(from_redis_value(&retry.0?)?, retry.1)
Expand Down
12 changes: 8 additions & 4 deletions redis/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ pub enum ErrorKind {
EmptySentinelList,
/// Attempted to kill a script/function while they werent' executing
NotBusy,
/// Used when a cluster connection cannot find a connection to a valid node.
ClusterConnectionNotFound,
/// Used when no valid node connections remain in the cluster connection
AllConnectionsUnavailable,
/// Used when a connection is not found for the specified route.
ConnectionNotFoundForRoute,

#[cfg(feature = "json")]
/// Error Serializing a struct to JSON form
Expand Down Expand Up @@ -875,7 +877,8 @@ impl RedisError {
ErrorKind::NoValidReplicasFoundBySentinel => "no valid replicas found by sentinel",
ErrorKind::EmptySentinelList => "empty sentinel list",
ErrorKind::NotBusy => "not busy",
ErrorKind::ClusterConnectionNotFound => "connection to node in cluster not found",
ErrorKind::AllConnectionsUnavailable => "no valid connections remain in the cluster",
ErrorKind::ConnectionNotFoundForRoute => "No connection found for the requested route",
#[cfg(feature = "json")]
ErrorKind::Serialize => "serializing",
ErrorKind::RESP3NotSupported => "resp3 is not supported by server",
Expand Down Expand Up @@ -1046,7 +1049,8 @@ impl RedisError {

ErrorKind::ParseError => RetryMethod::Reconnect,
ErrorKind::AuthenticationFailed => RetryMethod::Reconnect,
ErrorKind::ClusterConnectionNotFound => RetryMethod::Reconnect,
ErrorKind::AllConnectionsUnavailable => RetryMethod::Reconnect,
ErrorKind::ConnectionNotFoundForRoute => RetryMethod::Reconnect,

ErrorKind::IoError => match &self.repr {
ErrorRepr::IoError(err) => match err.kind() {
Expand Down

0 comments on commit 07ad7dd

Please sign in to comment.