Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
* drop wrap_box_space_func_result to cut allocations and speed storage calls.

## [1.6.1] - 19-09-25

### Added
Expand Down
4 changes: 2 additions & 2 deletions crud/borders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ local function get_border_on_storage(border_name, space_name, index_id, field_na
return index[border_name](index)
end

return schema.wrap_func_result(space, get_index_border, {index}, {
return schema.wrap_func_result(space, get_index_border, {
add_space_schema_hash = true,
field_names = field_names,
fetch_latest_metadata = fetch_latest_metadata,
})
}, index)
end

borders.storage_api = {[STAT_FUNC_NAME] = get_border_on_storage}
Expand Down
28 changes: 9 additions & 19 deletions crud/common/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,18 @@ function schema.truncate_row_trailing_fields(tuple, field_names)
return tuple
end

function schema.wrap_func_result(space, func, args, opts)
dev_checks('table', 'function', 'table', 'table')
-- schema.wrap_func_result pcalls function
-- and returns its result as a table
-- `{res = ..., err = ..., space_schema_hash = ...}`
-- space_schema_hash is computed if function failed and
-- `add_space_schema_hash` is true
function schema.wrap_func_result(space, func, opts, ...)
dev_checks('table', 'function', 'table')
opts = opts or {}

local result = {}

opts = opts or {}

local ok, func_res = pcall(func, unpack(args))
local ok, func_res = pcall(func, ...)
if ok then
if opts.noreturn ~= true then
result.res = filter_tuple_fields(func_res, opts.field_names)
Expand Down Expand Up @@ -246,20 +250,6 @@ function schema.wrap_func_result(space, func, args, opts)
return result
end

-- schema.wrap_box_space_func_result pcalls some box.space function
-- and returns its result as a table
-- `{res = ..., err = ..., space_schema_hash = ...}`
-- space_schema_hash is computed if function failed and
-- `add_space_schema_hash` is true
function schema.wrap_box_space_func_result(space, box_space_func_name, box_space_func_args, opts)
dev_checks('table', 'string', 'table', 'table')
local function func(space, box_space_func_name, box_space_func_args)
return space[box_space_func_name](space, unpack(box_space_func_args))
end

return schema.wrap_func_result(space, func, {space, box_space_func_name, box_space_func_args}, opts)
end

-- schema.result_needs_reload checks that schema reload can
-- be helpful to avoid storage error.
-- It checks if space_schema_hash returned by storage
Expand Down
4 changes: 2 additions & 2 deletions crud/delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ local function delete_on_storage(space_name, key, field_names, opts)

-- add_space_schema_hash is false because
-- reloading space format on router can't avoid delete error on storage
return schema.wrap_box_space_func_result(space, 'delete', {key}, {
return schema.wrap_func_result(space, space.delete, {
add_space_schema_hash = false,
field_names = field_names,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, key)
end

delete.storage_api = {[DELETE_FUNC_NAME] = delete_on_storage}
Expand Down
4 changes: 2 additions & 2 deletions crud/get.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ local function get_on_storage(space_name, key, field_names, opts)

-- add_space_schema_hash is false because
-- reloading space format on router can't avoid get error on storage
return schema.wrap_box_space_func_result(space, 'get', {key}, {
return schema.wrap_func_result(space, space.get, {
add_space_schema_hash = false,
field_names = field_names,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, key)
end

get.storage_api = {[GET_FUNC_NAME] = get_on_storage}
Expand Down
4 changes: 2 additions & 2 deletions crud/insert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ local function insert_on_storage(space_name, tuple, opts)
-- add_space_schema_hash is true only in case of insert_object
-- the only one case when reloading schema can avoid insert error
-- is flattening object on router
return schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
return schema.wrap_func_result(space, space.insert, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, tuple)
end

insert.storage_api = {[INSERT_FUNC_NAME] = insert_on_storage}
Expand Down
4 changes: 2 additions & 2 deletions crud/insert_many.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ local function insert_many_on_storage(space_name, tuples, opts)
-- add_space_schema_hash is true only in case of insert_object_many
-- the only one case when reloading schema can avoid insert error
-- is flattening object on router
local insert_result = schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
local insert_result = schema.wrap_func_result(space, space.insert, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, tuple)
if opts.fetch_latest_metadata then
replica_schema_version = insert_result.storage_info.replica_schema_version
end
Expand Down
6 changes: 4 additions & 2 deletions crud/replace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ local function replace_on_storage(space_name, tuple, opts)
-- add_space_schema_hash is true only in case of replace_object
-- the only one case when reloading schema can avoid insert error
-- is flattening object on router
return schema.wrap_box_space_func_result(space, 'replace', {tuple}, {

local result = schema.wrap_func_result(space, space.replace, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, tuple)
return result
end

replace.storage_api = {[REPLACE_FUNC_NAME] = replace_on_storage}
Expand Down
4 changes: 2 additions & 2 deletions crud/replace_many.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ local function replace_many_on_storage(space_name, tuples, opts)
-- add_space_schema_hash is true only in case of replace_object_many
-- the only one case when reloading schema can avoid replace error
-- is flattening object on router
local insert_result = schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
local insert_result = schema.wrap_func_result(space, space.replace, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, tuple)

if opts.fetch_latest_metadata then
replica_schema_version = insert_result.storage_info.replica_schema_version
Expand Down
8 changes: 4 additions & 4 deletions crud/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ local function update_on_storage(space_name, key, operations, field_names, opts)

-- add_space_schema_hash is false because
-- reloading space format on router can't avoid update error on storage
local res, err = schema.wrap_box_space_func_result(space, 'update', {key, operations}, {
local res, err = schema.wrap_func_result(space, space.update, {
add_space_schema_hash = false,
field_names = field_names,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, key, operations)

if err ~= nil then
return nil, err
Expand All @@ -66,12 +66,12 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
-- More details: https://github.com/tarantool/tarantool/issues/3378
if utils.is_field_not_found(res.err.code) then
operations = utils.add_intermediate_nullable_fields(operations, space:format(), space:get(key))
res, err = schema.wrap_box_space_func_result(space, 'update', {key, operations}, {
res, err = schema.wrap_func_result(space, space.update, {
add_space_schema_hash = false,
field_names = field_names,
noreturn = opts.noreturn,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, key, operations)
end

return res, err
Expand Down
4 changes: 2 additions & 2 deletions crud/upsert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ local function upsert_on_storage(space_name, tuple, operations, opts)
-- add_space_schema_hash is true only in case of upsert_object
-- the only one case when reloading schema can avoid insert error
-- is flattening object on router
return schema.wrap_box_space_func_result(space, 'upsert', {tuple, operations}, {
return schema.wrap_func_result(space, space.upsert, {
add_space_schema_hash = opts.add_space_schema_hash,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, tuple, operations)
end

upsert.storage_api = {[UPSERT_FUNC_NAME] = upsert_on_storage}
Expand Down
4 changes: 2 additions & 2 deletions crud/upsert_many.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ local function upsert_many_on_storage(space_name, tuples, operations, opts)
-- add_space_schema_hash is true only in case of upsert_object_many
-- the only one case when reloading schema can avoid upsert error
-- is flattening object on router
local insert_result = schema.wrap_box_space_func_result(space, 'upsert', {tuple, operations[i]}, {
local insert_result = schema.wrap_func_result(space, space.upsert, {
add_space_schema_hash = opts.add_space_schema_hash,
fetch_latest_metadata = opts.fetch_latest_metadata,
})
}, space, tuple, operations[i])
if opts.fetch_latest_metadata then
replica_schema_version = insert_result.storage_info.replica_schema_version
end
Expand Down