Skip to content

Commit

Permalink
Rotate binlogs when setting gtid_purged
Browse files Browse the repository at this point in the history
Summary:
In 5.6, the binlog was rotated when gtid_purge was set, but this
behavior changed in 8.0. Functionality such as SHOW GTID_EXECUTED IN
depend on reading the prev_gtid event of the binlog to construct the
executed set up to that point in the binlog file. If gtid_purge was set
without rotating the binlog, SHOW GTID_EXECUTED IN does not include the
purged gtid information.

Squash with D9368239

Reviewed By: yizhang82

Differential Revision: D20842600

fbshipit-source-id: b91da8c
  • Loading branch information
Herman Lee authored and facebook-github-bot committed Apr 6, 2020
1 parent 6e3968c commit 215b84b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DROP TABLE t1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
RESET MASTER;
SET GLOBAL gtid_purged = CONCAT(@@GLOBAL.server_uuid, ':1-9223372036854775805');
include/assert.inc [Binlog file must not rotate after SET GTID_PURGED]
include/assert.inc [Binlog file must rotate after SET GTID_PURGED]
INSERT INTO t1 VALUES (1);
SET GLOBAL binlog_error_action=ABORT_SERVER;
INSERT INTO t1 VALUES (2);
Expand Down
7 changes: 4 additions & 3 deletions mysql-test/suite/binlog_gtid/t/binlog_gtid_exhausted.test
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ RESET MASTER;
SET GLOBAL gtid_purged = CONCAT(@@GLOBAL.server_uuid, ':1-9223372036854775805');
--let $binlog_file_1= query_get_value(SHOW MASTER STATUS, File, 1)

--let $assert_cond = "$binlog_file_0" = "$binlog_file_1"
--let $assert_text = Binlog file must not rotate after SET GTID_PURGED
--source include/assert.inc
# FB - set gtid_purged now forces rotation
--let $assert_cond = "$binlog_file_0" != "$binlog_file_1"
--let $assert_text = Binlog file must rotate after SET GTID_PURGED
--source include/assert.inc

INSERT INTO t1 VALUES (1);
SET GLOBAL binlog_error_action=ABORT_SERVER;
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/suite/binlog_gtid/t/binlog_gtid_mysqldump.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ RESET MASTER;

--source include/restart_mysqld.inc

# FB - Due to how prev_gtid is used in 8.0 (full set), there exists some conditions
# where the gtid_purged will not reflect newly added purged sets.
# purged is calculated solely on the oldest binlog, so it requires the oldest binlog
# to have the purged uuid in the prev_gtid event.
--disable_query_log
--let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--eval PURGE BINARY LOGS TO '$current_binlog'
--enable_query_log

--let $assert_text= GTID_EXECUTED should equal master GTID_EXECUTED after server restarted
--let $assert_cond= @@GLOBAL.GTID_EXECUTED = "$gtid_executed"
--source include/assert.inc
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/suite/binlog_gtid/t/binlog_gtid_mysqlpump.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ RESET MASTER;

--source include/restart_mysqld.inc

# FB - Due to how prev_gtid is used in 8.0 (full set), there exists some conditions
# where the gtid_purged will not reflect newly added purged sets.
# purged is calculated solely on the oldest binlog, so it requires the oldest binlog
# to have the purged uuid in the prev_gtid event.
--disable_query_log
--let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--eval PURGE BINARY LOGS TO '$current_binlog'
--enable_query_log

--let $assert_text= GTID_EXECUTED should equal master GTID_EXECUTED after server restarted
--let $assert_cond= @@GLOBAL.GTID_EXECUTED = "$gtid_executed"
--source include/assert.inc
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/suite/rpl/r/rpl_gtid_executed.result
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ insert into t1 values(3);
SHOW GTID_EXECUTED IN 'master-bin.000002' FROM 400;
Gtid_executed
uuid:1-4
# Verify setting gtid_purged also rotates the binlog
SET GLOBAL gtid_purged="ffffffff-ffff-ffff-ffff-123456789abc:1-12345";
insert into t1 values(4);
SHOW GTID_EXECUTED IN 'master-bin.000003' FROM 400;
Gtid_executed
uuid:1-5,
ffffffff-ffff-ffff-ffff-123456789abc:1-12345
SET GLOBAL gtid_purged="ffffffff-ffff-ffff-ffff-123456789abc:1-12345";
drop table t1;
SHOW GTID_EXECUTED;
ERROR HY000: Error when executing command SHOW GTID_EXECUTED: binlog file name is not specified
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/suite/rpl/t/rpl_gtid_executed.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ FLUSH LOGS;
insert into t1 values(3);
replace_result $master_uuid uuid;
SHOW GTID_EXECUTED IN 'master-bin.000002' FROM 400;

