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

storage: fix local_call not finding C stored procedures #437

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions test/storage-luatest/storage_1_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,17 @@ test_group.test_recovery_bucket_stat = function(g)

vtest.cluster_cfg(g, global_cfg)
end

test_group.test_local_call = function(g)
-- box.func was introduced in 2.2.1.
t.run_only_if(vutil.version_is_at_least(2, 2, 1, nil, 0, 0))
g.replica_1_a:exec(function()
local body = [[function(a, b) return a + b end]]
box.schema.func.create('sum', {body = body})
local bid = _G.get_first_bucket()
local ok, ret = ivshard.storage.call(bid, 'read', 'sum', {1, 2})
ilt.assert_equals(ret, 3)
ilt.assert_equals(ok, true)
box.func.sum:drop()
end)
end
21 changes: 20 additions & 1 deletion vshard/storage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,29 @@ end
-- The function returns pcall() as is, because is used from places where
-- exceptions are not allowed.
Gerold103 marked this conversation as resolved.
Show resolved Hide resolved
--
local function local_call(func_name, args)
local local_call

if util.version_is_at_least(3, 0, 0, 'beta', 1, 18) then

local_call = function(func_name, args)
return pcall(netbox_self_call, netbox_self, func_name, args)
end

else -- < 3.0.0-beta1-18

-- net_box.self.call() doesn't work with C stored and Lua persistent
-- functions before 3.0.0-beta1-18, so we try to call it via func.call
-- API prior to using net_box.self API.
local_call = function(func_name, args)
local func = box.func and box.func[func_name]
if not func then
return pcall(netbox_self_call, netbox_self, func_name, args)
end
return pcall(func.call, func, args)
end

end

local function master_call(replicaset, func, args, opts)
local deadline = fiber_clock() + opts.timeout
local did_first_attempt = false
Expand Down
Loading