Skip to content

Commit

Permalink
Perform cluster bookeeping tasks _before_ determining retry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KJ Tsanaktsidis committed Dec 12, 2023
1 parent 658103d commit 21f643e
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions lib/redis_client/cluster/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,60 +83,57 @@ def try_send(node, method, command, args, retry_count: 3, &block) # rubocop:disa
rescue ::RedisClient::CircuitBreaker::OpenCircuitError
raise
rescue ::RedisClient::CommandError => e
raise if retry_count <= 0

if e.message.start_with?('MOVED')
node = assign_redirection_node(e.message)
retry_count -= 1
retry
retry if retry_count >= 0
elsif e.message.start_with?('ASK')
node = assign_asking_node(e.message)
node.call('ASKING')
retry_count -= 1
retry
retry if retry_count >= 0
elsif e.message.start_with?('CLUSTERDOWN Hash slot not served')
update_cluster_info!
retry_count -= 1
retry
else
raise
retry if retry_count >= 0
end
raise
rescue ::RedisClient::ConnectionError => e
raise if METHODS_FOR_BLOCKING_CMD.include?(method) && e.is_a?(RedisClient::ReadTimeoutError)
raise if retry_count <= 0

update_cluster_info!

raise if retry_count <= 0

retry_count -= 1
retry
end

def try_delegate(node, method, *args, retry_count: 3, **kwargs, &block) # rubocop:disable Metrics/AbcSize
def try_delegate(node, method, *args, retry_count: 3, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
node.public_send(method, *args, **kwargs, &block)
rescue ::RedisClient::CircuitBreaker::OpenCircuitError
raise
rescue ::RedisClient::CommandError => e
raise if retry_count <= 0

if e.message.start_with?('MOVED')
node = assign_redirection_node(e.message)
retry_count -= 1
retry
retry if retry_count >= 0
elsif e.message.start_with?('ASK')
node = assign_asking_node(e.message)
node.call('ASKING')
retry_count -= 1
retry
retry if retry_count >= 0
elsif e.message.start_with?('CLUSTERDOWN Hash slot not served')
update_cluster_info!
retry_count -= 1
retry
else
raise
retry if retry_count >= 0
end
raise
rescue ::RedisClient::ConnectionError
update_cluster_info!

raise if retry_count <= 0

update_cluster_info!
retry_count -= 1
retry
end
Expand Down

0 comments on commit 21f643e

Please sign in to comment.