forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the new `is_sync` parameter to `box.begin()`, `box.commit()`, and `box.atomic()`. To make the transaction synchronous, set the `is_sync` option to `true`. `box.commit()` can't change `is_sync` to `false` if the transaction was opened as synchronous or has writes to synchronous spaces. By default, `is_sync = false`. Examples: ```Lua -- Sync transactions box.atomic({is_sync = true}, function() ... end) box.begin({is_sync = true}) ... box.commit({is_sync = false}) box.begin({is_sync = false}) ... box.commit({is_sync = true}) box.begin({is_sync = true}) ... box.commit({is_sync = true}) -- Async transactions box.atomic({is_sync = false}, function() ... end) box.begin({is_sync = false}) ... box.commit({is_sync = false}) box.begin() ... box.commit() ``` Closes tarantool#8650 NO_DOC=internal
- Loading branch information
1 parent
bb74d6c
commit d8a981b
Showing
7 changed files
with
236 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## feature/box | ||
|
||
* Added the new `is_sync` parameter to `box.begin()`, `box.commit()`, and | ||
`box.atomic()`. To make the transaction synchronous, set the `is_sync` | ||
option to `true`. `box.commit()` can't change `is_sync` to `false` if | ||
the transaction was opened as synchronous or has writes to synchronous | ||
spaces (gh-8650). |
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
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,155 @@ | ||
local t = require('luatest') | ||
local cluster = require('luatest.replica_set') | ||
local server = require('luatest.server') | ||
|
||
local g = t.group('gh_8650') | ||
|
||
g.before_each(function(cg) | ||
cg.cluster = cluster:new({}) | ||
|
||
local box_cfg = { | ||
replication = { | ||
server.build_listen_uri('master', cg.cluster.id) | ||
}, | ||
replication_synchro_timeout = 0.2, | ||
replication_synchro_quorum = 2 | ||
} | ||
cg.master = cg.cluster:build_server({alias = 'master', | ||
box_cfg = box_cfg}) | ||
local box_cfg = { | ||
replication = { | ||
cg.master.net_box_uri, | ||
server.build_listen_uri('replica', cg.cluster.id) | ||
}, | ||
replication_synchro_timeout = 0.2, | ||
replication_synchro_quorum = 2, | ||
read_only = true | ||
} | ||
cg.replica = cg.cluster:build_server({alias = 'replica', | ||
box_cfg = box_cfg}) | ||
|
||
cg.cluster:add_server(cg.master) | ||
cg.cluster:add_server(cg.replica) | ||
cg.cluster:start() | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.cluster:drop() | ||
end) | ||
|
||
g.test_box_begin_commit_is_sync = function(cg) | ||
cg.master:exec(function() | ||
box.schema.space.create('test') | ||
box.space.test:create_index('pk') | ||
box.ctl.promote() | ||
|
||
box.begin({is_sync = false}) | ||
box.space.test:insert{1, 'is_sync = true'} | ||
box.commit({is_sync = true}) | ||
box.begin({is_sync = false}) | ||
box.space.test:insert{2, 'is_sync = false'} | ||
box.commit({is_sync = false}) | ||
box.begin({is_sync = true}) | ||
box.space.test:insert{3, 'is_sync = true'} | ||
box.commit({is_sync = true}) | ||
box.begin({is_sync = true}) | ||
box.space.test:insert{4, 'is_sync = true'} | ||
box.commit({is_sync = false}) | ||
end) | ||
|
||
t.assert_equals(cg.master:exec(function() | ||
return box.space.test:select() | ||
end), {{1, 'is_sync = true'}, {2, 'is_sync = false'}, | ||
{3, 'is_sync = true'}, {4, 'is_sync = true'}}) | ||
|
||
t.assert_equals(cg.replica:exec(function() | ||
return box.space.test:select() | ||
end), {{1, 'is_sync = true'}, {2, 'is_sync = false'}, | ||
{3, 'is_sync = true'}, {4, 'is_sync = true'}}) | ||
|
||
cg.replica:stop() | ||
|
||
-- Async transaction | ||
cg.master:exec(function() | ||
box.begin({is_sync = false}) | ||
box.space.test:insert{5, 'is_sync = false'} | ||
box.commit({is_sync = false}) | ||
end) | ||
|
||
-- Sync transaction | ||
t.assert_error_msg_content_equals('Quorum collection for a synchronous ' .. | ||
'transaction is timed out', | ||
function() | ||
cg.master:exec(function() | ||
box.begin({is_sync = true}) | ||
box.space.test:insert{6, 'is_sync = true'} | ||
box.commit({is_sync = false}) | ||
end) | ||
end) | ||
|
||
t.assert_equals(cg.master:exec(function() | ||
return box.space.test:select() | ||
end), {{1, 'is_sync = true'}, {2, 'is_sync = false'}, | ||
{3, 'is_sync = true'}, {4, 'is_sync = true'}, | ||
{5, "is_sync = false"}}) | ||
end | ||
|
||
g.test_box_atomic_is_sync = function(cg) | ||
cg.master:exec(function() | ||
box.schema.space.create('test') | ||
box.space.test:create_index('pk') | ||
box.ctl.promote() | ||
|
||
box.atomic(function() | ||
box.space.test:insert{1, 'is_sync = false'} | ||
box.space.test:insert{2, 'is_sync = false'} | ||
end) | ||
box.atomic({is_sync = true}, function() | ||
box.space.test:insert{3, 'is_sync = true'} | ||
box.space.test:insert{4, 'is_sync = true'} | ||
end) | ||
box.atomic({is_sync = false}, function() | ||
box.space.test:insert{5, 'is_sync = false'} | ||
box.space.test:insert{6, 'is_sync = false'} | ||
end) | ||
end) | ||
|
||
t.assert_equals(cg.master:exec(function() | ||
return box.space.test:select() | ||
end), {{1, 'is_sync = false'}, {2, 'is_sync = false'}, | ||
{3, 'is_sync = true'}, {4, 'is_sync = true'}, | ||
{5, 'is_sync = false'}, {6, 'is_sync = false'}}) | ||
|
||
t.assert_equals(cg.replica:exec(function() | ||
return box.space.test:select() | ||
end), {{1, 'is_sync = false'}, {2, 'is_sync = false'}, | ||
{3, 'is_sync = true'}, {4, 'is_sync = true'}, | ||
{5, 'is_sync = false'}, {6, 'is_sync = false'}}) | ||
|
||
cg.replica:stop() | ||
|
||
-- Async transaction | ||
cg.master:exec(function() | ||
box.atomic({is_sync = false}, function() | ||
box.space.test:insert{7, 'is_sync = false'} | ||
end) | ||
end) | ||
|
||
-- Sync transaction | ||
t.assert_error_msg_content_equals('Quorum collection for a synchronous ' .. | ||
'transaction is timed out', | ||
function() | ||
cg.master:exec(function() | ||
box.atomic({is_sync = true}, function() | ||
box.space.test:insert{8, 'is_sync = true'} | ||
end) | ||
end) | ||
end) | ||
|
||
t.assert_equals(cg.master:exec(function() | ||
return box.space.test:select() | ||
end), {{1, 'is_sync = false'}, {2, 'is_sync = false'}, | ||
{3, 'is_sync = true'}, {4, 'is_sync = true'}, | ||
{5, "is_sync = false"}, {6, 'is_sync = false'}, | ||
{7, 'is_sync = false'}}) | ||
end |