Skip to content

Commit

Permalink
storage: fix local_call not finding persistent func
Browse files Browse the repository at this point in the history
Currently, if function was created as C stored procedure or as Lua
persistent function (with body argument) via box.schema.func.create,
all types of router.call and router.map_callrw cannot find it and
return `Procedure 'name' is not defined` error.

This is cased by the fact that both of these function use local_call,
which invokes net_box.self.call. It didn't work with these type of
functions before Tarantool 3.0.0-beta1-18. Let's use box.func, where
it's needed instead of net_box.self.call in local_call.

Closes #436

NO_DOC=bugfix
  • Loading branch information
Serpentian authored and Gerold103 committed Dec 6, 2023
1 parent 16bbae3 commit 28d1b4e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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.
--
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

0 comments on commit 28d1b4e

Please sign in to comment.