Skip to content

Commit 882237e

Browse files
committed
Add a wrapper call.any() for vshard's replicaset:call()
Add a new wrapper for replicaset:call() that will be used in _fetch_on_router(). Part of #166 Reviewed-by: Alexander Turenko <[email protected]>
1 parent 95725b1 commit 882237e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

crud/common/call.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,31 @@ function call.single(bucket_id, func_name, func_args, opts)
145145
return res
146146
end
147147

148+
function call.any(func_name, func_args, opts)
149+
dev_checks('string', '?table', {
150+
timeout = '?number',
151+
})
152+
153+
local timeout = opts.timeout or call.DEFAULT_VSHARD_CALL_TIMEOUT
154+
155+
local replicasets, err = vshard.router.routeall()
156+
if replicasets == nil then
157+
return nil, CallError:new("Failed to get all replicasets: %s", err.err)
158+
end
159+
local replicaset = select(2, next(replicasets))
160+
161+
local res, err = replicaset:call(func_name, func_args, {
162+
timeout = timeout,
163+
})
164+
if err ~= nil then
165+
return nil, wrap_vshard_err(err, func_name, replicaset.uuid)
166+
end
167+
168+
if res == box.NULL then
169+
return nil
170+
end
171+
172+
return res
173+
end
174+
148175
return call

test/unit/call_test.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,32 @@ g.test_map_vshard_calls = function()
225225
mode = 'read', prefer_replica = true, balance = true,
226226
})
227227
end
228+
229+
g.test_any_vshard_call = function()
230+
g.clear_vshard_calls()
231+
local results, err = g.cluster.main_server.net_box:eval([[
232+
local call = require('crud.common.call')
233+
return call.any('say_hi_politely', {'dude'}, {})
234+
]])
235+
236+
t.assert_equals(results, 'HI, dude! I am s2-master')
237+
t.assert_equals(err, nil)
238+
end
239+
240+
g.test_any_vshard_call_timeout = function()
241+
local timeout = 0.2
242+
243+
local results, err = g.cluster.main_server.net_box:eval([[
244+
local call = require('crud.common.call')
245+
246+
local say_hi_timeout, call_timeout = ...
247+
248+
return call.any('say_hi_sleepily', {say_hi_timeout}, {
249+
timeout = call_timeout,
250+
})
251+
]], {timeout + 0.1, timeout})
252+
253+
t.assert_equals(results, nil)
254+
t.assert_str_contains(err.err, "Failed for %w+%-0000%-0000%-0000%-000000000000", true)
255+
t.assert_str_contains(err.err, "Timeout exceeded")
256+
end

0 commit comments

Comments
 (0)