mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
c8ae357341
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!
102 lines
3.4 KiB
PHP
102 lines
3.4 KiB
PHP
--source include/have_innodb.inc
|
|
--source include/have_perfschema.inc
|
|
#
|
|
# The test verifies binlogging of XA transaction and state of prepared XA
|
|
# as far as binlog is concerned.
|
|
#
|
|
# The prepared XA transactions can be disconnected from the client,
|
|
# discovered from another connection and commited or rolled back
|
|
# later. They also survive the server restart. The test runs two
|
|
# loops each consisting of prepared XA:s generation, their
|
|
# manipulation and a server restart followed with survived XA:s
|
|
# completion.
|
|
#
|
|
# Prepared XA can't get available to an external connection
|
|
# until connection that either leaves actively or is killed
|
|
# has completed a necessary part of its cleanup.
|
|
# Selecting from P_S.threads provides a method to learn that.
|
|
#
|
|
# Total number of connection each performing one insert into table
|
|
--let $conn_number=20
|
|
# Number of rollbacks and commits from either side of the server restart
|
|
--let $rollback_number=5
|
|
--let $commit_number=5
|
|
# Number of transactions that are terminated before server restarts
|
|
--let $term_number=`SELECT $rollback_number + $commit_number`
|
|
# Instead of disconnect make some connections killed when their
|
|
# transactions got prepared.
|
|
--let $killed_number=5
|
|
# make some connections disconnected by shutdown rather than actively
|
|
--let $server_disconn_number=5
|
|
--let $prepared_at_server_restart = `SELECT $conn_number - $term_number`
|
|
# number a "warmup" connection after server restart, they all commit
|
|
--let $post_restart_conn_number=10
|
|
|
|
# Counter to be used in GTID consistency check.
|
|
# It's incremented per each non-XA transaction commit.
|
|
# Local to this file variable to control one-phase commit loop
|
|
--let $one_phase_number = 5
|
|
|
|
--connection default
|
|
|
|
# Remove possibly preceeding binlogs and clear initialization time
|
|
# GTID executed info. In the following all transactions are counted
|
|
# to conduct verification at the end of the test.
|
|
if (`SELECT @@global.log_bin`)
|
|
{
|
|
RESET MASTER;
|
|
}
|
|
|
|
# Disconected and follower threads need synchronization
|
|
CREATE VIEW v_processlist as SELECT * FROM performance_schema.threads where type = 'FOREGROUND';
|
|
|
|
--eval call mtr.add_suppression("Found $prepared_at_server_restart prepared XA transactions")
|
|
|
|
CREATE TABLE t (a INT) ENGINE=innodb;
|
|
|
|
# Counter is incremented at the end of post restart to
|
|
# reflect number of loops done in correctness computation.
|
|
--let $restart_number = 0
|
|
--let $how_to_restart=restart_mysqld.inc
|
|
--source suite/binlog/include/binlog_xa_prepared_do_and_restart.inc
|
|
|
|
--let $how_to_restart=kill_and_restart_mysqld.inc
|
|
--source suite/binlog/include/binlog_xa_prepared_do_and_restart.inc
|
|
|
|
--connection default
|
|
|
|
# Few xs that commit in one phase, not subject to the server restart
|
|
# nor reconnect.
|
|
# This piece of test is related to mysqlbinlog recovery examine below.
|
|
--let $k = 0
|
|
while ($k < $one_phase_number)
|
|
{
|
|
--eval XA START 'one_phase_trx_$k'
|
|
--eval INSERT INTO t SET a=$k
|
|
--eval XA END 'one_phase_trx_$k'
|
|
--eval XA COMMIT 'one_phase_trx_$k' ONE PHASE
|
|
|
|
--inc $k
|
|
}
|
|
|
|
SELECT SUM(a) FROM t;
|
|
DROP TABLE t;
|
|
DROP VIEW v_processlist;
|
|
|
|
let $outfile= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql;
|
|
if (`SELECT @@global.log_bin`)
|
|
{
|
|
# Recording proper samples of binlogged prepared XA:s
|
|
--source include/show_binlog_events.inc
|
|
--exec $MYSQL_BINLOG -R --to-last-log master-bin.000001 > $outfile
|
|
}
|
|
|
|
--echo All transactions must be completed, to empty-list the following:
|
|
XA RECOVER;
|
|
|
|
if (`SELECT @@global.log_bin`)
|
|
{
|
|
--exec $MYSQL test < $outfile
|
|
--remove_file $outfile
|
|
XA RECOVER;
|
|
}
|