[Tarantool-patches] [PATCH vshard 02/11] storage: add helper for local functions invocation

Oleg Babin olegrok at tarantool.org
Wed Feb 24 13:27:24 MSK 2021


Hi! Thanks for your patch. LGTM.

On 23.02.2021 03:15, Vladislav Shpilevoy wrote:
> Function local_call() works like netbox.self.call, but is
> exception-safe, and uses cached values of 'netbox.self' and
> 'netbox.self.call'. This saves at least 3 indexing operations,
> which are not free as it appeared.
>
> The cached values are not used directly in storage_call(), because
> local_call() also will be used from the future function
> storage_map() - a part of map-reduce API.
>
> Needed for #147
> ---
>   vshard/storage/init.lua | 14 +++++++++++++-
>   1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua
> index e0ce31d..a3d383d 100644
> --- a/vshard/storage/init.lua
> +++ b/vshard/storage/init.lua
> @@ -6,6 +6,8 @@ local trigger = require('internal.trigger')
>   local ffi = require('ffi')
>   local yaml_encode = require('yaml').encode
>   local fiber_clock = lfiber.clock
> +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.
> @@ -171,6 +173,16 @@ else
>       bucket_ref_new = ffi.typeof("struct bucket_ref")
>   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 function local_call(func_name, args)
> +    return pcall(netbox_self_call, netbox_self, func_name, args)
> +end
> +
>   --
>   -- Trigger for on replace into _bucket to update its generation.
>   --
> @@ -2275,7 +2287,7 @@ local function storage_call(bucket_id, mode, name, args)
>       if not ok then
>           return ok, err
>       end
> -    ok, ret1, ret2, ret3 = pcall(netbox.self.call, netbox.self, name, args)
> +    ok, ret1, ret2, ret3 = local_call(name, args)
>       _, err = bucket_unref(bucket_id, mode)
>       assert(not err)
>       if not ok then


More information about the Tarantool-patches mailing list