--echo # Verify setting gtid_purged also rotates the binlog
SET GLOBAL gtid_purged="ffffffff-ffff-ffff-ffff-123456789abc:1-12345";
insert into t1 values(4);
replace_result $master_uuid uuid;
SHOW GTID_EXECUTED IN 'master-bin.000003' FROM 400;
connection slave;
SET GLOBAL gtid_purged="ffffffff-ffff-ffff-ffff-123456789abc:1-12345";

connection master;
drop table t1;
-- error ER_ERROR_WHEN_EXECUTING_COMMAND
SHOW GTID_EXECUTED;
Expand Down
25 changes: 13 additions & 12 deletions mysql-test/suite/rpl_gtid/r/rpl_gtid_mysqldump_minimum_hlc.result
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,19 @@ INSERT INTO t3 VALUES (1, 'a');
INSERT INTO t3 VALUES (2, 'b');
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
slave-bin.000002 # Metadata # # HLC time: 2538630000000000006
slave-bin.000002 # Query # # use `test`; CREATE TABLE t3 (a INT PRIMARY KEY, b CHAR(8)) ENGINE=InnoDB
slave-bin.000002 # Metadata # # HLC time: 2538630000000000007
slave-bin.000002 # Query # # BEGIN
slave-bin.000002 # Table_map # # table_id: # (test.t3)
slave-bin.000002 # Write_rows # # table_id: # flags: STMT_END_F
slave-bin.000002 # Xid # # COMMIT /* XID */
slave-bin.000002 # Metadata # # HLC time: 2538630000000000008
slave-bin.000002 # Query # # BEGIN
slave-bin.000002 # Table_map # # table_id: # (test.t3)
slave-bin.000002 # Write_rows # # table_id: # flags: STMT_END_F
slave-bin.000002 # Xid # # COMMIT /* XID */
slave-bin.000003 # Metadata # # Prev HLC time: 0
slave-bin.000003 # Metadata # # HLC time: 2538630000000000006
slave-bin.000003 # Query # # use `test`; CREATE TABLE t3 (a INT PRIMARY KEY, b CHAR(8)) ENGINE=InnoDB
slave-bin.000003 # Metadata # # HLC time: 2538630000000000007
slave-bin.000003 # Query # # BEGIN
slave-bin.000003 # Table_map # # table_id: # (test.t3)
slave-bin.000003 # Write_rows # # table_id: # flags: STMT_END_F
slave-bin.000003 # Xid # # COMMIT /* XID */
slave-bin.000003 # Metadata # # HLC time: 2538630000000000008
slave-bin.000003 # Query # # BEGIN
slave-bin.000003 # Table_map # # table_id: # (test.t3)
slave-bin.000003 # Write_rows # # table_id: # flags: STMT_END_F
slave-bin.000003 # Xid # # COMMIT /* XID */
DROP TABLE t3;
include/start_slave.inc
[connection master]
Expand Down
12 changes: 12 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6661,6 +6661,18 @@ bool Sys_var_gtid_purged::global_update(THD *thd, set_var *var) {
my_free(previous_gtid_purged);
my_free(current_gtid_executed);
my_free(current_gtid_purged);

// FB - mimic 5.6 functionality to rotate the log
// Rotate logs to push out the Previous_gtid_event to the binlog.
// Rotate requires the global_sid_lock, so perform this step
// after everything else has completed successfully.
//
// SHOW GTID_EXECUTED IN <binlog_file> FROM <offset>
// uses the PREV_GTID event to calculate the executed set.
if (!error && mysql_bin_log.rotate_and_purge(thd, true)) {
error = true;
}

DBUG_RETURN(error);
}

Expand Down

0 comments on commit 215b84b

Please sign in to comment.