@@ -12,7 +12,7 @@ class Pipeline
12
12
class Extended < ::RedisClient ::Pipeline
13
13
attr_reader :outer_indices
14
14
15
- def initialize ( command_builder )
15
+ def initialize ( ... )
16
16
super
17
17
@outer_indices = nil
18
18
end
@@ -50,14 +50,14 @@ def get_block(inner_index)
50
50
end
51
51
52
52
::RedisClient ::ConnectionMixin . module_eval do
53
- def call_pipelined_aware_of_redirection ( commands , timeouts ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
53
+ def call_pipelined_aware_of_redirection ( commands , timeouts , exception : ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
54
54
size = commands . size
55
55
results = Array . new ( commands . size )
56
56
@pending_reads += size
57
57
write_multi ( commands )
58
58
59
59
redirection_indices = nil
60
- exception = nil
60
+ first_exception = nil
61
61
size . times do |index |
62
62
timeout = timeouts && timeouts [ index ]
63
63
result = read ( timeout )
@@ -67,14 +67,14 @@ def call_pipelined_aware_of_redirection(commands, timeouts) # rubocop:disable Me
67
67
if result . is_a? ( ::RedisClient ::CommandError ) && result . message . start_with? ( 'MOVED' , 'ASK' )
68
68
redirection_indices ||= [ ]
69
69
redirection_indices << index
70
- else
71
- exception ||= result
70
+ elsif exception
71
+ first_exception ||= result
72
72
end
73
73
end
74
74
results [ index ] = result
75
75
end
76
76
77
- raise exception if exception
77
+ raise first_exception if exception && first_exception
78
78
return results if redirection_indices . nil?
79
79
80
80
err = ::RedisClient ::Cluster ::Pipeline ::RedirectionNeeded . new
@@ -98,10 +98,11 @@ class RedirectionNeeded < ::RedisClient::Error
98
98
attr_accessor :replies , :indices
99
99
end
100
100
101
- def initialize ( router , command_builder , concurrent_worker , seed : Random . new_seed )
101
+ def initialize ( router , command_builder , concurrent_worker , exception : , seed : Random . new_seed )
102
102
@router = router
103
103
@command_builder = command_builder
104
104
@concurrent_worker = concurrent_worker
105
+ @exception = exception
105
106
@seed = seed
106
107
@pipelines = nil
107
108
@size = 0
@@ -212,7 +213,7 @@ def send_pipeline(client, pipeline)
212
213
results = client . ensure_connected_cluster_scoped ( retryable : pipeline . _retryable? ) do |connection |
213
214
commands = pipeline . _commands
214
215
client . middlewares . call_pipelined ( commands , client . config ) do
215
- connection . call_pipelined_aware_of_redirection ( commands , pipeline . _timeouts )
216
+ connection . call_pipelined_aware_of_redirection ( commands , pipeline . _timeouts , exception : @exception )
216
217
end
217
218
end
218
219
@@ -224,15 +225,21 @@ def handle_redirection(err, pipeline, inner_index)
224
225
225
226
if err . message . start_with? ( 'MOVED' )
226
227
node = @router . assign_redirection_node ( err . message )
227
- redirect_command ( node , pipeline , inner_index )
228
+ try_redirection ( node , pipeline , inner_index )
228
229
elsif err . message . start_with? ( 'ASK' )
229
230
node = @router . assign_asking_node ( err . message )
230
- try_asking ( node ) ? redirect_command ( node , pipeline , inner_index ) : err
231
+ try_asking ( node ) ? try_redirection ( node , pipeline , inner_index ) : err
231
232
else
232
233
err
233
234
end
234
235
end
235
236
237
+ def try_redirection ( node , pipeline , inner_index )
238
+ redirect_command ( node , pipeline , inner_index )
239
+ rescue StandardError => e
240
+ @exception ? raise : e
241
+ end
242
+
236
243
def redirect_command ( node , pipeline , inner_index )
237
244
method = pipeline . get_callee_method ( inner_index )
238
245
command = pipeline . get_command ( inner_index )
0 commit comments