-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Batch upsert is mostly used for operation with one bucket / one Tarantool node in a transaction. In this case batch upsert is more efficient then upserting tuple-by-tuple. Right now CRUD cannot provide batch upsert with full consistency. CRUD offers batch upsert with partial consistency. That means that full consistency can be provided only on single replicaset using `box` transactions. Part of #193
- Loading branch information
1 parent
82294c8
commit b48fe50
Showing
11 changed files
with
2,722 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
local errors = require('errors') | ||
|
||
local dev_checks = require('crud.common.dev_checks') | ||
local sharding = require('crud.common.sharding') | ||
|
||
local BaseIterator = require('crud.common.map_call_cases.base_iter') | ||
|
||
local SplitTuplesError = errors.new_class('SplitTuplesError') | ||
|
||
local BatchUpsertIterator = {} | ||
-- inheritance from BaseIterator | ||
setmetatable(BatchUpsertIterator, {__index = BaseIterator}) | ||
|
||
--- Create new batch upsert iterator for map call | ||
-- | ||
-- @function new | ||
-- | ||
-- @tparam[opt] table opts | ||
-- Options of BatchUpsertIterator:new | ||
-- @tparam[opt] table opts.tuples | ||
-- Tuples to be upserted | ||
-- @tparam[opt] table opts.space | ||
-- Space to be upserted into | ||
-- @tparam[opt] table opts.operations | ||
-- Operations to be performed on tuples | ||
-- @tparam[opt] table opts.execute_on_storage_opts | ||
-- Additional opts for call on storage | ||
-- | ||
-- @return[1] table iterator | ||
-- @treturn[2] nil | ||
-- @treturn[2] table of tables Error description | ||
function BatchUpsertIterator:new(opts) | ||
dev_checks('table', { | ||
tuples = 'table', | ||
space = 'table', | ||
operations = 'table', | ||
execute_on_storage_opts = 'table', | ||
}) | ||
|
||
local sharding_data, err = sharding.split_tuples_by_replicaset(opts.tuples, opts.space, { | ||
operations = opts.operations, | ||
}) | ||
if err ~= nil then | ||
return nil, SplitTuplesError:new("Failed to split tuples by replicaset: %s", err.err) | ||
end | ||
|
||
local next_replicaset, next_batch = next(sharding_data.batches) | ||
|
||
local execute_on_storage_opts = opts.execute_on_storage_opts | ||
execute_on_storage_opts.sharding_func_hash = sharding_data.sharding_func_hash | ||
execute_on_storage_opts.sharding_key_hash = sharding_data.sharding_key_hash | ||
execute_on_storage_opts.skip_sharding_hash_check = sharding_data.skip_sharding_hash_check | ||
|
||
local iter = { | ||
space_name = opts.space.name, | ||
opts = execute_on_storage_opts, | ||
batches_by_replicasets = sharding_data.batches, | ||
next_index = next_replicaset, | ||
next_batch = next_batch, | ||
} | ||
|
||
setmetatable(iter, self) | ||
self.__index = self | ||
|
||
return iter | ||
end | ||
|
||
--- Get function arguments and next replicaset | ||
-- | ||
-- @function get | ||
-- | ||
-- @return[1] table func_args | ||
-- @return[2] table replicaset | ||
function BatchUpsertIterator:get() | ||
local replicaset = self.next_index | ||
local func_args = { | ||
self.space_name, | ||
self.next_batch.tuples, | ||
self.next_batch.operations, | ||
self.opts, | ||
} | ||
|
||
self.next_index, self.next_batch = next(self.batches_by_replicasets, self.next_index) | ||
|
||
return func_args, replicaset | ||
end | ||
|
||
return BatchUpsertIterator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.