Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform cluster bookeeping tasks _before_ determining retry #300

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions lib/redis_client/cluster/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,60 +83,62 @@ 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
if retry_count >= 0
# Don't actually prepend our next command with ASKING unless we're going to retry.
node.call('ASKING')
retry
end
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
if retry_count >= 0
node.call('ASKING')
retry
end
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
Loading