Skip to content

Commit c455753

Browse files
petyaslavovaManelCoutinhoSensei
authored andcommitted
When SlotNotCoveredError is raised, the cluster topology should be reinitialized as part of error handling and retrying of the commands. (redis#3621)
1 parent 1a88165 commit c455753

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

redis/asyncio/cluster.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,16 @@ async def _execute_command(
810810
# and try again with the new setup
811811
await self.aclose()
812812
raise
813-
except ClusterDownError:
813+
except (ClusterDownError, SlotNotCoveredError):
814814
# ClusterDownError can occur during a failover and to get
815815
# self-healed, we will try to reinitialize the cluster layout
816816
# and retry executing the command
817+
818+
# SlotNotCoveredError can occur when the cluster is not fully
819+
# initialized or can be temporary issue.
820+
# We will try to reinitialize the cluster topology
821+
# and retry executing the command
822+
817823
await self.aclose()
818824
await asyncio.sleep(0.25)
819825
raise

redis/cluster.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,12 @@ class AbstractRedisCluster:
410410
list_keys_to_dict(["SCRIPT FLUSH"], lambda command, res: all(res.values())),
411411
)
412412

413-
ERRORS_ALLOW_RETRY = (ConnectionError, TimeoutError, ClusterDownError)
413+
ERRORS_ALLOW_RETRY = (
414+
ConnectionError,
415+
TimeoutError,
416+
ClusterDownError,
417+
SlotNotCoveredError,
418+
)
414419

415420
def replace_default_node(self, target_node: "ClusterNode" = None) -> None:
416421
"""Replace the default cluster node.
@@ -1239,13 +1244,19 @@ def _execute_command(self, target_node, *args, **kwargs):
12391244
except AskError as e:
12401245
redirect_addr = get_node_name(host=e.host, port=e.port)
12411246
asking = True
1242-
except ClusterDownError as e:
1247+
except (ClusterDownError, SlotNotCoveredError):
12431248
# ClusterDownError can occur during a failover and to get
12441249
# self-healed, we will try to reinitialize the cluster layout
12451250
# and retry executing the command
1251+
1252+
# SlotNotCoveredError can occur when the cluster is not fully
1253+
# initialized or can be temporary issue.
1254+
# We will try to reinitialize the cluster topology
1255+
# and retry executing the command
1256+
12461257
time.sleep(0.25)
12471258
self.nodes_manager.initialize()
1248-
raise e
1259+
raise
12491260
except ResponseError:
12501261
raise
12511262
except Exception as e:

0 commit comments

Comments
 (0)