1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-34705: Binlog-in-engine: Integration with server-layer code

Mostly various fixes to avoid initializing or creating any data or files for
the legacy binlog.

A possible later refinement could be to sub-class the binlog class
differently for legacy and in-engine binlogs, writing separate virtual
functions for behaviour that differ, extracting common functionality into
sub-methods. This could remove some if (opt_binlog_engine_hton)
conditionals.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
Kristian Nielsen
2025-04-10 14:54:37 +02:00
parent 0327708ed6
commit d496e5278d
19 changed files with 595 additions and 165 deletions

View File

@@ -0,0 +1,54 @@
RESET MASTER;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 0);
connect con1,localhost,root,,;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connect con2,localhost,root,,;
*** Connection sees current position by default.
connection default;
INSERT INTO t1 VALUES (2, 0);
FLUSH BINARY LOGS;
INSERT INTO t1 VALUES (3, 0);
INSERT INTO t1 VALUES (4, 0);
SELECT * FROM t1 ORDER BY a;
a b
1 0
2 0
3 0
4 0
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
binlog-000001.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000001.ibb # Query # # use `test`; INSERT INTO t1 VALUES (4, 0)
binlog-000001.ibb # Xid # # COMMIT /* XID */
*** START TRANSACTION WITH CONSISTENT SNAPSHOT sees position consistent with read view.
connection con1;
SELECT * FROM t1 ORDER BY a;
a b
1 0
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 (2, 0)
binlog-000000.ibb # Xid # # COMMIT /* XID */
*** Connection with no active transaction sees the current position.
connection con2;
connection default;
INSERT INTO t1 VALUES (5, 0);
connection con2;
SELECT * FROM t1 ORDER BY a;
a b
1 0
2 0
3 0
4 0
5 0
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
binlog-000001.ibb # Gtid # # BEGIN GTID #-#-#
binlog-000001.ibb # Query # # use `test`; INSERT INTO t1 VALUES (5, 0)
binlog-000001.ibb # Xid # # COMMIT /* XID */
connection default;
disconnect con1;
disconnect con2;
DROP TABLE t1;

View File

@@ -0,0 +1,45 @@
--source include/have_binlog_format_mixed.inc
--source include/have_innodb_binlog.inc
RESET MASTER;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 0);
--connect(con1,localhost,root,,)
START TRANSACTION WITH CONSISTENT SNAPSHOT;
--connect(con2,localhost,root,,)
--echo *** Connection sees current position by default.
--connection default
INSERT INTO t1 VALUES (2, 0);
FLUSH BINARY LOGS;
INSERT INTO t1 VALUES (3, 0);
--let $binlog_file= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_file', Value, 1)
--let $binlog_start= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_position', Value, 1)
--let $binlog_limit= 0, 3
INSERT INTO t1 VALUES (4, 0);
SELECT * FROM t1 ORDER BY a;
--source include/show_binlog_events.inc
--echo *** START TRANSACTION WITH CONSISTENT SNAPSHOT sees position consistent with read view.
--connection con1
--let $binlog_file= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_file', Value, 1)
--let $binlog_start= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_position', Value, 1)
SELECT * FROM t1 ORDER BY a;
--source include/show_binlog_events.inc
--echo *** Connection with no active transaction sees the current position.
--connection con2
--let $binlog_file= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_file', Value, 1)
--let $binlog_start= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_position', Value, 1)
--connection default
INSERT INTO t1 VALUES (5, 0);
--connection con2
SELECT * FROM t1 ORDER BY a;
--source include/show_binlog_events.inc
--connection default
--disconnect con1
--disconnect con2
DROP TABLE t1;

View File

@@ -0,0 +1,13 @@
SET GLOBAL rpl_semi_sync_master_enabled= 1;
ERROR HY000: Semi-synchronous replication is not yet supported with --binlog-storage-engine
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
XA START 'a';
ERROR HY000: Explicit XA transactions are not yet supported with --binlog-storage-engine
INSERT INTO t1 VALUES (0, 0);
XA END 'a';
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the NON-EXISTING state
XA PREPARE 'a';
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the NON-EXISTING state
XA COMMIT 'a';
ERROR XAE04: XAER_NOTA: Unknown XID
DROP TABLE t1;

