Skip to content

Commit 781ef16

Browse files
GRISHNOVDifferentialOrange
authored andcommitted
feature: add noreturn opt for some DML operations
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
1 parent 121e765 commit 781ef16

16 files changed

+545
-3
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
* Add `noreturn` option for operations:
12+
`insert`, `insert_object`, `insert_many`, `insert_object_many`,
13+
`replace`, `replace_object`, `replace_many`, `insert_object_many`,
14+
`upsert`, `upsert_object`, `upsert_many`, `upsert_object_many`,
15+
`update`, `delete`. (#267).
16+
817
## [1.1.1] - 24-03-23
918

1019
### Changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ where:
234234
since each replicaset has its own sequence. If sequence field is a part
235235
of the sharding key (which is true by default), choosing the bucket id is
236236
the sole responsibility of the developer
237+
* `noreturn` (`?boolean`) - suppress successfully processed tuple
238+
(first return value is `nil`). `false` by default
237239

238240
Returns metadata and array contains one inserted row, error.
239241

@@ -299,6 +301,8 @@ where:
299301
since each replicaset has its own sequence. If sequence field is a part
300302
of the sharding key (which is true by default), choosing the bucket id is
301303
the sole responsibility of the developer
304+
* `noreturn` (`?boolean`) - suppress successfully processed tuples
305+
(first return value is `nil`). `false` by default
302306

303307
Returns metadata and array with inserted rows, array of errors.
304308
Each error object can contain field `operation_data`.
@@ -474,6 +478,8 @@ where:
474478
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
475479
vshard router instance. Set this parameter if your space is not
476480
a part of the default vshard cluster
481+
* `noreturn` (`?boolean`) - suppress successfully processed tuple
482+
(first return value is `nil`). `false` by default
477483

478484
Returns metadata and array contains one updated row, error.
479485

@@ -510,6 +516,8 @@ where:
510516
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
511517
vshard router instance. Set this parameter if your space is not
512518
a part of the default vshard cluster
519+
* `noreturn` (`?boolean`) - suppress successfully processed tuple
520+
(first return value is `nil`). `false` by default
513521

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

@@ -557,6 +565,8 @@ where:
557565
since each replicaset has its own sequence. If sequence field is a part
558566
of the sharding key (which is true by default), choosing the bucket id is
559567
the sole responsibility of the developer
568+
* `noreturn` (`?boolean`) - suppress successfully processed tuple
569+
(first return value is `nil`). `false` by default
560570

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

@@ -622,6 +632,8 @@ where:
622632
since each replicaset has its own sequence. If sequence field is a part
623633
of the sharding key (which is true by default), choosing the bucket id is
624634
the sole responsibility of the developer
635+
* `noreturn` (`?boolean`) - suppress successfully processed tuples
636+
(first return value is `nil`). `false` by default
625637

626638
Returns metadata and array with inserted/replaced rows, array of errors.
627639
Each error object can contain field `operation_data`.
@@ -758,6 +770,8 @@ where:
758770
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
759771
vshard router instance. Set this parameter if your space is not
760772
a part of the default vshard cluster
773+
* `noreturn` (`?boolean`) - suppress successfully processed tuple
774+
(first return value is `nil`). `false` by default
761775

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

@@ -819,6 +833,8 @@ where:
819833
* `vshard_router` (`?string|table`) - Cartridge vshard group name or
820834
vshard router instance. Set this parameter if your space is not
821835
a part of the default vshard cluster
836+
* `noreturn` (`?boolean`) - suppress successfully processed tuples
837+
(first return value is `nil`). `false` by default
822838

823839
Returns metadata and array of errors.
824840
Each error object can contain field `operation_data`.

crud/common/schema.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ function schema.wrap_func_result(space, func, args, opts)
216216
result.space_schema_hash = get_space_schema_hash(space)
217217
end
218218
else
219-
result.res = filter_tuple_fields(func_res, opts.field_names)
219+
if opts.noreturn ~= true then
220+
result.res = filter_tuple_fields(func_res, opts.field_names)
221+
end
220222
end
221223

222224
return result

crud/delete.lua

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local function delete_on_storage(space_name, key, field_names, opts)
2121
sharding_key_hash = '?number',
2222
sharding_func_hash = '?number',
2323
skip_sharding_hash_check = '?boolean',
24+
noreturn = '?boolean',
2425
})
2526

2627
opts = opts or {}
@@ -44,6 +45,7 @@ local function delete_on_storage(space_name, key, field_names, opts)
4445
return schema.wrap_box_space_func_result(space, 'delete', {key}, {
4546
add_space_schema_hash = false,
4647
field_names = field_names,
48+
noreturn = opts.noreturn,
4749
})
4850
end
4951

@@ -60,6 +62,7 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
6062
bucket_id = '?number|cdata',
6163
fields = '?table',
6264
vshard_router = '?string|table',
65+
noreturn = '?boolean',
6366
})
6467

