@@ -589,6 +589,14 @@ def _execute_command(self, *args, **kwargs):
589
589
ttl = int (self .RedisClusterRequestTTL )
590
590
connection_error_retry_counter = 0
591
591
592
+ def log_exception (message , exception ):
593
+ if ttl == 1 :
594
+ # This is the last attempt before we run out of TTL, so log the full exception.
595
+ log .exception (message )
596
+ else :
597
+ # We are going to retry, and therefore may yet succeed, so just log a warning.
598
+ log .warning (message + str (exception ))
599
+
592
600
while ttl > 0 :
593
601
ttl -= 1
594
602
connection = None
@@ -630,7 +638,7 @@ def _execute_command(self, *args, **kwargs):
630
638
connection .send_command (* args )
631
639
return self .parse_response (connection , command , ** kwargs )
632
640
except SlotNotCoveredError as e :
633
- log . exception ("SlotNotCoveredError" )
641
+ log_exception ("SlotNotCoveredError" , e )
634
642
635
643
# In some cases during failover to a replica is happening
636
644
# a slot sometimes is not covered by the cluster layout and
@@ -644,8 +652,8 @@ def _execute_command(self, *args, **kwargs):
644
652
except (RedisClusterException , BusyLoadingError ):
645
653
log .exception ("RedisClusterException || BusyLoadingError" )
646
654
raise
647
- except ConnectionError :
648
- log . exception ("ConnectionError" )
655
+ except ConnectionError as e :
656
+ log_exception ("ConnectionError" , e )
649
657
650
658
# ConnectionError can also be raised if we couldn't get a connection
651
659
# from the pool before timing out, so check that this is an actual
@@ -670,8 +678,8 @@ def _execute_command(self, *args, **kwargs):
670
678
self .connection_pool .nodes .increment_reinitialize_counter (
671
679
count = self .connection_pool .nodes .reinitialize_steps ,
672
680
)
673
- except TimeoutError :
674
- log . exception ("TimeoutError" )
681
+ except TimeoutError as e :
682
+ log_exception ("TimeoutError" , e )
675
683
connection .disconnect ()
676
684
677
685
if ttl < self .RedisClusterRequestTTL / 2 :
@@ -683,7 +691,7 @@ def _execute_command(self, *args, **kwargs):
683
691
if command in READ_COMMANDS :
684
692
try_random_node = True
685
693
except ClusterDownError as e :
686
- log .exception ("ClusterDownError" )
694
+ log .exception ("ClusterDownError" , e )
687
695
688
696
self .connection_pool .disconnect ()
689
697
self .connection_pool .reset ()
@@ -696,20 +704,20 @@ def _execute_command(self, *args, **kwargs):
696
704
# This counter will increase faster when the same client object
697
705
# is shared between multiple threads. To reduce the frequency you
698
706
# can set the variable 'reinitialize_steps' in the constructor.
699
- log . exception ("MovedError" )
707
+ log_exception ("MovedError" , e )
700
708
701
709
self .refresh_table_asap = True
702
710
self .connection_pool .nodes .increment_reinitialize_counter ()
703
711
704
712
node = self .connection_pool .nodes .set_node (e .host , e .port , server_type = 'master' )
705
713
self .connection_pool .nodes .slots [e .slot_id ][0 ] = node
706
- except TryAgainError :
707
- log . exception ("TryAgainError" )
714
+ except TryAgainError as e :
715
+ log_exception ("TryAgainError" , e )
708
716
709
717
if ttl < self .RedisClusterRequestTTL / 2 :
710
718
time .sleep (0.05 )
711
719
except AskError as e :
712
- log . exception ("AskError" )
720
+ log_exception ("AskError" , e )
713
721
714
722
redirect_addr , asking = "{0}:{1}" .format (e .host , e .port ), True
715
723
except BaseException as e :
0 commit comments