mariadb/mysql-test/suite/binlog_in_engine/xa.result
Kristian Nielsen 7081f2a58e Binlog-in-engine: New binlog implementation integrated in InnoDB
Implement an improved binlog implementation that is integrated into
the storage engine. The new implementation is enabled with the
--binlog-storage-engine option. Initially the InnoDB storage engine
implements the binlog.

Integrating the binlog in the storage engine improves performance,
since it makes the InnoDB redo log the single source of truth and
avoids the need for expensive two-phase commit between binlog and
engine. It also makes it possible to disable durability (set
--innodb-flush-log-at-trx-commit=0) to further improve performance,
while still preserving the ability to recover the binlog and database
into a consistent state after a crash.

The new binlog implementation also greatly improves the internal
design and implementation of the binlog, and enables future
enhancements for replication.

This is a squash of the original 11.4-based patch series.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2026-01-23 03:21:03 +01:00

262 lines
7.9 KiB
Text

include/reset_master.inc
CREATE TABLE t1(a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
*** Test basic XA COMMIT from same or different client connection.
connect con1,localhost,root,,;
XA START 'a';
INSERT INTO t1 VALUES (1, 0);
INSERT INTO t1 VALUES (2, 0);
INSERT INTO t1 VALUES (3, 0);
XA END 'a';
XA PREPARE 'a';
connection default;
disconnect con1;
RESET MASTER;
ERROR HY000: Cannot execute RESET MASTER as the binlog is in use by an active transaction
connect con2,localhost,root,,;
XA COMMIT 'a';
connect con1_roll,localhost,root,,;
XA START 'a_roll';
INSERT INTO t1 VALUES (1001, 0);
INSERT INTO t1 VALUES (1002, 0);
INSERT INTO t1 VALUES (1003, 0);
XA END 'a_roll';
XA PREPARE 'a_roll';
connection default;
disconnect con1_roll;
connection con2;
XA ROLLBACK 'a_roll';
connection default;
XA START 'b';
UPDATE t1 SET b=2 WHERE a=1;
XA END 'b';
XA PREPARE 'b';
XA COMMIT 'b';
XA START 'b_roll';
UPDATE t1 SET b=3 WHERE a=1;
XA END 'b_roll';
XA PREPARE 'b_roll';
XA ROLLBACK 'b_roll';
XA START 'c';
UPDATE t1 SET b=3 WHERE a=3;
XA END 'c';
XA COMMIT 'c' ONE PHASE;
SELECT * FROM t1 ORDER BY a;
a b
1 2
2 0
3 3
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
CREATE TABLE t3 (id INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1),(2);
INSERT INTO t3 VALUES (1),(2);
XA START '1';
REPLACE INTO t2 SELECT * FROM t2;
REPLACE INTO t3 SELECT * FROM t3;
XA END '1';
XA PREPARE '1';
XA RECOVER FORMAT='SQL';
formatID gtrid_length bqual_length data
1 1 0 '1'
XA ROLLBACK '1';
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
DROP TABLE t2, t3;
CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1);
CREATE SEQUENCE s ENGINE=InnoDB;
XA START '2';
SELECT NEXT VALUE FOR s;
NEXT VALUE FOR s
1
REPLACE INTO t2 SELECT * FROM t2;
XA END '2';
XA PREPARE '2';
XA RECOVER FORMAT='SQL';
formatID gtrid_length bqual_length data
1 1 0 '2'
XA ROLLBACK '2';
DROP SEQUENCE s;
DROP TABLE t2;
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Query # # use `test`; INSERT INTO t1 VALUES (1, 0)
binlog-000000.ibb # Query # # use `test`; INSERT INTO t1 VALUES (2, 0)
binlog-000000.ibb # Query # # use `test`; INSERT INTO t1 VALUES (3, 0)
binlog-000000.ibb # Query # # COMMIT
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Query # # use `test`; UPDATE t1 SET b=2 WHERE a=1
binlog-000000.ibb # Query # # COMMIT
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Query # # use `test`; UPDATE t1 SET b=3 WHERE a=3
binlog-000000.ibb # Xid # # COMMIT /* XID */
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; CREATE TABLE t2 (a INT) ENGINE=MyISAM
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; CREATE TABLE t3 (id INT PRIMARY KEY) ENGINE=InnoDB
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Query # # use `test`; INSERT INTO t2 VALUES (1),(2)
binlog-000000.ibb # Query # # COMMIT
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Query # # use `test`; INSERT INTO t3 VALUES (1),(2)
binlog-000000.ibb # Xid # # COMMIT /* XID */
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Annotate_rows # # REPLACE INTO t2 SELECT * FROM t2
binlog-000000.ibb # Table_map # # table_id: # (test.t2)
binlog-000000.ibb # Write_rows_v1 # # table_id: # flags: STMT_END_F
binlog-000000.ibb # Query # # COMMIT
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; DROP TABLE `t2`,`t3` /* generated by server */
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Query # # use `test`; INSERT INTO t2 VALUES (1)
binlog-000000.ibb # Xid # # COMMIT /* XID */
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; CREATE SEQUENCE s ENGINE=InnoDB
binlog-000000.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000000.ibb # Annotate_rows # # SELECT NEXT VALUE FOR s
binlog-000000.ibb # Table_map # # table_id: # (test.s)
binlog-000000.ibb # Write_rows_v1 # # table_id: # flags: STMT_END_F
binlog-000000.ibb # Query # # COMMIT
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; DROP SEQUENCE `s` /* generated by server */
binlog-000000.ibb # Gtid # # GTID #-#-#
binlog-000000.ibb # Query # # use `test`; DROP TABLE `t2` /* generated by server */
*** Test that we will not purge a file that is needed by an active XA transaction.
connection default;
ALTER TABLE t1 ADD COLUMN c LONGBLOB;
UPDATE t1 SET b=10 WHERE a=1;
connection con2;
SET SESSION binlog_format=ROW;
XA START 'd';
INSERT INTO t1 VALUES (10, 2, REPEAT('#', 40000));
connect con3,localhost,root,,;
SET SESSION binlog_format=ROW;
XA START 'e';
INSERT INTO t1 VALUES (110, 2, REPEAT('#', 40000));
connection default;
UPDATE t1 SET b=11 WHERE a=1;
FLUSH BINARY LOGS;
UPDATE t1 SET b=12 WHERE a=1;
connection con2;
INSERT INTO t1 VALUES (11, 2, REPEAT('*', 40000));
connection con3;
INSERT INTO t1 VALUES (111, 2, REPEAT('*', 40000));
connection default;
UPDATE t1 SET b=13 WHERE a=1;
FLUSH BINARY LOGS;
UPDATE t1 SET b=14 WHERE a=1;
UPDATE t1 SET b=15 WHERE a=1;
FLUSH BINARY LOGS;
UPDATE t1 SET b=16 WHERE a=1;
FLUSH BINARY LOGS;
connection default;
SET @old_min_slaves= @@GLOBAL.slave_connections_needed_for_purge;
SET GLOBAL slave_connections_needed_for_purge= 0;
PURGE BINARY LOGS TO 'binlog-000001.ibb';
ERROR HY000: A purgeable log is in use, will not purge
connection con2;
XA END 'd';
XA PREPARE 'd';
connection con3;
XA END 'e';
XA PREPARE 'e';
connection default;
PURGE BINARY LOGS TO 'binlog-000001.ibb';
ERROR HY000: A purgeable log is in use, will not purge
connection con2;
XA COMMIT 'd';
connection con3;
XA ROLLBACK 'e';
connection default;
PURGE BINARY LOGS TO 'binlog-000001.ibb';
FLUSH BINARY LOGS;
UPDATE t1 SET b=17 WHERE a=1;
FLUSH BINARY LOGS;
UPDATE t1 SET b=18 WHERE a=1;
PURGE BINARY LOGS TO 'binlog-000001.ibb';
SET GLOBAL slave_connections_needed_for_purge= @old_min_slaves;
*** Test disconnecting in XA transaction before XA PREPARE.
connection con2;
SET SESSION binlog_format=MIXED;
XA BEGIN 'f';
CREATE TEMPORARY TABLE tmp ENGINE=InnoDB AS SELECT a FROM t1;
disconnect con2;
connection con3;
SET SESSION binlog_format=MIXED;
XA BEGIN 'g';
UPDATE t1 SET b=19 WHERE a=1;
XA END 'g';
disconnect con3;
connection default;
BEGIN;
SELECT b FROM t1 WHERE a=1 FOR UPDATE;
b
18
ROLLBACK;
*** Test duplicate SAVEPOINT with XA
XA BEGIN 'x';
DELETE FROM t1;
SAVEPOINT A;
SAVEPOINT B;
SAVEPOINT A;
ROLLBACK TO SAVEPOINT B;
XA END 'x';
XA ROLLBACK 'x';
*** Test server shutdown after XA PREPARE.
XA BEGIN 'y';
INSERT INTO t1 VALUES (201, 0, '');
XA END 'y';
XA PREPARE 'y';
# restart
XA ROLLBACK 'y';
*** Test binlogging of empty XA transaction.
SET binlog_format=row;
DELETE FROM t1 WHERE a=4242;
INSERT INTO t1 VALUES (4242, 0, 'z1');
XA BEGIN 'z';
SELECT a, b, LENGTH(c) FROM t1 ORDER BY a LIMIT 3;
a b LENGTH(c)
1 18 NULL
2 0 NULL
3 3 NULL
INSERT IGNORE INTO t1 VALUES (4242, 0, 'z2');
Warnings:
Warning 1062 Duplicate entry '4242' for key 'PRIMARY'
SELECT a, b, LENGTH(c) FROM t1 WHERE a>3 ORDER BY a LIMIT 1;
a b LENGTH(c)
10 2 40000
XA END 'z';
XA PREPARE 'z';
XA COMMIT 'z';
XA BEGIN 'z';
UPDATE t1 SET b=10 WHERE a=4242;
XA END 'z';
XA PREPARE 'z';
XA COMMIT 'z';
SELECT a, b, LENGTH(c) FROM t1 WHERE a=4242;
a b LENGTH(c)
4242 10 2
*** Test XA PREPARE when the transaction is empty because statements rolled back on error
CREATE TRIGGER u AFTER INSERT ON t1 FOR EACH ROW BEGIN RELEASE SAVEPOINT A ; END //
XA BEGIN 'xid44';
INSERT IGNORE INTO t1(a) VALUES (10000);
ERROR 42000: SAVEPOINT A does not exist
XA END 'xid44';
XA PREPARE 'xid44';
XA COMMIT 'xid44';
DROP TRIGGER u;
XA BEGIN 'xid44';
SAVEPOINT A;
ROLLBACK TO A;
ROLLBACK TO A;
INSERT INTO t1(a) VALUES (10001);
XA END 'xid44';
XA PREPARE 'xid44';
# restart
XA COMMIT 'xid44';
SELECT * FROM t1 WHERE a >= 10000 ORDER BY a;
a b c
10001 NULL NULL
DROP TABLE t1;