mirror of
https://github.com/MariaDB/server.git
synced 2025-04-22 15:15:41 +02:00

Lifted long standing limitation to the XA of rolling it back at the transaction's connection close even if the XA is prepared. Prepared XA-transaction is made to sustain connection close or server restart. The patch consists of - binary logging extension to write prepared XA part of transaction signified with its XID in a new XA_prepare_log_event. The concusion part - with Commit or Rollback decision - is logged separately as Query_log_event. That is in the binlog the XA consists of two separate group of events. That makes the whole XA possibly interweaving in binlog with other XA:s or regular transaction but with no harm to replication and data consistency. Gtid_log_event receives two more flags to identify which of the two XA phases of the transaction it represents. With either flag set also XID info is added to the event. When binlog is ON on the server XID::formatID is constrained to 4 bytes. - engines are made aware of the server policy to keep up user prepared XA:s so they (Innodb, rocksdb) don't roll them back anymore at their disconnect methods. - slave applier is refined to cope with two phase logged XA:s including parallel modes of execution. This patch does not address crash-safe logging of the new events which is being addressed by MDEV-21469. CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc Are addressed along the following policies. 1. The read-only at reconnect marks XID to fail for future completion with ER_XA_RBROLLBACK. 2. binlog-* filtered XA when it changes engine data is regarded as loggable even when nothing got cached for binlog. An empty XA-prepare group is recorded. Consequent Commit-or-Rollback succeeds in the Engine(s) as well as recorded into binlog. 3. The same applies to the non-transactional engine XA. 4. @@skip_log_bin=OFF does not record anything at XA-prepare (obviously), but the completion event is recorded into binlog to admit inconsistency with slave. The following actions are taken by the patch. At XA-prepare: when empty binlog cache - don't do anything to binlog if RO, otherwise write empty XA_prepare (assert(binlog-filter case)). At Disconnect: when Prepared && RO (=> no binlogging was done) set Xid_cache_element::error := ER_XA_RBROLLBACK *keep* XID in the cache, and rollback the transaction. At XA-"complete": Discover the error, if any don't binlog the "complete", return the error to the user. Kudos ----- Alexey Botchkov took to drive this work initially. Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of good recommendations. Sergei Voitovich made a magnificent review and improvements to the code. They all deserve a bunch of thanks for making this work done!
69 lines
2.2 KiB
Text
69 lines
2.2 KiB
Text
select * from information_schema.engines where engine='tokudb';
|
|
ENGINE TokuDB
|
|
SUPPORT YES
|
|
COMMENT Percona TokuDB Storage Engine with Fractal Tree(tm) Technology
|
|
TRANSACTIONS YES
|
|
XA YES
|
|
SAVEPOINTS YES
|
|
create table t1 (a int) engine=tokudb;
|
|
xa start 'test1';
|
|
insert t1 values (10);
|
|
xa end 'test1';
|
|
xa prepare 'test1';
|
|
xa rollback 'test1';
|
|
select * from t1;
|
|
a
|
|
xa start 'test2';
|
|
xa start 'test-bad';
|
|
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state
|
|
insert t1 values (20);
|
|
xa prepare 'test2';
|
|
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state
|
|
xa end 'test2';
|
|
xa prepare 'test2';
|
|
xa commit 'test2';
|
|
select * from t1;
|
|
a
|
|
20
|
|
xa start 'testa','testb';
|
|
insert t1 values (30);
|
|
commit;
|
|
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state
|
|
xa end 'testa','testb';
|
|
begin;
|
|
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state
|
|
create table t2 (a int);
|
|
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state
|
|
connect con1,localhost,root,,;
|
|
connection con1;
|
|
xa start 'testa','testb';
|
|
ERROR XAE08: XAER_DUPID: The XID already exists
|
|
xa start 'testa','testb', 123;
|
|
ERROR XAE08: XAER_DUPID: The XID already exists
|
|
xa start 0x7465737462, 0x2030405060, 0xb;
|
|
insert t1 values (40);
|
|
xa end 'testb',' 0@P`',11;
|
|
xa prepare 'testb',0x2030405060,11;
|
|
start transaction;
|
|
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
|
|
xa recover;
|
|
formatID gtrid_length bqual_length data
|
|
11 5 5 testb 0@P`
|
|
connection default;
|
|
xa prepare 'testa','testb';
|
|
xa recover;
|
|
formatID gtrid_length bqual_length data
|
|
11 5 5 testb 0@P`
|
|
1 5 5 testatestb
|
|
xa commit 'testb',0x2030405060,11;
|
|
ERROR XAE04: XAER_NOTA: Unknown XID
|
|
xa rollback 'testa','testb';
|
|
xa start 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
|
|
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
|
|
select * from t1;
|
|
a
|
|
20
|
|
disconnect con1;
|
|
connection default;
|
|
xa rollback 'testb',0x2030405060,11;
|
|
drop table t1;
|