Skip to content

Commit

Permalink
feature: add noreturn opt for some DML operations
Browse files Browse the repository at this point in the history
This patch introduces `noreturn` opt for some DML operarions
(`insert`, `replace`, `update`, `delete`, `insert_many`,
`replace_many`, `upsert_many`) which suppress returning
successfully processed tuple(s).

Closes #267
  • Loading branch information
GRISHNOV committed Mar 29, 2023
1 parent 83b3d84 commit 91c5357
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
* Add `noreturn` opt for some DML operations (PR #356).

## [1.1.1] - 24-03-23

### Changed
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ where:
since each replicaset has its own sequence. If sequence field is a part
of the sharding key (which is true by default), choosing the bucket id is
the sole responsibility of the developer
* `noreturn` (`?boolean`) - suppress returning successfully processed tuple

Returns metadata and array contains one inserted row, error.

Expand Down Expand Up @@ -299,6 +300,7 @@ where:
since each replicaset has its own sequence. If sequence field is a part
of the sharding key (which is true by default), choosing the bucket id is
the sole responsibility of the developer
* `noreturn` (`?boolean`) - suppress returning successfully processed tuples

Returns metadata and array with inserted rows, array of errors.
Each error object can contain field `operation_data`.
Expand Down Expand Up @@ -474,6 +476,7 @@ where:
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
vshard router instance. Set this parameter if your space is not
a part of the default vshard cluster
* `noreturn` (`?boolean`) - suppress returning successfully processed tuple

Returns metadata and array contains one updated row, error.

Expand Down Expand Up @@ -510,6 +513,7 @@ where:
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
vshard router instance. Set this parameter if your space is not
a part of the default vshard cluster
* `noreturn` (`?boolean`) - suppress returning successfully processed tuple

Returns metadata and array contains one deleted row (empty for vinyl), error.

Expand Down Expand Up @@ -557,6 +561,7 @@ where:
since each replicaset has its own sequence. If sequence field is a part
of the sharding key (which is true by default), choosing the bucket id is
the sole responsibility of the developer
* `noreturn` (`?boolean`) - suppress returning successfully processed tuple

Returns inserted or replaced rows and metadata or nil with error.

Expand Down Expand Up @@ -622,6 +627,7 @@ where:
since each replicaset has its own sequence. If sequence field is a part
of the sharding key (which is true by default), choosing the bucket id is
the sole responsibility of the developer
* `noreturn` (`?boolean`) - suppress returning successfully processed tuples

Returns metadata and array with inserted/replaced rows, array of errors.
Each error object can contain field `operation_data`.
Expand Down Expand Up @@ -819,6 +825,7 @@ where:
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
vshard router instance. Set this parameter if your space is not
a part of the default vshard cluster
* `noreturn` (`?boolean`) - suppress returning successfully processed tuples

Returns metadata and array of errors.
Each error object can contain field `operation_data`.
Expand Down
4 changes: 3 additions & 1 deletion crud/common/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ function schema.wrap_func_result(space, func, args, opts)
result.space_schema_hash = get_space_schema_hash(space)
end
else
result.res = filter_tuple_fields(func_res, opts.field_names)
if opts.noreturn ~= true then
result.res = filter_tuple_fields(func_res, opts.field_names)
end
end

return result
Expand Down
8 changes: 8 additions & 0 deletions crud/delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local function delete_on_storage(space_name, key, field_names, opts)
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand All @@ -44,6 +45,7 @@ local function delete_on_storage(space_name, key, field_names, opts)
return schema.wrap_box_space_func_result(space, 'delete', {key}, {
add_space_schema_hash = false,
field_names = field_names,
noreturn = opts.noreturn,
})
end

Expand All @@ -60,6 +62,7 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
bucket_id = '?number|cdata',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand Down Expand Up @@ -108,6 +111,7 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
sharding_func_hash = bucket_id_data.sharding_func_hash,
sharding_key_hash = sharding_key_hash,
skip_sharding_hash_check = skip_sharding_hash_check,
noreturn = opts.noreturn,
}

local call_opts = {
Expand Down Expand Up @@ -162,6 +166,9 @@ end
-- Set this parameter if your space is not a part of the
-- default vshard cluster.
--
-- @tparam ?boolean opts.noreturn
-- Suppress returning successfully processed tuple.
--
-- @return[1] object
-- @treturn[2] nil
-- @treturn[2] table Error description
Expand All @@ -172,6 +179,7 @@ function delete.call(space_name, key, opts)
bucket_id = '?number|cdata',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down
9 changes: 9 additions & 0 deletions crud/insert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local function insert_on_storage(space_name, tuple, opts)
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand All @@ -45,6 +46,7 @@ local function insert_on_storage(space_name, tuple, opts)
return schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
})
end

Expand All @@ -62,6 +64,7 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
add_space_schema_hash = '?boolean',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -85,6 +88,7 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
sharding_func_hash = sharding_data.sharding_func_hash,
sharding_key_hash = sharding_data.sharding_key_hash,
skip_sharding_hash_check = sharding_data.skip_sharding_hash_check,
noreturn = opts.noreturn,
}