6568
local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
@@ -108,6 +111,7 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
108111
sharding_func_hash = bucket_id_data.sharding_func_hash,
109112
sharding_key_hash = sharding_key_hash,
110113
skip_sharding_hash_check = skip_sharding_hash_check,
114+
noreturn = opts.noreturn,
111115
}
112116

113117
local call_opts = {
@@ -135,6 +139,10 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
135139
return nil, DeleteError:new("Failed to delete: %s", storage_result.err)
136140
end
137141

142+
if opts.noreturn == true then
143+
return nil
144+
end
145+
138146
local tuple = storage_result.res
139147

140148
return utils.format_result({tuple}, space, opts.fields)
@@ -162,6 +170,9 @@ end
162170
-- Set this parameter if your space is not a part of the
163171
-- default vshard cluster.
164172
--
173+
-- @tparam ?boolean opts.noreturn
174+
-- Suppress returning successfully processed tuple.
175+
--
165176
-- @return[1] object
166177
-- @treturn[2] nil
167178
-- @treturn[2] table Error description
@@ -172,6 +183,7 @@ function delete.call(space_name, key, opts)
172183
bucket_id = '?number|cdata',
173184
fields = '?table',
174185
vshard_router = '?string|table',
186+
noreturn = '?boolean',
175187
})
176188

177189
opts = opts or {}

crud/insert.lua

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local function insert_on_storage(space_name, tuple, opts)
2121
sharding_key_hash = '?number',
2222
sharding_func_hash = '?number',
2323
skip_sharding_hash_check = '?boolean',
24+
noreturn = '?boolean',
2425
})
2526

2627
opts = opts or {}
@@ -45,6 +46,7 @@ local function insert_on_storage(space_name, tuple, opts)
4546
return schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
4647
add_space_schema_hash = opts.add_space_schema_hash,
4748
field_names = opts.fields,
49+
noreturn = opts.noreturn,
4850
})
4951
end
5052

@@ -63,6 +65,7 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
6365
fields = '?table',
6466
vshard_router = '?string|table',
6567
skip_nullability_check_on_flatten = '?boolean',
68+
noreturn = '?boolean',
6669
})
6770

6871
local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
@@ -86,6 +89,7 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
8689
sharding_func_hash = sharding_data.sharding_func_hash,
8790
sharding_key_hash = sharding_data.sharding_key_hash,
8891
skip_sharding_hash_check = sharding_data.skip_sharding_hash_check,
92+
noreturn = opts.noreturn,
8993
}
9094

9195
local call_opts = {
@@ -119,6 +123,10 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
119123
return nil, err_wrapped
120124
end
121125

126+
if opts.noreturn == true then
127+
return nil
128+
end
129+
122130
local tuple = storage_result.res
123131

124132
return utils.format_result({tuple}, space, opts.fields)
@@ -146,6 +154,9 @@ end
146154
-- Set this parameter if your space is not a part of the
147155
-- default vshard cluster.
148156
--
157+
-- @tparam ?boolean opts.noreturn
158+
-- Suppress returning successfully processed tuple.
159+
--
149160
-- @return[1] tuple
150161
-- @treturn[2] nil
151162
-- @treturn[2] table Error description
@@ -157,6 +168,7 @@ function insert.tuple(space_name, tuple, opts)
157168
add_space_schema_hash = '?boolean',
158169
fields = '?table',
159170
vshard_router = '?string|table',
171+
noreturn = '?boolean',
160172
})
161173

162174
opts = opts or {}
@@ -195,6 +207,7 @@ function insert.object(space_name, obj, opts)
195207
fields = '?table',
196208
vshard_router = '?string|table',
197209
skip_nullability_check_on_flatten = '?boolean',
210+
noreturn = '?boolean',
198211
})
199212

200213
opts = opts or {}

crud/insert_many.lua

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local function insert_many_on_storage(space_name, tuples, opts)
2727
sharding_key_hash = '?number',
2828
sharding_func_hash = '?number',
2929
skip_sharding_hash_check = '?boolean',
30+
noreturn = '?boolean',
3031
})
3132

3233
opts = opts or {}
@@ -56,6 +57,7 @@ local function insert_many_on_storage(space_name, tuples, opts)
5657
local insert_result = schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
5758
add_space_schema_hash = opts.add_space_schema_hash,
5859
field_names = opts.fields,
60+
noreturn = opts.noreturn,
5961
})
6062

6163
if insert_result.err ~= nil then
@@ -130,6 +132,7 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
130132
rollback_on_error = '?boolean',
131133
vshard_router = '?string|table',
132134
skip_nullability_check_on_flatten = '?boolean',
135+
noreturn = '?boolean',
133136
})
134137

135138
local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
@@ -149,6 +152,7 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
149152
fields = opts.fields,
150153
stop_on_error = opts.stop_on_error,
151154
rollback_on_error = opts.rollback_on_error,
155+
noreturn = opts.noreturn,
152156
}
153157

