-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit implements two phase binloggable ALTER. When a new @@session.binlog_alter_two_phase = YES ALTER query gets logged in two parts, the START ALTER and the COMMIT or ROLLBACK ALTER. START Alter is written in binlog as soon as necessary locks have been acquired for the table. The timing is such that any concurrent DML:s that update the same table are either committed, thus logged into binary log having done work on the old version of the table, or will be queued for execution on its new version. The "COMPLETE" COMMIT or ROLLBACK ALTER are written at the very point of a normal "single-piece" ALTER that is after the most of the query work is done. When its result is positive COMMIT ALTER is written, otherwise ROLLBACK ALTER is written with specific error happened after START ALTER phase. Replication of two-phase binloggable ALTER is cross-version safe. Specifically the OLD slave merely does not recognized the start alter part, still being able to process and memorize its gtid. Two phase logged ALTER is read from binlog by mysqlbinlog to produce BINLOG 'string', where 'string' contains base64 encoded Query_log_event containing either the start part of ALTER, or a completion part. The Query details can be displayed with `-v` flag, similarly to ROW format events. Notice, mysqlbinlog output containing parts of two-phase binloggable ALTER is processable correctly only by binlog_alter_two_phase server. @@log_warnings > 2 can reveal details of binlogging and slave side processing of the ALTER parts. The current commit also carries fixes to the following list of reported bugs: MDEV-27511, MDEV-27471, MDEV-27349, MDEV-27628, MDEV-27528. Thanks to all people involved into early discussion of the feature including Kristian Nielsen, those who helped to design, implement and test: Sergei Golubchik, Andrei Elkin who took the burden of the implemenation completion, Sujatha Sivakumar, Brandon Nesterenko, Alice Sherepa, Ramesh Sivaraman, Jan Lindstrom.
- Loading branch information
1 parent
c64e507
commit 0c5d134
Showing
87 changed files
with
8,451 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
mysql-test/suite/binlog/r/binlog_mysqlbinlog_start_alter_verbose.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set global binlog_alter_two_phase=YES; | ||
set binlog_alter_two_phase=YES; | ||
RESET MASTER; | ||
create table myt (a int) engine=InnoDB; | ||
alter table myt add column (b int); | ||
FLUSH LOGS; | ||
# Exec MYSQL_BINLOG --base64-output=decode-rows -v MYSQLD_DATADIR/BINLOG_FILENAME > MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql | ||
Verbose statements from : master-bin.000001 | ||
select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%'; | ||
stmt | ||
### alter table myt add column (b int) | ||
### alter table myt add column (b int) | ||
drop table raw_binlog_rows; | ||
drop table myt; | ||
set global binlog_alter_two_phase=No; |
42 changes: 42 additions & 0 deletions
42
mysql-test/suite/binlog/r/start_alter_mysqlbinlog_replay.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Test verifies replay of binary logs which contain | ||
# SA/RA/CA works fine. | ||
# Generate a binary log with alter events and use mysqlbinlog tool to | ||
# generate a sql file for replay. Source it on an clean master and | ||
# verify the correctness. Use the latest binlog and repeat the same | ||
# process mentioned above and observe replay works fine. | ||
# | ||
set global binlog_alter_two_phase=YES; | ||
set binlog_alter_two_phase=YES; | ||
create table t1 (f1 int primary key) engine=InnoDB; | ||
create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; | ||
alter table t2 add constraint c1 foreign key (f1) references t1(f1); | ||
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") | ||
drop table t2, t1; | ||
select @@gtid_binlog_state; | ||
@@gtid_binlog_state | ||
0-1-5 | ||
FLUSH LOGS; | ||
# reset the binlog | ||
RESET MASTER; | ||
# execute the binlog | ||
SELECT @@gtid_binlog_state; | ||
@@gtid_binlog_state | ||
0-1-5 | ||
FLUSH LOGS; | ||
# Replay 1: One more time to simulate S->S case | ||
RESET MASTER; | ||
# execute the binlog | ||
SELECT @@gtid_binlog_state; | ||
@@gtid_binlog_state | ||
0-1-5 | ||
FLUSH LOGS; | ||
# Replay 2: One more time to simulate S->S case | ||
RESET MASTER; | ||
# execute the binlog | ||
SELECT @@gtid_binlog_state; | ||
@@gtid_binlog_state | ||
0-1-5 | ||
# clean up | ||
RESET MASTER; | ||
set global binlog_alter_two_phase=No;; |
58 changes: 58 additions & 0 deletions
58
mysql-test/suite/binlog/t/binlog_mysqlbinlog_start_alter_verbose.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# Purpose: | ||
# | ||
# This test ensures that mysqlbinlog prints a comment when two-phase alter | ||
# is enabled which shows the original alter query issued. | ||
# | ||
# | ||
# References: | ||
# MENT-662: Finalize MDEV-11675 "Lag Free Alter On Slave" | ||
# | ||
|
||
# Just row format for faster testing | ||
--source include/have_binlog_format_row.inc | ||
--source include/have_innodb.inc | ||
|
||
#--- | ||
# Setup | ||
#--- | ||
--let $binlog_alter_two_phase= `select @@binlog_alter_two_phase` | ||
set global binlog_alter_two_phase=YES; | ||
set binlog_alter_two_phase=YES; | ||
|
||
RESET MASTER; | ||
create table myt (a int) engine=InnoDB; | ||
|
||
|
||
#--- | ||
# Issue ALTER | ||
#--- | ||
alter table myt add column (b int); | ||
|
||
|
||
#--- | ||
# Check binlog output | ||
#--- | ||
FLUSH LOGS; | ||
|
||
--disable_query_log | ||
--let $MYSQLD_DATADIR= `select @@datadir` | ||
--let $BINLOG_FILENAME= query_get_value(SHOW BINARY LOGS, Log_name, 1) | ||
|
||
--echo # Exec MYSQL_BINLOG --base64-output=decode-rows -v MYSQLD_DATADIR/BINLOG_FILENAME > MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql | ||
--exec $MYSQL_BINLOG --base64-output=decode-rows -v $MYSQLD_DATADIR/$BINLOG_FILENAME > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql | ||
|
||
create table raw_binlog_rows (txt varchar(1000)); | ||
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql' into table raw_binlog_rows columns terminated by '\n' | ||
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql | ||
--enable_query_log | ||
--echo Verbose statements from : $BINLOG_FILENAME | ||
# Output --verbose lines, with extra Windows CR's trimmed | ||
select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%'; | ||
|
||
#--- | ||
# Cleanup | ||
#--- | ||
drop table raw_binlog_rows; | ||
drop table myt; | ||
--eval set global binlog_alter_two_phase=$binlog_alter_two_phase |
61 changes: 61 additions & 0 deletions
61
mysql-test/suite/binlog/t/start_alter_mysqlbinlog_replay.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# MENT-662: Lag Free Alter On Slave | ||
# | ||
|
||
--echo # | ||
--echo # Test verifies replay of binary logs which contain | ||
--echo # SA/RA/CA works fine. | ||
--echo # Generate a binary log with alter events and use mysqlbinlog tool to | ||
--echo # generate a sql file for replay. Source it on an clean master and | ||
--echo # verify the correctness. Use the latest binlog and repeat the same | ||
--echo # process mentioned above and observe replay works fine. | ||
--echo # | ||
--source include/have_log_bin.inc | ||
--source include/have_innodb.inc | ||
--source include/have_binlog_format_statement.inc | ||
|
||
--let $binlog_alter_two_phase= `select @@binlog_alter_two_phase` | ||
set global binlog_alter_two_phase=YES; | ||
set binlog_alter_two_phase=YES; | ||
|
||
create table t1 (f1 int primary key) engine=InnoDB; | ||
create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; | ||
|
||
--error ER_CANT_CREATE_TABLE | ||
alter table t2 add constraint c1 foreign key (f1) references t1(f1); | ||
|
||
drop table t2, t1; | ||
select @@gtid_binlog_state; | ||
FLUSH LOGS; | ||
|
||
let MYSQLD_DATADIR= `select @@datadir;`; | ||
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/slave_1.sql | ||
|
||
--echo # reset the binlog | ||
RESET MASTER; | ||
--echo # execute the binlog | ||
--exec $MYSQL --port=$MASTER_MYPORT --host=127.0.0.1 -e "source $MYSQLTEST_VARDIR/tmp/slave_1.sql" | ||
SELECT @@gtid_binlog_state; | ||
FLUSH LOGS; | ||
--echo # Replay 1: One more time to simulate S->S case | ||
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/slave_2.sql | ||
|
||
RESET MASTER; | ||
--echo # execute the binlog | ||
--exec $MYSQL --port=$MASTER_MYPORT --host=127.0.0.1 -e "source $MYSQLTEST_VARDIR/tmp/slave_2.sql" | ||
SELECT @@gtid_binlog_state; | ||
FLUSH LOGS; | ||
--echo # Replay 2: One more time to simulate S->S case | ||
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/slave_3.sql | ||
RESET MASTER; | ||
--echo # execute the binlog | ||
--exec $MYSQL --port=$MASTER_MYPORT --host=127.0.0.1 -e "source $MYSQLTEST_VARDIR/tmp/slave_3.sql" | ||
SELECT @@gtid_binlog_state; | ||
|
||
--echo # clean up | ||
remove_file $MYSQLTEST_VARDIR/tmp/slave_1.sql; | ||
remove_file $MYSQLTEST_VARDIR/tmp/slave_2.sql; | ||
remove_file $MYSQLTEST_VARDIR/tmp/slave_3.sql; | ||
RESET MASTER; | ||
|
||
--eval set global binlog_alter_two_phase=$binlog_alter_two_phase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# | ||
# Run start alter basic tests (CA/RA with given engine) | ||
# Params:- | ||
# $engine | ||
# $sync_slave | ||
# master_node and slave_node connection should be defined | ||
|
||
--echo # $engine | ||
--connection master_node | ||
--eval create table t1(a int, b int) engine=$engine; | ||
insert into t1 values(1,1); | ||
insert into t1 values(2,2); | ||
--echo # Normal Alter | ||
alter table t1 add column c int; | ||
show create table t1; | ||
--echo # Failed Alter | ||
insert into t1 values(1,1, NULL); | ||
--error ER_DUP_ENTRY | ||
alter table t1 change a a int unique; | ||
set @@session.binlog_alter_two_phase = 0; | ||
alter table t1 change a a int; | ||
set @@session.binlog_alter_two_phase = 1; | ||
alter table t1 change a a int; | ||
show create table t1; | ||
|
||
# The following restriction should be removed post MDEV-26005 fix. | ||
# TODO MDEV-26130 , should be removed after fixing | ||
#if ($engine != 'aria') | ||
#{ | ||
#--eval create temporary table tmp_tbl(a int, b int) engine=$engine; | ||
#insert into tmp_tbl values(1,1); | ||
#insert into tmp_tbl values(2,2); | ||
#--echo # Normal Alter | ||
#alter table tmp_tbl add column c int; | ||
#--echo # Failed Alter | ||
#insert into tmp_tbl values(1,1, NULL); | ||
#--error ER_DUP_ENTRY | ||
#alter table tmp_tbl change a a int unique ; | ||
#show create table tmp_tbl; | ||
#} | ||
if ($sync_slave) | ||
{ | ||
--source include/save_master_gtid.inc | ||
--connection slave_node | ||
--source include/sync_with_master_gtid.inc | ||
show create table t1; | ||
} | ||
|
||
--connection master_node | ||
drop table t1; | ||
#if ($engine != 'aria') | ||
#{ | ||
#drop temporary table tmp_tbl; | ||
#} | ||
if ($sync_slave) | ||
{ | ||
--source include/save_master_gtid.inc | ||
--connection slave_node | ||
--source include/sync_with_master_gtid.inc | ||
} |
Oops, something went wrong.