mirror of
https://github.com/MariaDB/server.git
synced 2025-07-12 14:28:13 +02:00

The current semi-sync binlog fail-over recovery process uses rpl_semi_sync_slave_enabled==TRUE as its condition to truncate a primary server’s binlog, as it is anticipating the server to re-join a replication topology as a replica. However, for servers configured with both rpl_semi_sync_master_enabled=1 and rpl_semi_sync_slave_enabled=1, if a primary is just re-started (i.e. retaining its role as master), it can truncate its binlog to drop transactions which its replica(s) has already received and executed. If this happens, when the replica reconnects, its gtid_slave_pos can be ahead of the recovered primary’s gtid_binlog_pos, resulting in an error state where the replica’s state is ahead of the primary’s. This patch changes the condition for semi-sync recovery to truncate the binlog to instead use the configuration variable --init-rpl-role, when set to SLAVE. This allows for both rpl_semi_sync_master_enabled and rpl_semi_sync_slave_enabled to be set for a primary that is restarted, and no transactions will be lost, so long as --init-rpl-role is not set to SLAVE. Reviewed By: ============ Sergei Golubchik <serg@mariadb.com>
191 lines
4.8 KiB
Text
191 lines
4.8 KiB
Text
call mtr.add_suppression("Can.t init tc log");
|
|
call mtr.add_suppression("Aborting");
|
|
SET @@global.sync_binlog= 1;
|
|
CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
|
|
CREATE TABLE t2 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=rocksdb;
|
|
#
|
|
#
|
|
# Case "A" : "neither engine committed => rollback & binlog truncate"
|
|
#
|
|
RESET MASTER;
|
|
FLUSH LOGS;
|
|
SET GLOBAL max_binlog_size= 4096;
|
|
connect con1,localhost,root,,;
|
|
List of binary logs before rotation
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
INSERT INTO t1 VALUES (1, REPEAT("x", 1));
|
|
INSERT INTO t2 VALUES (1, REPEAT("x", 1));
|
|
BEGIN;
|
|
INSERT INTO t2 VALUES (2, REPEAT("x", 4100));
|
|
INSERT INTO t1 VALUES (2, REPEAT("x", 4100));
|
|
SET DEBUG_SYNC= "commit_after_release_LOCK_log SIGNAL con1_ready WAIT_FOR signal_no_signal";
|
|
COMMIT;
|
|
connection default;
|
|
SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
|
|
List of binary logs after rotation
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
master-bin.000003 #
|
|
# restart the server with --init-rpl-role=SLAVE --sync-binlog=1
|
|
# the server is restarted
|
|
# restart: --init-rpl-role=SLAVE --sync-binlog=1
|
|
connection default;
|
|
#
|
|
# *** Summary: 1 row should be present in both tables; binlog is truncated; number of binlogs at reconnect - 3:
|
|
#
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
1
|
|
SELECT COUNT(*) FROM t2;
|
|
COUNT(*)
|
|
1
|
|
SELECT @@GLOBAL.gtid_binlog_state;
|
|
@@GLOBAL.gtid_binlog_state
|
|
0-1-2
|
|
SELECT @@GLOBAL.gtid_binlog_pos;
|
|
@@GLOBAL.gtid_binlog_pos
|
|
0-1-2
|
|
List of binary logs at the end of the tests
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
master-bin.000003 #
|
|
# ***
|
|
DELETE FROM t1;
|
|
DELETE FROM t2;
|
|
disconnect con1;
|
|
#
|
|
Proof of the truncated binlog file is readable (two transactions must be seen):
|
|
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
|
|
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
|
|
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
|
|
DELIMITER /*!*/;
|
|
START TRANSACTION
|
|
/*!*/;
|
|
COMMIT/*!*/;
|
|
START TRANSACTION
|
|
/*!*/;
|
|
COMMIT/*!*/;
|
|
DELIMITER ;
|
|
# End of log file
|
|
ROLLBACK /* added by mysqlbinlog */;
|
|
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
|
|
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
|
|
#
|
|
#
|
|
# Case "B" : "one engine has committed its transaction branch"
|
|
#
|
|
RESET MASTER;
|
|
FLUSH LOGS;
|
|
SET GLOBAL max_binlog_size= 4096;
|
|
connect con1,localhost,root,,;
|
|
List of binary logs before rotation
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
INSERT INTO t1 VALUES (1, REPEAT("x", 1));
|
|
INSERT INTO t2 VALUES (1, REPEAT("x", 1));
|
|
SET GLOBAL debug_dbug="d,enable_log_write_upto_crash";
|
|
BEGIN;
|
|
INSERT INTO t2 VALUES (2, REPEAT("x", 4100));
|
|
INSERT INTO t1 VALUES (2, REPEAT("x", 4100));
|
|
COMMIT;
|
|
connection default;
|
|
# restart: --init-rpl-role=SLAVE --sync-binlog=1
|
|
connection default;
|
|
#
|
|
# *** Summary: 2 rows should be present in both tables; no binlog truncation; one extra binlog file compare with A; number of binlogs at reconnect - 4:
|
|
#
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
2
|
|
SELECT COUNT(*) FROM t2;
|
|
COUNT(*)
|
|
2
|
|
SELECT @@GLOBAL.gtid_binlog_state;
|
|
@@GLOBAL.gtid_binlog_state
|
|
0-1-3
|
|
SELECT @@GLOBAL.gtid_binlog_pos;
|
|
@@GLOBAL.gtid_binlog_pos
|
|
0-1-3
|
|
List of binary logs at the end of the tests
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
master-bin.000003 #
|
|
master-bin.000004 #
|
|
# ***
|
|
DELETE FROM t1;
|
|
DELETE FROM t2;
|
|
disconnect con1;
|
|
#
|
|
#
|
|
#
|
|
# Case "C" : "both engines have committed its transaction branch"
|
|
#
|
|
RESET MASTER;
|
|
FLUSH LOGS;
|
|
SET GLOBAL max_binlog_size= 4096;
|
|
connect con1,localhost,root,,;
|
|
List of binary logs before rotation
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
INSERT INTO t1 VALUES (1, REPEAT("x", 1));
|
|
INSERT INTO t2 VALUES (1, REPEAT("x", 1));
|
|
BEGIN;
|
|
INSERT INTO t2 VALUES (2, REPEAT("x", 4100));
|
|
INSERT INTO t1 VALUES (2, REPEAT("x", 4100));
|
|
SET DEBUG_SYNC= "commit_after_run_commit_ordered SIGNAL con1_ready";
|
|
COMMIT;
|
|
connection default;
|
|
SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
|
|
List of binary logs after rotation
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
master-bin.000003 #
|
|
# restart the server with --init-rpl-role=SLAVE --sync-binlog=1
|
|
# the server is restarted
|
|
# restart: --init-rpl-role=SLAVE --sync-binlog=1
|
|
connection default;
|
|
#
|
|
# *** Summary: 2 rows should be present in both tables; no binlog truncation; the same # of binlog files as in B; number of binlogs at reconnect - 4:
|
|
#
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
2
|
|
SELECT COUNT(*) FROM t2;
|
|
COUNT(*)
|
|
2
|
|
SELECT @@GLOBAL.gtid_binlog_state;
|
|
@@GLOBAL.gtid_binlog_state
|
|
0-1-3
|
|
SELECT @@GLOBAL.gtid_binlog_pos;
|
|
@@GLOBAL.gtid_binlog_pos
|
|
0-1-3
|
|
List of binary logs at the end of the tests
|
|
show binary logs;
|
|
Log_name File_size
|
|
master-bin.000001 #
|
|
master-bin.000002 #
|
|
master-bin.000003 #
|
|
master-bin.000004 #
|
|
# ***
|
|
DELETE FROM t1;
|
|
DELETE FROM t2;
|
|
disconnect con1;
|
|
#
|
|
DROP TABLE t1, t2;
|
|
SET @@global.sync_binlog= default;
|
|
# End of the tests
|