Skip to content

Commit

Permalink
Linearizable isolation level (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyaksenov authored Jul 6, 2023
1 parent 901a9e9 commit 6c889b2
Show file tree
Hide file tree
Showing 18 changed files with 468 additions and 135 deletions.
43 changes: 43 additions & 0 deletions doc/code_snippets/test/transactions/box_atomic_test.lua
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
43 changes: 43 additions & 0 deletions doc/code_snippets/test/transactions/box_commit_test.lua
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
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 doc/code_snippets/test/transactions/box_on_commit_test.lua
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
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
43 changes: 43 additions & 0 deletions doc/code_snippets/test/transactions/box_rollback_test.lua
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
Loading

0 comments on commit 6c889b2

Please sign in to comment.