Skip to content

Commit f92d39d

Browse files
author
KJ Tsanaktsidis
committed
Perform cluster bookeeping tasks _before_ determining retry
Just because a block is not going to be retried, does not mean we should not process topology updates & redirections in response to errors, I think.
1 parent 658103d commit f92d39d

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lib/redis_client/cluster/router.rb

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,60 +83,62 @@ def try_send(node, method, command, args, retry_count: 3, &block) # rubocop:disa
8383
rescue ::RedisClient::CircuitBreaker::OpenCircuitError
8484
raise
8585
rescue ::RedisClient::CommandError => e
86-
raise if retry_count <= 0
87-
8886
if e.message.start_with?('MOVED')
8987
node = assign_redirection_node(e.message)
9088
retry_count -= 1
91-
retry
89+
retry if retry_count >= 0
9290
elsif e.message.start_with?('ASK')
9391
node = assign_asking_node(e.message)
94-
node.call('ASKING')
9592
retry_count -= 1
96-
retry
93+
if retry_count >= 0
94+
# Don't actually prepend our next command with ASKING unless we're going to retry.
95+
node.call('ASKING')
96+
retry
97+
end
9798
elsif e.message.start_with?('CLUSTERDOWN Hash slot not served')
9899
update_cluster_info!
99100
retry_count -= 1
100-
retry
101-
else
102-
raise
101+
retry if retry_count >= 0
103102
end
103+
raise
104104
rescue ::RedisClient::ConnectionError => e
105105
raise if METHODS_FOR_BLOCKING_CMD.include?(method) && e.is_a?(RedisClient::ReadTimeoutError)
106-
raise if retry_count <= 0
107106

108107
update_cluster_info!
108+
109+
raise if retry_count <= 0
110+
109111
retry_count -= 1
110112
retry
111113
end
112114

113-
def try_delegate(node, method, *args, retry_count: 3, **kwargs, &block) # rubocop:disable Metrics/AbcSize
115+
def try_delegate(node, method, *args, retry_count: 3, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
114116
node.public_send(method, *args, **kwargs, &block)
115117
rescue ::RedisClient::CircuitBreaker::OpenCircuitError
116118
raise
117119
rescue ::RedisClient::CommandError => e
118-
raise if retry_count <= 0
119-
120120
if e.message.start_with?('MOVED')
121121
node = assign_redirection_node(e.message)
122122
retry_count -= 1
123-
retry
123+
retry if retry_count >= 0
124124
elsif e.message.start_with?('ASK')
125125
node = assign_asking_node(e.message)
126-
node.call('ASKING')
127126
retry_count -= 1
128-
retry
127+
if retry_count >= 0
128+
node.call('ASKING')
129+
retry
130+
end
129131
elsif e.message.start_with?('CLUSTERDOWN Hash slot not served')
130132
update_cluster_info!
131133
retry_count -= 1
132-
retry
133-
else
134-
raise
134+
retry if retry_count >= 0
135135
end
136+
raise
136137
rescue ::RedisClient::ConnectionError
138+
update_cluster_info!
139+
137140
raise if retry_count <= 0
138141

139-
update_cluster_info!
140142
retry_count -= 1
141143
retry
142144
end

0 commit comments

Comments
 (0)