-
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 insert is mostly used for operation with one bucket / one Tarantool node in a transaction. In this case batch insert is more efficient then inserting tuple-by-tuple. Right now CRUD cannot provide batch insert with full consistency. CRUD offers batch insert with partial consistency. That means that full consistency can be provided only on single replicaset using `box` transactions. Part of #193
- Loading branch information
Showing
17 changed files
with
3,141 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local errors = require('errors') | ||
local dev_checks = require('crud.common.dev_checks') | ||
local sharding_utils = require('crud.common.sharding.utils') | ||
|
||
local NotPerformedError = errors.new_class('NotPerformedError', {capture_stack = false}) | ||
|
||
local batching_utils = {} | ||
|
||
batching_utils.stop_on_error_msg = "Operation with tuple was not performed" | ||
batching_utils.rollback_on_error_msg = "Operation with tuple was rollback" | ||
|
||
function batching_utils.construct_sharding_hash_mismatch_errors(err_msg, tuples) | ||
dev_checks('string', 'table') | ||
|
||
local errs = {} | ||
|
||
for _, tuple in ipairs(tuples) do | ||
local err_obj = sharding_utils.ShardingHashMismatchError:new(err_msg) | ||
err_obj.operation_data = tuple | ||
table.insert(errs, err_obj) | ||
end | ||
|
||
return errs | ||
end | ||
|
||
function batching_utils.complement_batching_errors(errs, err_msg, tuples) | ||
dev_checks('table', 'string', 'table') | ||
|
||
for _, tuple in ipairs(tuples) do | ||
local err_obj = NotPerformedError:new(err_msg) | ||
err_obj.operation_data = tuple | ||
table.insert(errs, err_obj) | ||
end | ||
|
||
return errs | ||
end | ||
|
||
return batching_utils |
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,76 @@ | ||
local errors = require('errors') | ||
local vshard = require('vshard') | ||
|
||
local dev_checks = require('crud.common.dev_checks') | ||
local GetReplicasetsError = errors.new_class('GetReplicasetsError') | ||
|
||
local BaseIterator = {} | ||
|
||
--- Create new base iterator for map call | ||
-- | ||
-- @function new | ||
-- | ||
-- @tparam[opt] table opts | ||
-- Options of BaseIterator:new | ||
-- @tparam[opt] table opts.func_args | ||
-- Function arguments to call | ||
-- @tparam[opt] table opts.replicasets | ||
-- Replicasets to call | ||
-- | ||
-- @return[1] table iterator | ||
-- @treturn[2] nil | ||
-- @treturn[2] table of tables Error description | ||
function BaseIterator:new(opts) | ||
dev_checks('table', { | ||
func_args = '?table', | ||
replicasets = '?table', | ||
}) | ||
|
||
local replicasets, err | ||
if opts.replicasets ~= nil then | ||
replicasets = opts.replicasets | ||
else | ||
replicasets, err = vshard.router.routeall() | ||
if replicasets == nil then | ||
return nil, GetReplicasetsError:new("Failed to get all replicasets: %s", err.err) | ||
end | ||
end | ||
|
||
local next_index, next_replicaset = next(replicasets) | ||
|
||
local iter = { | ||
func_args = opts.func_args, | ||
replicasets = replicasets, | ||
next_replicaset = next_replicaset, | ||
next_index = next_index | ||
} | ||
|
||
setmetatable(iter, self) | ||
self.__index = self | ||
|
||
return iter | ||
end | ||
|
||
--- Check there is next replicaset to call | ||
-- | ||
-- @function has_next | ||
-- | ||
-- @return[1] boolean | ||
function BaseIterator:has_next() | ||
return self.next_index ~= nil | ||
end | ||
|
||
--- Get function arguments and next replicaset | ||
-- | ||
-- @function get | ||
-- | ||
-- @return[1] table func_args | ||
-- @return[2] table replicaset | ||
function BaseIterator:get() | ||
local replicaset = self.next_replicaset | ||
self.next_index, self.next_replicaset = next(self.replicasets, self.next_index) | ||
|
||
return self.func_args, replicaset | ||
end | ||
|
||
return BaseIterator |
Oops, something went wrong.