Skip to content
Draft
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
26 changes: 26 additions & 0 deletions test/storage-luatest/storage_1_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,29 @@ test_group.test_info_disable_consistency = function(g)
ilt.assert(res.is_enabled)
end, {global_cfg})
end

local function test_error_msg_is_preserved_template(add_to_schema, g)
g.replica_1_a:exec(function(add_to_schema)
rawset(_G, 'test_fail', function()
box.begin()
error('test_error')
end)
if add_to_schema then
box.schema.func.create('test_fail')
end
local status, err = ivshard.storage.call(1, 'read', 'test_fail', {})
ilt.assert_not(status)
local err_msg = tostring(err)
ilt.assert_str_contains(err_msg, 'test_error')
ilt.assert_not_str_contains(err_msg, 'Transaction is active')
rawset(_G, 'test_fail', nil)
if add_to_schema then
box.schema.func.drop('test_fail')
end
end, {add_to_schema})
end

test_group.test_error_msg_is_preserved = function(g)
test_error_msg_is_preserved_template(false, g)
test_error_msg_is_preserved_template(true, g)
end
55 changes: 28 additions & 27 deletions vshard/storage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ local log = require('log')
local luri = require('uri')
local lfiber = require('fiber')
local lmsgpack = require('msgpack')
local netbox = require('net.box') -- for net.box:self()
local trigger = require('internal.trigger')
local ffi = require('ffi')
local json_encode = require('json').encode
local yaml_encode = require('yaml').encode
local fiber_clock = lfiber.clock
local fiber_yield = lfiber.yield
local netbox_self = netbox.self
local netbox_self_call = netbox_self.call

local MODULE_INTERNALS = '__module_vshard_storage'
-- Reload requirements, in case this module is reloaded manually.
Expand Down Expand Up @@ -260,33 +257,37 @@ else
end
end

--
-- Invoke a function on this instance. Arguments are unpacked into the function
-- as arguments.
-- The function returns pcall() as is, because is used from places where
-- exceptions are not allowed.
--
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)
local function handle_results(status, ...)
if not status then
box.rollback()
return status, box.error.new(box.error.PROC_LUA, (...))
end
return pcall(func.call, func, args)
return status, ...
end

--
-- Reimplementation of the net.box.self.call(), but without encoding/decoding
-- of the arguments. Invoke a function on this instance. Arguments are unpacked
-- into the function as arguments. The function returns pcall() as is, because
-- is used from places where exceptions are not allowed.
--
local function local_call(name, args)
args = args or {}
name = tostring(name)
local status, func, obj
func = box.func and box.func[name]
if func then
return handle_results(pcall(func.call, func, args))
end
status, func, obj = handle_results(pcall(box.internal.call_loadproc, name))
if not status then
return status, func
end
if obj ~= nil then
return handle_results(pcall(func, obj, unpack(args)))
else
return handle_results(pcall(func, unpack(args)))
Comment on lines +287 to +289

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tarantool> unpack({1, nil, 3})
---
- 1
Suggested change
return handle_results(pcall(func, obj, unpack(args)))
else
return handle_results(pcall(func, unpack(args)))
return handle_results(pcall(func, obj, unpack(args, 1, table.maxn(args))))
else
return handle_results(pcall(func, unpack(args, 1, table.maxn(args))))

end
end

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