Skip to content

Commit

Permalink
Add a wrapper call.any() for vshard's replicaset:call()
Browse files Browse the repository at this point in the history
Add a new wrapper for replicaset:call() that will be used in
_fetch_on_router().

Part of #166

Reviewed-by: Alexander Turenko <alexander.turenko@tarantool.org>
  • Loading branch information
ligurio committed Nov 27, 2021
1 parent 9fba7c3 commit fc7bc57
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crud/common/call.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,31 @@ function call.single(bucket_id, func_name, func_args, opts)
return res
end

function call.any(func_name, func_args, opts)
dev_checks('string', '?table', {
timeout = '?number',
})

local timeout = opts.timeout or call.DEFAULT_VSHARD_CALL_TIMEOUT

local replicasets, err = vshard.router.routeall()
if replicasets == nil then
return nil, CallError:new("Failed to get all replicasets: %s", err.err)
end
local replicaset = select(2, next(replicasets))

local res, err = replicaset:call(func_name, func_args, {
timeout = timeout,
})
if err ~= nil then
return nil, wrap_vshard_err(err, func_name, replicaset.uuid)
end

if res == box.NULL then
return nil
end

return res
end

return call
29 changes: 29 additions & 0 deletions test/unit/call_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,32 @@ g.test_map_vshard_calls = function()
mode = 'read', prefer_replica = true, balance = true,
})
end

g.test_any_vshard_call = function()
g.clear_vshard_calls()
local results, err = g.cluster.main_server.net_box:eval([[
local call = require('crud.common.call')
return call.any('say_hi_politely', {'dude'}, {})
]])

t.assert_equals(results, 'HI, dude! I am s2-master')
t.assert_equals(err, nil)
end

g.test_any_vshard_call_timeout = function()
local timeout = 0.2

local results, err = g.cluster.main_server.net_box:eval([[
local call = require('crud.common.call')
local say_hi_timeout, call_timeout = ...
return call.any('say_hi_sleepily', {say_hi_timeout}, {
timeout = call_timeout,
})
]], {timeout + 0.1, timeout})

t.assert_equals(results, nil)
t.assert_str_contains(err.err, "Failed for %w+%-0000%-0000%-0000%-000000000000", true)
t.assert_str_contains(err.err, "Timeout exceeded")
end

0 comments on commit fc7bc57

Please sign in to comment.