local call_opts = {
Expand Down Expand Up @@ -145,6 +149,9 @@ end
-- Set this parameter if your space is not a part of the
-- default vshard cluster.
--
-- @tparam ?boolean opts.noreturn
-- Suppress returning successfully processed tuple.
--
-- @return[1] tuple
-- @treturn[2] nil
-- @treturn[2] table Error description
Expand All @@ -156,6 +163,7 @@ function insert.tuple(space_name, tuple, opts)
add_space_schema_hash = '?boolean',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down Expand Up @@ -194,6 +202,7 @@ function insert.object(space_name, obj, opts)
fields = '?table',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down
6 changes: 6 additions & 0 deletions crud/insert_many.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ local function insert_many_on_storage(space_name, tuples, opts)
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down Expand Up @@ -56,6 +57,7 @@ local function insert_many_on_storage(space_name, tuples, opts)
local insert_result = schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
})

if insert_result.err ~= nil then
Expand Down Expand Up @@ -129,6 +131,7 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
stop_on_error = '?boolean',
rollback_on_error = '?boolean',
vshard_router = '?string|table',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -148,6 +151,7 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
fields = opts.fields,
stop_on_error = opts.stop_on_error,
rollback_on_error = opts.rollback_on_error,
noreturn = opts.noreturn,
}

local iter, err = BatchInsertIterator:new({
Expand Down Expand Up @@ -219,6 +223,7 @@ function insert_many.tuples(space_name, tuples, opts)
stop_on_error = '?boolean',
rollback_on_error = '?boolean',
vshard_router = '?string|table',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down Expand Up @@ -257,6 +262,7 @@ function insert_many.objects(space_name, objs, opts)
rollback_on_error = '?boolean',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down
9 changes: 9 additions & 0 deletions crud/replace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local function replace_on_storage(space_name, tuple, opts)
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand All @@ -45,6 +46,7 @@ local function replace_on_storage(space_name, tuple, opts)
return schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
})
end

Expand All @@ -62,6 +64,7 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
add_space_schema_hash = '?boolean',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -85,6 +88,7 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
sharding_func_hash = sharding_data.sharding_func_hash,
sharding_key_hash = sharding_data.sharding_key_hash,
skip_sharding_hash_check = sharding_data.skip_sharding_hash_check,
noreturn = opts.noreturn,
}

local call_opts = {
Expand Down Expand Up @@ -144,6 +148,9 @@ end
-- Set this parameter if your space is not a part of the
-- default vshard cluster.
--
-- @tparam ?boolean opts.noreturn
-- Suppress returning successfully processed tuple.
--
-- @return[1] object
-- @treturn[2] nil
-- @treturn[2] table Error description
Expand All @@ -155,6 +162,7 @@ function replace.tuple(space_name, tuple, opts)
add_space_schema_hash = '?boolean',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down Expand Up @@ -193,6 +201,7 @@ function replace.object(space_name, obj, opts)
fields = '?table',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down
6 changes: 6 additions & 0 deletions crud/replace_many.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ local function replace_many_on_storage(space_name, tuples, opts)
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down Expand Up @@ -56,6 +57,7 @@ local function replace_many_on_storage(space_name, tuples, opts)
local insert_result = schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
add_space_schema_hash = opts.add_space_schema_hash,
field_names = opts.fields,
noreturn = opts.noreturn,
})

table.insert(errs, err)
Expand Down Expand Up @@ -131,6 +133,7 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
stop_on_error = '?boolean',
rollback_on_error = '?boolean',
vshard_router = '?string|table',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -150,6 +153,7 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
fields = opts.fields,
stop_on_error = opts.stop_on_error,
rollback_on_error = opts.rollback_on_error,
noreturn = opts.noreturn,
}

local iter, err = BatchInsertIterator:new({
Expand Down Expand Up @@ -221,6 +225,7 @@ function replace_many.tuples(space_name, tuples, opts)
stop_on_error = '?boolean',
rollback_on_error = '?boolean',
vshard_router = '?string|table',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down Expand Up @@ -259,6 +264,7 @@ function replace_many.objects(space_name, objs, opts)
rollback_on_error = '?boolean',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down
8 changes: 8 additions & 0 deletions crud/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
noreturn = '?boolean',
})

opts = opts or {}
Expand All @@ -44,6 +45,7 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
local res, err = schema.wrap_box_space_func_result(space, 'update', {key, operations}, {
add_space_schema_hash = false,
field_names = field_names,
noreturn = opts.noreturn,
})

if err ~= nil then
Expand Down Expand Up @@ -82,6 +84,7 @@ local function call_update_on_router(vshard_router, space_name, key, user_operat
bucket_id = '?number|cdata',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand Down Expand Up @@ -140,6 +143,7 @@ local function call_update_on_router(vshard_router, space_name, key, user_operat
sharding_func_hash = bucket_id_data.sharding_func_hash,
sharding_key_hash = sharding_key_hash,
skip_sharding_hash_check = skip_sharding_hash_check,
noreturn = opts.noreturn,
}

local call_opts = {
Expand Down Expand Up @@ -198,6 +202,9 @@ end
-- Set this parameter if your space is not a part of the
-- default vshard cluster.
--
-- @tparam ?boolean opts.noreturn
-- Suppress returning successfully processed tuple.
--
-- @return[1] object
-- @treturn[2] nil
-- @treturn[2] table Error description
Expand All @@ -208,6 +215,7 @@ function update.call(space_name, key, user_operations, opts)
bucket_id = '?number|cdata',
fields = '?table',
vshard_router = '?string|table',
noreturn = '?boolean',
})

opts = opts or {}
Expand Down
Loading

0 comments on commit 91c5357

Please sign in to comment.