1
1
import copy
2
- import logging
3
2
import random
4
3
import socket
5
4
import sys
15
14
from redis .exceptions import (
16
15
AskError ,
17
16
AuthenticationError ,
18
- BusyLoadingError ,
19
17
ClusterCrossSlotError ,
20
18
ClusterDownError ,
21
19
ClusterError ,
39
37
str_if_bytes ,
40
38
)
41
39
42
- log = logging .getLogger (__name__ )
43
-
44
40
45
41
def get_node_name (host : str , port : int ) -> str :
46
42
return f"{ host } :{ port } "
@@ -535,7 +531,6 @@ def __init__(
535
531
" RedisCluster(startup_nodes=[ClusterNode('localhost', 6379),"
536
532
" ClusterNode('localhost', 6378)])"
537
533
)
538
- log .debug (f"startup_nodes : { startup_nodes } " )
539
534
# Update the connection arguments
540
535
# Whenever a new connection is established, RedisCluster's on_connect
541
536
# method should be run
@@ -666,13 +661,8 @@ def set_default_node(self, node):
666
661
:return True if the default node was set, else False
667
662
"""
668
663
if node is None or self .get_node (node_name = node .name ) is None :
669
- log .info (
670
- "The requested node does not exist in the cluster, so "
671
- "the default node was not changed."
672
- )
673
664
return False
674
665
self .nodes_manager .default_node = node
675
- log .info (f"Changed the default cluster node to { node } " )
676
666
return True
677
667
678
668
def monitor (self , target_node = None ):
@@ -816,8 +806,6 @@ def _determine_nodes(self, *args, **kwargs):
816
806
else :
817
807
# get the nodes group for this command if it was predefined
818
808
command_flag = self .command_flags .get (command )
819
- if command_flag :
820
- log .debug (f"Target node/s for { command } : { command_flag } " )
821
809
if command_flag == self .__class__ .RANDOM :
822
810
# return a random node
823
811
return [self .get_random_node ()]
@@ -841,7 +829,6 @@ def _determine_nodes(self, *args, **kwargs):
841
829
node = self .nodes_manager .get_node_from_slot (
842
830
slot , self .read_from_replicas and command in READ_COMMANDS
843
831
)
844
- log .debug (f"Target for { args } : slot { slot } " )
845
832
return [node ]
846
833
847
834
def _should_reinitialized (self ):
@@ -1019,7 +1006,7 @@ def execute_command(self, *args, **kwargs):
1019
1006
res [node .name ] = self ._execute_command (node , * args , ** kwargs )
1020
1007
# Return the processed result
1021
1008
return self ._process_result (args [0 ], res , ** kwargs )
1022
- except BaseException as e :
1009
+ except Exception as e :
1023
1010
if type (e ) in self .__class__ .ERRORS_ALLOW_RETRY :
1024
1011
# The nodes and slots cache were reinitialized.
1025
1012
# Try again with the new cluster setup.
@@ -1059,10 +1046,6 @@ def _execute_command(self, target_node, *args, **kwargs):
1059
1046
)
1060
1047
moved = False
1061
1048
1062
- log .debug (
1063
- f"Executing command { command } on target node: "
1064
- f"{ target_node .server_type } { target_node .name } "
1065
- )
1066
1049
redis_node = self .get_redis_connection (target_node )
1067
1050
connection = get_connection (redis_node , * args , ** kwargs )
1068
1051
if asking :
@@ -1077,12 +1060,9 @@ def _execute_command(self, target_node, *args, **kwargs):
1077
1060
response , ** kwargs
1078
1061
)
1079
1062
return response
1080
-
1081
- except (RedisClusterException , BusyLoadingError , AuthenticationError ) as e :
1082
- log .exception (type (e ))
1063
+ except AuthenticationError :
1083
1064
raise
1084
1065
except (ConnectionError , TimeoutError ) as e :
1085
- log .exception (type (e ))
1086
1066
# ConnectionError can also be raised if we couldn't get a
1087
1067
# connection from the pool before timing out, so check that
1088
1068
# this is an actual connection before attempting to disconnect.
@@ -1101,7 +1081,7 @@ def _execute_command(self, target_node, *args, **kwargs):
1101
1081
# and try again with the new setup
1102
1082
target_node .redis_connection = None
1103
1083
self .nodes_manager .initialize ()
1104
- raise
1084
+ raise e
1105
1085
except MovedError as e :
1106
1086
# First, we will try to patch the slots/nodes cache with the
1107
1087
# redirected node output and try again. If MovedError exceeds
@@ -1111,7 +1091,6 @@ def _execute_command(self, target_node, *args, **kwargs):
1111
1091
# the same client object is shared between multiple threads. To
1112
1092
# reduce the frequency you can set this variable in the
1113
1093
# RedisCluster constructor.
1114
- log .exception ("MovedError" )
1115
1094
self .reinitialize_counter += 1
1116
1095
if self ._should_reinitialized ():
1117
1096
self .nodes_manager .initialize ()
@@ -1121,29 +1100,21 @@ def _execute_command(self, target_node, *args, **kwargs):
1121
1100
self .nodes_manager .update_moved_exception (e )
1122
1101
moved = True
1123
1102
except TryAgainError :
1124
- log .exception ("TryAgainError" )
1125
-
1126
1103
if ttl < self .RedisClusterRequestTTL / 2 :
1127
1104
time .sleep (0.05 )
1128
1105
except AskError as e :
1129
- log .exception ("AskError" )
1130
-
1131
1106
redirect_addr = get_node_name (host = e .host , port = e .port )
1132
1107
asking = True
1133
1108
except ClusterDownError as e :
1134
- log .exception ("ClusterDownError" )
1135
1109
# ClusterDownError can occur during a failover and to get
1136
1110
# self-healed, we will try to reinitialize the cluster layout
1137
1111
# and retry executing the command
1138
1112
time .sleep (0.25 )
1139
1113
self .nodes_manager .initialize ()
1140
1114
raise e
1141
- except ResponseError as e :
1142
- message = e .__str__ ()
1143
- log .exception (f"ResponseError: { message } " )
1144
- raise e
1145
- except BaseException as e :
1146
- log .exception ("BaseException" )
1115
+ except ResponseError :
1116
+ raise
1117
+ except Exception as e :
1147
1118
if connection :
1148
1119
connection .disconnect ()
1149
1120
raise e
@@ -1280,11 +1251,6 @@ def get_node(self, host=None, port=None, node_name=None):
1280
1251
elif node_name :
1281
1252
return self .nodes_cache .get (node_name )
1282
1253
else :
1283
- log .error (
1284
- "get_node requires one of the following: "
1285
- "1. node name "
1286
- "2. host and port"
1287
- )
1288
1254
return None
1289
1255
1290
1256
def update_moved_exception (self , exception ):
@@ -1432,7 +1398,6 @@ def initialize(self):
1432
1398
:startup_nodes:
1433
1399
Responsible for discovering other nodes in the cluster
1434
1400
"""
1435
- log .debug ("Initializing the nodes' topology of the cluster" )
1436
1401
self .reset ()
1437
1402
tmp_nodes_cache = {}
1438
1403
tmp_slots = {}
@@ -1460,17 +1425,9 @@ def initialize(self):
1460
1425
)
1461
1426
cluster_slots = str_if_bytes (r .execute_command ("CLUSTER SLOTS" ))
1462
1427
startup_nodes_reachable = True
1463
- except (ConnectionError , TimeoutError ) as e :
1464
- msg = e .__str__
1465
- log .exception (
1466
- "An exception occurred while trying to"
1467
- " initialize the cluster using the seed node"
1468
- f" { startup_node .name } :\n { msg } "
1469
- )
1428
+ except (ConnectionError , TimeoutError ):
1470
1429
continue
1471
1430
except ResponseError as e :
1472
- log .exception ('ReseponseError sending "cluster slots" to redis server' )
1473
-
1474
1431
# Isn't a cluster connection, so it won't parse these
1475
1432
# exceptions automatically
1476
1433
message = e .__str__ ()
@@ -2042,12 +1999,6 @@ def _send_cluster_commands(
2042
1999
# If a lot of commands have failed, we'll be setting the
2043
2000
# flag to rebuild the slots table from scratch.
2044
2001
# So MOVED errors should correct themselves fairly quickly.
2045
- log .exception (
2046
- f"An exception occurred during pipeline execution. "
2047
- f"args: { attempt [- 1 ].args } , "
2048
- f"error: { type (attempt [- 1 ].result ).__name__ } "
2049
- f"{ str (attempt [- 1 ].result )} "
2050
- )
2051
2002
self .reinitialize_counter += 1
2052
2003
if self ._should_reinitialized ():
2053
2004
self .nodes_manager .initialize ()
0 commit comments