-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linearizable isolation level (#3553)
- Loading branch information
1 parent
901a9e9
commit 6c889b2
Showing
18 changed files
with
468 additions
and
135 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,43 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_space_is_updated = function(cg) | ||
cg.server:exec(function() | ||
-- Insert test data -- | ||
box.space.bands:insert { 1, 'Roxette', 1986 } | ||
box.space.bands:insert { 2, 'Scorpions', 1965 } | ||
box.space.bands:insert { 3, 'Ace of Base', 1987 } | ||
|
||
-- Commit the transaction implicitly -- | ||
box.atomic(function() | ||
box.space.bands:insert { 4, 'The Beatles', 1960 } | ||
box.space.bands:replace { 1, 'Pink Floyd', 1965 } | ||
end) | ||
|
||
t.assert_equals(box.space.bands:count(), 4) | ||
t.assert_equals(box.space.bands:select { 1 }[1], { 1, 'Pink Floyd', 1965 }) | ||
end) | ||
end |
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,43 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_space_is_updated = function(cg) | ||
cg.server:exec(function() | ||
-- Insert test data -- | ||
box.space.bands:insert { 1, 'Roxette', 1986 } | ||
box.space.bands:insert { 2, 'Scorpions', 1965 } | ||
box.space.bands:insert { 3, 'Ace of Base', 1987 } | ||
|
||
-- Commit the transaction -- | ||
box.begin() | ||
box.space.bands:insert { 4, 'The Beatles', 1960 } | ||
box.space.bands:replace { 1, 'Pink Floyd', 1965 } | ||
box.commit() | ||
|
||
t.assert_equals(box.space.bands:count(), 4) | ||
t.assert_equals(box.space.bands:select { 1 }[1], { 1, 'Pink Floyd', 1965 }) | ||
end) | ||
end |
55 changes: 55 additions & 0 deletions
55
doc/code_snippets/test/transactions/box_on_commit_iterator_test.lua
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,55 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_space_is_updated = function(cg) | ||
cg.server:exec(function() | ||
-- Insert test data -- | ||
box.space.bands:insert { 1, 'Roxette', 1986 } | ||
box.space.bands:insert { 2, 'Scorpions', 1965 } | ||
box.space.bands:insert { 3, 'Ace of Base', 1987 } | ||
|
||
-- Define a function called on commit -- | ||
function print_replace_details(iterator) | ||
for request_number, old_tuple, new_tuple, space_id in iterator() do | ||
print('request_number: ' .. tostring(request_number)) | ||
print('old_tuple: ' .. tostring(old_tuple)) | ||
print('new_tuple: ' .. tostring(new_tuple)) | ||
print('space_id: ' .. tostring(space_id)) | ||
end | ||
end | ||
|
||
-- Commit the transaction -- | ||
box.begin() | ||
box.space.bands:replace { 1, 'The Beatles', 1960 } | ||
box.space.bands:replace { 2, 'The Rolling Stones', 1965 } | ||
box.on_commit(print_replace_details) | ||
box.commit() | ||
|
||
t.assert_equals(box.space.bands:count(), 3) | ||
t.assert_equals(box.space.bands:select { 1 }[1], { 1, 'The Beatles', 1960 }) | ||
t.assert_equals(box.space.bands:select { 2 }[1], { 2, 'The Rolling Stones', 1965 }) | ||
end) | ||
end |
47 changes: 47 additions & 0 deletions
47
doc/code_snippets/test/transactions/box_on_commit_test.lua
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,47 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_space_is_updated = function(cg) | ||
cg.server:exec(function() | ||
-- Insert test data -- | ||
box.space.bands:insert { 1, 'Roxette', 1986 } | ||
box.space.bands:insert { 2, 'Scorpions', 1965 } | ||
box.space.bands:insert { 3, 'Ace of Base', 1987 } | ||
|
||
-- Define a function called on commit -- | ||
function print_commit_result() | ||
print('Commit happened') | ||
end | ||
|
||
-- Commit the transaction -- | ||
box.begin() | ||
box.space.bands:insert { 4, 'The Beatles', 1960 } | ||
box.on_commit(print_commit_result) | ||
box.commit() | ||
|
||
t.assert_equals(box.space.bands:count(), 4) | ||
end) | ||
end |
45 changes: 45 additions & 0 deletions
45
doc/code_snippets/test/transactions/box_rollback_savepoint_test.lua
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,45 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_space_is_updated_partially = function(cg) | ||
cg.server:exec(function() | ||
-- Insert test data -- | ||
box.space.bands:insert { 1, 'Roxette', 1986 } | ||
box.space.bands:insert { 2, 'Scorpions', 1965 } | ||
box.space.bands:insert { 3, 'Ace of Base', 1987 } | ||
|
||
-- Rollback the transaction to a savepoint -- | ||
box.begin() | ||
box.space.bands:insert { 4, 'The Beatles', 1960 } | ||
save1 = box.savepoint() | ||
box.space.bands:replace { 1, 'Pink Floyd', 1965 } | ||
box.rollback_to_savepoint(save1) | ||
box.commit() | ||
|
||
t.assert_equals(box.space.bands:count(), 4) | ||
t.assert_equals(box.space.bands:select { 1 }[1], { 1, 'Roxette', 1986 }) | ||
end) | ||
end |
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,43 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_space_is_not_updated = function(cg) | ||
cg.server:exec(function() | ||
-- Insert test data -- | ||
box.space.bands:insert { 1, 'Roxette', 1986 } | ||
box.space.bands:insert { 2, 'Scorpions', 1965 } | ||
box.space.bands:insert { 3, 'Ace of Base', 1987 } | ||
|
||
-- Rollback the transaction -- | ||
box.begin() | ||
box.space.bands:insert { 4, 'The Beatles', 1960 } | ||
box.space.bands:replace { 1, 'Pink Floyd', 1965 } | ||
box.rollback() | ||
|
||
t.assert_equals(box.space.bands:count(), 3) | ||
t.assert_equals(box.space.bands:select { 1 }[1], { 1, 'Roxette', 1986 }) | ||
end) | ||
end |
Oops, something went wrong.