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, which doesn't currently work with
C stored procedures due to the bug. Let's use box.func, where it's
possible instead of net_box.self.call in local_call.

Closes #436

NO_DOC=bugfix
  • Loading branch information
Serpentian committed Nov 21, 2023
1 parent 9fda354 commit 8cdac9d
Show file tree
Hide file tree
Showing 2 changed files with 25 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.0.
t.run_only_if(vutil.version_is_at_least(2, 2, 0, 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
12 changes: 11 additions & 1 deletion vshard/storage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,17 @@ end
-- exceptions are not allowed.
--
local function local_call(func_name, args)
return pcall(netbox_self_call, netbox_self, func_name, args)
-- If function was created with box.schema.func we call it via
-- func.call API, as net_box.self.call doesn't work with C stored
-- procedures up to Tarantool 3.X. If box.func is inaccessible,
-- which is true for all versions below 2.2, we fallback to
-- net_box.self.call too.
if box.func == nil or box.func[func_name] == nil then
return pcall(netbox_self_call, netbox_self, func_name, args)
end

local func = box.func[func_name]
return pcall(func.call, func, args)
end

local function master_call(replicaset, func, args, opts)
Expand Down

0 comments on commit 8cdac9d

Please sign in to comment.