mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-32771 Server crash upon online alter with concurrent XA
In case of a non-recovery XA rollback/commit in the same connection, thon->rollback is called instead of rollback_by_xid, Though previously, thd_ha_data was moved to thd->transaction->xid_state.xid in hton->prepare. Like it wasn't enough, XA PREPARE can be skipped upon user and thus we can end up in hton->commit/rollback with and unprepared XA, so checking xid_state.is_explicit_XA is not enough -- we should check xid_state.get_state_code() == XA_PREPARED, which will also guarantee is_explicit_XA() == true.
This commit is contained in:
@ -1675,6 +1675,116 @@ connect con1, localhost, root,,;
|
||||
connection default;
|
||||
drop table t;
|
||||
set debug_sync= reset;
|
||||
# MDEV-32771 Server crash upon online alter with concurrent XA
|
||||
create table t (a int primary key);
|
||||
insert t values(1),(2),(3);
|
||||
# First, check that nothing from the rollbacked statement commits
|
||||
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for go';
|
||||
alter table t add b int default (555), algorithm=copy;
|
||||
connection con1;
|
||||
set debug_sync= 'now wait_for downgraded';
|
||||
xa start 'xid';
|
||||
update t set a = 0;
|
||||
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
|
||||
xa end 'xid';
|
||||
xa prepare 'xid';
|
||||
xa commit 'xid';
|
||||
set debug_sync= 'now signal go';
|
||||
connection default;
|
||||
select * from t;
|
||||
a b
|
||||
1 555
|
||||
2 555
|
||||
3 555
|
||||
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for go';
|
||||
alter table t add c int default(777), algorithm=copy;
|
||||
connection con1;
|
||||
set debug_sync= 'now wait_for downgraded';
|
||||
xa start 'xid';
|
||||
update t set a = 0;
|
||||
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
|
||||
xa end 'xid';
|
||||
xa prepare 'xid';
|
||||
xa rollback 'xid';
|
||||
set debug_sync= 'now signal go';
|
||||
connection default;
|
||||
select * from t;
|
||||
a b c
|
||||
1 555 777
|
||||
2 555 777
|
||||
3 555 777
|
||||
# Same, but add one successful statement into transaction
|
||||
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for go';
|
||||
alter table t drop b, algorithm=copy;
|
||||
connection con1;
|
||||
set debug_sync= 'now wait_for downgraded';
|
||||
xa start 'xid';
|
||||
update t set a = 10 where a = 1;
|
||||
update t set a = 0;
|
||||
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
|
||||
xa end 'xid';
|
||||
xa prepare 'xid';
|
||||
xa rollback 'xid';
|
||||
set debug_sync= 'now signal go';
|
||||
connection default;
|
||||
select * from t;
|
||||
a c
|
||||
1 777
|
||||
2 777
|
||||
3 777
|
||||
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for go';
|
||||
alter table t drop primary key, algorithm=copy;
|
||||
connection con1;
|
||||
set debug_sync= 'now wait_for downgraded';
|
||||
xa start 'xid';
|
||||
# This statement will take effect.
|
||||
update t set a = 10 where a = 1;
|
||||
update t set a = 0;
|
||||
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
|
||||
xa end 'xid';
|
||||
xa prepare 'xid';
|
||||
xa commit 'xid';
|
||||
set debug_sync= 'now signal go';
|
||||
connection default;
|
||||
select * from t;
|
||||
a c
|
||||
10 777
|
||||
2 777
|
||||
3 777
|
||||
# The only statement succeeds (test both commit and rollback)
|
||||
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for go';
|
||||
alter table t add d text default ('qwe'), algorithm=copy;
|
||||
connection con1;
|
||||
set debug_sync= 'now wait_for downgraded';
|
||||
xa start 'xid';
|
||||
update t set a = 0;
|
||||
xa end 'xid';
|
||||
xa prepare 'xid';
|
||||
xa rollback 'xid';
|
||||
set debug_sync= 'now signal go';
|
||||
connection default;
|
||||
select * from t;
|
||||
a c d
|
||||
10 777 qwe
|
||||
2 777 qwe
|
||||
3 777 qwe
|
||||
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for go';
|
||||
alter table t drop c, algorithm=copy;
|
||||
connection con1;
|
||||
set debug_sync= 'now wait_for downgraded';
|
||||
xa start 'xid';
|
||||
update t set a = 0;
|
||||
xa end 'xid';
|
||||
xa prepare 'xid';
|
||||
xa commit 'xid';
|
||||
set debug_sync= 'now signal go';
|
||||
connection default;
|
||||
select * from t;
|
||||
a d
|
||||
0 qwe
|
||||
0 qwe
|
||||
0 qwe
|
||||
drop table t;
|
||||
set global default_storage_engine= MyISAM;
|
||||
disconnect con1;
|
||||
disconnect con2;
|
||||
|
Reference in New Issue
Block a user