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 DML operarions:
`insert`, `insert_object`, `insert_many`, `insert_object_many`,
`replace`, `replace_object`, `replace_many`, `insert_object_many`,
`upsert`, `upsert_object`, `upsert_many`, `upsert_object_many`,
`update`, `delete`.
The opt allows to suppress returning successfully processed tuple(s).

Closes #267
  • Loading branch information
GRISHNOV committed Mar 31, 2023
1 parent c2900be commit af0ce90
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ 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` option for operations:
`insert`, `insert_object`, `insert_many`, `insert_object_many`,
`replace`, `replace_object`, `replace_many`, `insert_object_many`,
`upsert`, `upsert_object`, `upsert_many`, `upsert_object_many`,
`update`, `delete`. (#267).

## [1.1.1] - 24-03-23

### Changed
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ 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 successfully processed tuple
(first return value is `nil`). `false` by default

Returns metadata and array contains one inserted row, error.

Expand Down Expand Up @@ -299,6 +301,8 @@ 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 successfully processed tuples
(first return value is `nil`). `false` by default

Returns metadata and array with inserted rows, array of errors.
Each error object can contain field `operation_data`.
Expand Down Expand Up @@ -474,6 +478,8 @@ 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 successfully processed tuple
(first return value is `nil`). `false` by default

Returns metadata and array contains one updated row, error.

Expand Down Expand Up @@ -510,6 +516,8 @@ 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 successfully processed tuple
(first return value is `nil`). `false` by default

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

Expand Down Expand Up @@ -557,6 +565,8 @@ 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 successfully processed tuple
(first return value is `nil`). `false` by default

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

Expand Down Expand Up @@ -622,6 +632,8 @@ 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 successfully processed tuples
(first return value is `nil`). `false` by default

Returns metadata and array with inserted/replaced rows, array of errors.
Each error object can contain field `operation_data`.
Expand Down Expand Up @@ -758,6 +770,8 @@ 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 successfully processed tuple
(first return value is `nil`). `false` by default

Returns metadata and empty array of rows or nil, error.

Expand Down Expand Up @@ -819,6 +833,8 @@ 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 successfully processed tuples
(first return value is `nil`). `false` by default

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
12 changes: 12 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 @@ -135,6 +139,10 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
return nil, DeleteError:new("Failed to delete: %s", storage_result.err)
end

if opts.noreturn == true then
return nil
end

local tuple = storage_result.res

return utils.format_result({tuple}, space, opts.fields)
Expand Down Expand Up @@ -162,6 +170,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 +183,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
13 changes: 13 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 @@ -63,6 +65,7 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
fields = '?table',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -86,6 +89,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 @@ -119,6 +123,10 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
return nil, err_wrapped
end

if opts.noreturn == true then
return nil
end

local tuple = storage_result.res

return utils.format_result({tuple}, space, opts.fields)
Expand Down Expand Up @@ -146,6 +154,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 @@ -157,6 +168,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 @@ -195,6 +207,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 @@ -130,6 +132,7 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
rollback_on_error = '?boolean',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -149,6 +152,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 @@ -220,6 +224,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 @@ -258,6 +263,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
13 changes: 13 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 @@ -63,6 +65,7 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
fields = '?table',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -86,6 +89,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 @@ -118,6 +122,10 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
return nil, err_wrapped
end

if opts.noreturn == true then
return nil
end

local tuple = storage_result.res

return utils.format_result({tuple}, space, opts.fields)
Expand Down Expand Up @@ -145,6 +153,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 @@ -156,6 +167,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 @@ -194,6 +206,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 @@ -132,6 +134,7 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
rollback_on_error = '?boolean',
vshard_router = '?string|table',
skip_nullability_check_on_flatten = '?boolean',
noreturn = '?boolean',
})

local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
Expand All @@ -151,6 +154,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 @@ -222,6 +226,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 @@ -260,6 +265,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
Loading

0 comments on commit af0ce90

Please sign in to comment.