-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
memtx: abort readers of rollbacked prepared
There's case when a transaction is rolled back from prepared state. This happens when WAL fails, synchronized replication confirmation failure or perhaps in other similar cases. By design other RW transactions and transactions with READ_COMMITTED isolation level are allowed to read prepared state. All these transactions must be aborted in case of rollback of prepared transaction since they definitely have read no more possible database state. This patch implements this abortion. Closed #8654 NO_DOC=bugfix (cherry picked from commit 5498690)
- Loading branch information
Showing
3 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelogs/unreleased/gh-8654-mvcc-abort-readers-of-prepared-and-rollbacked.md
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,4 @@ | ||
## bugfix/core | ||
|
||
* Now MVCC engine automatically aborts a transaction if it reads changes | ||
of a prepared transaction and this transaction is aborted (gh-8654). |
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
86 changes: 86 additions & 0 deletions
86
test/engine-luatest/gh_8654_memtx_mvcc_abort_readers_of_prepared_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,86 @@ | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
|
||
local pg = t.group(nil, t.helpers.matrix({engine = {'memtx', 'vinyl'}, | ||
idx = {0, 1}})) | ||
|
||
pg.before_all(function(cg) | ||
cg.server = server:new{ | ||
alias = 'default', | ||
box_cfg = {memtx_use_mvcc_engine = true} | ||
} | ||
cg.server:start() | ||
end) | ||
|
||
pg.after_all(function(cg) | ||
cg.server:drop() | ||
end) | ||
|
||
pg.before_each(function(cg) | ||
cg.server:exec(function(engine) | ||
local s = box.schema.create_space('test', {engine = engine}) | ||
s:create_index('pk') | ||
s:create_index('sk', {parts = {{2, 'uint'}}}) | ||
end, {cg.params.engine}) | ||
end) | ||
|
||
pg.after_each(function(cg) | ||
cg.server:exec(function() | ||
box.space.test:drop() | ||
end) | ||
end) | ||
|
||
-- Check that if transaction with insertion is prepared and then aborted, | ||
-- its readers are aborted too. | ||
pg.test_abort_readers_of_insertion = function(cg) | ||
t.tarantool.skip_if_not_debug() | ||
cg.server:exec(function(idx) | ||
local txn_proxy = require('test.box.lua.txn_proxy') | ||
local fiber = require('fiber') | ||
|
||
local tx1 = txn_proxy.new() | ||
local tx2 = txn_proxy.new() | ||
tx1:begin() | ||
tx2:begin() | ||
tx1('box.space.test:replace{1, 1}') | ||
tx2('box.space.test:replace{2, 2}') | ||
box.error.injection.set('ERRINJ_WAL_WRITE', true) | ||
local fib = fiber.create(tx1.commit, tx1) | ||
fib:set_joinable(true) | ||
-- select by any index must read {1, 1} and lead to the same behavior. | ||
t.assert_equals(tx2('box.space.test.index[' .. idx ..']:select{1}'), | ||
{{{1, 1}}}) | ||
fib:join() | ||
box.error.injection.set('ERRINJ_WAL_WRITE', false) | ||
t.assert_equals(tx2:commit(), | ||
{{error = "Transaction has been aborted by conflict"}}) | ||
end, {cg.params.idx}) | ||
end | ||
|
||
-- Check that if transaction with deletion is prepared and then aborted, | ||
-- its readers are aborted too. | ||
pg.test_abort_readers_of_deletion = function(cg) | ||
t.tarantool.skip_if_not_debug() | ||
cg.server:exec(function(idx) | ||
local txn_proxy = require('test.box.lua.txn_proxy') | ||
local fiber = require('fiber') | ||
|
||
box.space.test:replace{1, 1} | ||
local tx1 = txn_proxy.new() | ||
local tx2 = txn_proxy.new() | ||
tx1:begin() | ||
tx2:begin() | ||
tx1('box.space.test:delete{1}') | ||
tx2('box.space.test:replace{2, 2}') | ||
box.error.injection.set('ERRINJ_WAL_WRITE', true) | ||
local fib = fiber.create(tx1.commit, tx1) | ||
fib:set_joinable(true) | ||
-- select by any index must read {} and lead to the same behavior. | ||
t.assert_equals(tx2('box.space.test.index[' .. idx ..']:select{1}'), | ||
{{}}) | ||
fib:join() | ||
box.error.injection.set('ERRINJ_WAL_WRITE', false) | ||
t.assert_equals(tx2:commit(), | ||
{{error = "Transaction has been aborted by conflict"}}) | ||
end, {cg.params.idx}) | ||
end |