154158
local iter, err = BatchInsertIterator:new({
@@ -220,6 +224,7 @@ function insert_many.tuples(space_name, tuples, opts)
220224
stop_on_error = '?boolean',
221225
rollback_on_error = '?boolean',
222226
vshard_router = '?string|table',
227+
noreturn = '?boolean',
223228
})
224229

225230
opts = opts or {}
@@ -258,6 +263,7 @@ function insert_many.objects(space_name, objs, opts)
258263
rollback_on_error = '?boolean',
259264
vshard_router = '?string|table',
260265
skip_nullability_check_on_flatten = '?boolean',
266+
noreturn = '?boolean',
261267
})
262268

263269
opts = opts or {}

crud/replace.lua

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local function replace_on_storage(space_name, tuple, opts)
2121
sharding_key_hash = '?number',
2222
sharding_func_hash = '?number',
2323
skip_sharding_hash_check = '?boolean',
24+
noreturn = '?boolean',
2425
})
2526

2627
opts = opts or {}
@@ -45,6 +46,7 @@ local function replace_on_storage(space_name, tuple, opts)
4546
return schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
4647
add_space_schema_hash = opts.add_space_schema_hash,
4748
field_names = opts.fields,
49+
noreturn = opts.noreturn,
4850
})
4951
end
5052

@@ -63,6 +65,7 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
6365
fields = '?table',
6466
vshard_router = '?string|table',
6567
skip_nullability_check_on_flatten = '?boolean',
68+
noreturn = '?boolean',
6669
})
6770

6871
local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
@@ -86,6 +89,7 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
8689
sharding_func_hash = sharding_data.sharding_func_hash,
8790
sharding_key_hash = sharding_data.sharding_key_hash,
8891
skip_sharding_hash_check = sharding_data.skip_sharding_hash_check,
92+
noreturn = opts.noreturn,
8993
}
9094

9195
local call_opts = {
@@ -118,6 +122,10 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
118122
return nil, err_wrapped
119123
end
120124

125+
if opts.noreturn == true then
126+
return nil
127+
end
128+
121129
local tuple = storage_result.res
122130

123131
return utils.format_result({tuple}, space, opts.fields)
@@ -145,6 +153,9 @@ end
145153
-- Set this parameter if your space is not a part of the
146154
-- default vshard cluster.
147155
--
156+
-- @tparam ?boolean opts.noreturn
157+
-- Suppress returning successfully processed tuple.
158+
--
148159
-- @return[1] object
149160
-- @treturn[2] nil
150161
-- @treturn[2] table Error description
@@ -156,6 +167,7 @@ function replace.tuple(space_name, tuple, opts)
156167
add_space_schema_hash = '?boolean',
157168
fields = '?table',
158169
vshard_router = '?string|table',
170+
noreturn = '?boolean',
159171
})
160172

161173
opts = opts or {}
@@ -194,6 +206,7 @@ function replace.object(space_name, obj, opts)
194206
fields = '?table',
195207
vshard_router = '?string|table',
196208
skip_nullability_check_on_flatten = '?boolean',
209+
noreturn = '?boolean',
197210
})
198211

199212
opts = opts or {}

crud/replace_many.lua

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local function replace_many_on_storage(space_name, tuples, opts)
2727
sharding_key_hash = '?number',
2828
sharding_func_hash = '?number',
2929
skip_sharding_hash_check = '?boolean',
30+
noreturn = '?boolean',
3031
})
3132

3233
opts = opts or {}
@@ -56,6 +57,7 @@ local function replace_many_on_storage(space_name, tuples, opts)
5657
local insert_result = schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
5758
add_space_schema_hash = opts.add_space_schema_hash,
5859
field_names = opts.fields,
60+
noreturn = opts.noreturn,
5961
})
6062

6163
table.insert(errs, err)
@@ -132,6 +134,7 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
132134
rollback_on_error = '?boolean',
133135
vshard_router = '?string|table',
134136
skip_nullability_check_on_flatten = '?boolean',
137+
noreturn = '?boolean',
135138
})
136139

137140
local space, err = utils.get_space(space_name, vshard_router, opts.timeout)
@@ -151,6 +154,7 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
151154
fields = opts.fields,
152155
stop_on_error = opts.stop_on_error,
153156
rollback_on_error = opts.rollback_on_error,
157+
noreturn = opts.noreturn,
154158
}
155159

156160
local iter, err = BatchInsertIterator:new({
@@ -222,6 +226,7 @@ function replace_many.tuples(space_name, tuples, opts)
222226
stop_on_error = '?boolean',
223227
rollback_on_error = '?boolean',
224228
vshard_router = '?string|table',
229+
noreturn = '?boolean',
225230
})
226231

227232
opts = opts or {}
@@ -260,6 +265,7 @@ function replace_many.objects(space_name, objs, opts)
260265
rollback_on_error = '?boolean',
261266
vshard_router = '?string|table',
262267
skip_nullability_check_on_flatten = '?boolean',
268+
noreturn = '?boolean',
263269
})
264270

265271
opts = opts or {}

0 commit comments

Comments
 (0)