View File

@@ -0,0 +1,17 @@
--source include/have_binlog_format_mixed.inc
--source include/have_innodb_binlog.inc
--error ER_ENGINE_BINLOG_NO_SEMISYNC
SET GLOBAL rpl_semi_sync_master_enabled= 1;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
--error ER_ENGINE_BINLOG_NO_USER_XA
XA START 'a';
INSERT INTO t1 VALUES (0, 0);
--error ER_XAER_RMFAIL
XA END 'a';
--error ER_XAER_RMFAIL
XA PREPARE 'a';
--error ER_XAER_NOTA
XA COMMIT 'a';
DROP TABLE t1;

View File

@@ -0,0 +1,46 @@
include/master-slave.inc
[connection master]
*** Test the --binlog-directory variable with legacy binlog.
connection slave;
include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=Slave_pos;
connection master;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES (1, 10);
include/rpl_stop_server.inc [server_number=1]
include/rpl_start_server.inc [server_number=1 parameters: --binlog-directory=binlog_dir]
INSERT INTO t1 VALUES (2, 11);
include/rpl_stop_server.inc [server_number=1]
include/rpl_start_server.inc [server_number=1]
INSERT INTO t1 VALUES (3, 12);
show binary logs;
Log_name File_size
master-bin.000001 #
master-bin.000002 #
master-bin.000002 #
*** Contents of master-bin.index (including directory path):
./master-bin.000001
binlog_dir/master-bin.000002
./master-bin.000002
SELECT * FROM t1 ORDER BY a;
a b
1 10
2 11
3 12
connection slave;
include/start_slave.inc
SELECT * FROM t1 ORDER BY a;
a b
1 10
2 11
3 12
connection slave;
include/stop_slave.inc
SET GLOBAL gtid_slave_pos= '';
connection master;
RESET MASTER;
connection slave;
include/start_slave.inc
connection master;
DROP TABLE t1;
include/rpl_end.inc

View File

@@ -0,0 +1,63 @@
--source include/have_binlog_format_mixed.inc
--source include/master-slave.inc
--echo *** Test the --binlog-directory variable with legacy binlog.
--connection slave
# Stop the slave while restarting master, just to not have to worry about
# any connect/re-connect tries. We are testing the location of the binlog,
# not the slave re-connect abilities.
--source include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=Slave_pos;
--connection master
--let $master_datadir= `SELECT @@datadir`
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES (1, 10);
# Test that the master can be restarted with binlogs in a separate
# directory specificed by --binlog-directory.
--let $rpl_server_number= 1
--source include/rpl_stop_server.inc
--mkdir $master_datadir/binlog_dir
--copy_file $master_datadir/master-bin.000001 $master_datadir/binlog_dir/master-bin.000001
--copy_file $master_datadir/master-bin.000001.idx $master_datadir/binlog_dir/master-bin.000001.idx
--let $rpl_server_parameters= --binlog-directory=binlog_dir
--source include/rpl_start_server.inc
INSERT INTO t1 VALUES (2, 11);
# Move master back to using the standard binlog directory.
--source include/rpl_stop_server.inc
--let $rpl_server_parameters=
--source include/rpl_start_server.inc
INSERT INTO t1 VALUES (3, 12);
--save_master_pos
--source include/show_binary_logs.inc
--echo *** Contents of master-bin.index (including directory path):
--cat_file $master_datadir/master-bin.index
SELECT * FROM t1 ORDER BY a;
--connection slave
--source include/start_slave.inc
--sync_with_master
SELECT * FROM t1 ORDER BY a;
# Clean up.
--connection slave
--source include/stop_slave.inc
SET GLOBAL gtid_slave_pos= '';
--connection master
RESET MASTER;
--rmdir $master_datadir/binlog_dir
--connection slave
--source include/start_slave.inc
--connection master
DROP TABLE t1;
--source include/rpl_end.inc