1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-24 06:01:25 +03:00
Files
mariadb/mysql-test/suite/rpl/t/rpl_parallel_xa_same_xid.test
Andrei Elkin c8ae357341 MDEV-742 XA PREPAREd transaction survive disconnect/server restart
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!
2020-03-14 22:45:48 +02:00

139 lines
3.1 KiB
Plaintext

# The tests verify concurrent execution of replicated (MDEV-742)
# XA transactions in the parallel optimistic mode.
# Prove optimistic scheduler handles xid-namesake XA:s.
# That is despite running in parallel there must be no conflicts
# caused by multiple transactions' same xid.
--source include/have_binlog_format_mixed_or_row.inc
--source include/have_innodb.inc
--source include/have_perfschema.inc
--source include/master-slave.inc
--let $xid_num = 19
--let $repeat = 17
--let $workers = 7
--connection slave
call mtr.add_suppression("WSREP: handlerton rollback failed");
--source include/stop_slave.inc
# a measure against MDEV-20605
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads;
--disable_query_log
--eval SET @@global.slave_parallel_threads = $workers
--enable_query_log
SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode;
SET @@global.slave_parallel_mode ='optimistic';
--source include/start_slave.inc
--connection master
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
--let $i = $xid_num
--let $t = t1
--disable_query_log
while ($i)
{
--let $k = $repeat
while ($k)
{
--eval XA START 'xid_$i'
--eval INSERT INTO $t SET a=$i, b=$k
--eval XA END 'xid_$i'
--let $one_phase = `SELECT IF(floor(rand()*10)%2, "ONE PHASE", 0)`
if (!$one_phase)
{
--eval XA PREPARE 'xid_$i'
--eval XA COMMIT 'xid_$i'
}
if ($one_phase)
{
--eval XA COMMIT 'xid_$i' ONE PHASE
}
if (!$one_phase)
{
--eval XA START 'xid_$i'
--eval INSERT INTO $t SET a=$i, b=$k
--eval XA END 'xid_$i'
--eval XA PREPARE 'xid_$i'
--eval XA ROLLBACK 'xid_$i'
}
--dec $k
}
--dec $i
}
--enable_query_log
# Above-like test complicates execution env to create
# data conflicts as well. They will be resolved by the optmistic
# scheduler as usual.
CREATE TABLE t2 (a INT AUTO_INCREMENT PRIMARY KEY, b INT) ENGINE=InnoDB;
--let $i = $xid_num
--let $t = t2
--disable_query_log
while ($i)
{
--let $k = $repeat
while ($k)
{
--eval XA START 'xid_$i'
--eval INSERT INTO $t SET a=NULL, b=$k
--eval UPDATE $t SET b=$k + 1 WHERE a=last_insert_id() % $workers
--eval XA END 'xid_$i'
--let $one_phase = `SELECT IF(floor(rand()*10)%2, "ONE PHASE", 0)`
if (!$one_phase)
{
--eval XA PREPARE 'xid_$i'
--eval XA COMMIT 'xid_$i'
}
if ($one_phase)
{
--eval XA COMMIT 'xid_$i' ONE PHASE
}
--eval XA START 'xid_$i'
--eval UPDATE $t SET b=$k + 1 WHERE a=last_insert_id() % $workers
--eval DELETE FROM $t WHERE a=last_insert_id()
--eval XA END 'xid_$i'
--eval XA PREPARE 'xid_$i'
--eval XA ROLLBACK 'xid_$i'
--let $do_drop_create = `SELECT IF(floor(rand()*10)%100, 1, 0)`
if ($do_drop_create)
{
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
}
--dec $k
}
--dec $i
}
--enable_query_log
--source include/sync_slave_sql_with_master.inc
--let $diff_tables= master:t1, slave:t1
--source include/diff_tables.inc
#
# Clean up.
#
--connection slave
--source include/stop_slave.inc
SET GLOBAL slave_parallel_threads=@old_parallel_threads;
SET GLOBAL slave_parallel_mode=@old_parallel_mode;
--source include/start_slave.inc
--connection master
DROP TABLE t1, t2;
--source include/rpl_end.inc