Skip to content

Commit 4bb6dfa

Browse files
committed
SHOW MASTER|BINARY LOGS [WITH GTID]
Summary: adds option to show last set GTID in SHOW MASTER LOGS command Test Plan: binlog.binlog_gtid_index, binlog.binlog_nogtid_index Reviewers: santoshb, tengli Reviewed By: santoshb Subscribers: webscalesql-eng Differential Revision: https://reviews.facebook.net/D58467
1 parent b62cee1 commit 4bb6dfa

12 files changed

+320
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
show binary logs with gtid;
7+
Log_name File_size Prev_gtid_set
8+
master-bin.000001 # # [empty]
9+
create table t1 (a int);
10+
insert into t1 values(1);
11+
insert into t1 values(2);
12+
show binary logs with gtid;
13+
Log_name File_size Prev_gtid_set
14+
master-bin.000001 # # [empty]
15+
FLUSH LOGS;
16+
show binary logs with gtid;
17+
Log_name File_size Prev_gtid_set
18+
master-bin.000001 # # [empty]
19+
master-bin.000002 # # uuid:1-3
20+
include/stop_slave.inc
21+
insert into t1 values(3);
22+
insert into t1 values(4);
23+
show binary logs with gtid;
24+
Log_name File_size Prev_gtid_set
25+
master-bin.000001 # # [empty]
26+
master-bin.000002 # # uuid:1-3
27+
FLUSH LOGS;
28+
show binary logs with gtid;
29+
Log_name File_size Prev_gtid_set
30+
master-bin.000001 # # [empty]
31+
master-bin.000002 # # uuid:1-3
32+
master-bin.000003 # # uuid:1-5
33+
include/start_slave.inc
34+
"GTID sets on master"
35+
select @@global.gtid_executed , @@global.gtid_purged;
36+
@@global.gtid_executed @@global.gtid_purged
37+
UUID:1-5
38+
show binary logs with gtid;
39+
Log_name File_size Prev_gtid_set
40+
master-bin.000001 # # [empty]
41+
master-bin.000002 # # uuid:1-3
42+
master-bin.000003 # # uuid:1-5
43+
"GTID sets on slave"
44+
select @@global.gtid_executed , @@global.gtid_purged;
45+
@@global.gtid_executed @@global.gtid_purged
46+
UUID:1-5
47+
show binary logs with gtid;
48+
Log_name File_size Prev_gtid_set
49+
slave-bin.000001 # # [empty]
50+
include/stop_slave.inc
51+
show binary logs with gtid;
52+
Log_name File_size Prev_gtid_set
53+
master-bin.000001 # # [empty]
54+
master-bin.000002 # # uuid:1-3
55+
master-bin.000003 # # uuid:1-5
56+
include/rpl_restart_server.inc [server_number=1 gtids=on]
57+
"GTID sets on master after first restart"
58+
select @@global.gtid_executed , @@global.gtid_purged;
59+
@@global.gtid_executed @@global.gtid_purged
60+
UUID:1-5
61+
show binary logs with gtid;
62+
Log_name File_size Prev_gtid_set
63+
master-bin.000001 # # [empty]
64+
master-bin.000002 # # uuid:1-3
65+
master-bin.000003 # # uuid:1-5
66+
master-bin.000004 # # uuid:1-5
67+
purge binary logs to 'master-bin.000002';
68+
show binary logs with gtid;
69+
Log_name File_size Prev_gtid_set
70+
master-bin.000002 # # uuid:1-3
71+
master-bin.000003 # # uuid:1-5
72+
master-bin.000004 # # uuid:1-5
73+
"GTID sets on master after purge"
74+
select @@global.gtid_executed , @@global.gtid_purged;
75+
@@global.gtid_executed @@global.gtid_purged
76+
UUID:1-5 UUID:1-3
77+
include/rpl_restart_server.inc [server_number=1 gtids=on]
78+
"GTID sets on master after second restart"
79+
select @@global.gtid_executed , @@global.gtid_purged;
80+
@@global.gtid_executed @@global.gtid_purged
81+
UUID:1-5 UUID:1-3
82+
show binary logs with gtid;
83+
Log_name File_size Prev_gtid_set
84+
master-bin.000002 # # uuid:1-3
85+
master-bin.000003 # # uuid:1-5
86+
master-bin.000004 # # uuid:1-5
87+
master-bin.000005 # # uuid:1-5
88+
change master to master_auto_position=0;
89+
include/start_slave.inc
90+
drop table t1;
91+
create table t1 (a int);
92+
insert into t1 values(5);
93+
insert into t1 values(6);
94+
FLUSH LOGS;
95+
drop table t1;
96+
"GTID sets on master finally"
97+
select @@global.gtid_executed , @@global.gtid_purged;
98+
@@global.gtid_executed @@global.gtid_purged
99+
UUID:1-10 UUID:1-3
100+
show binary logs with gtid;
101+
Log_name File_size Prev_gtid_set
102+
master-bin.000002 # # uuid:1-3
103+
master-bin.000003 # # uuid:1-5
104+
master-bin.000004 # # uuid:1-5
105+
master-bin.000005 # # uuid:1-5
106+
master-bin.000006 # # uuid:1-9
107+
"GTID sets on slave finally"
108+
select @@global.gtid_executed , @@global.gtid_purged;
109+
@@global.gtid_executed @@global.gtid_purged
110+
UUID:1-10
111+
show binary logs with gtid;
112+
Log_name File_size Prev_gtid_set
113+
slave-bin.000001 # # [empty]
114+
include/rpl_end.inc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
create table t1 (a int);
7+
insert into t1 values(1);
8+
insert into t1 values(2);
9+
SHOW BINARY LOGS WITH GTID;
10+
Log_name File_size Prev_gtid_set
11+
master-bin.000001 #
12+
FLUSH LOGS;
13+
insert into t1 values(3);
14+
SHOW BINARY LOGS WITH GTID;
15+
Log_name File_size Prev_gtid_set
16+
master-bin.000001 #
17+
master-bin.000002 #
18+
drop table t1;
19+
SHOW BINARY LOGS WITH GTID;
20+
Log_name File_size Prev_gtid_set
21+
master-bin.000001 #
22+
master-bin.000002 #
23+
include/rpl_end.inc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--gtid_mode=ON --enforce_gtid_consistency --log_bin --log_slave_updates
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--gtid_mode=ON --enforce_gtid_consistency --log_bin --log_slave_updates
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
-- source include/master-slave.inc
2+
-- source include/have_gtid.inc
3+
4+
connection master;
5+
let $master_uuid=`select @@server_uuid;`;
6+
replace_result $master_uuid uuid; replace_column 2 #;
7+
show binary logs with gtid;
8+
create table t1 (a int);
9+
10+
insert into t1 values(1);
11+
insert into t1 values(2);
12+
13+
replace_result $master_uuid uuid; replace_column 2 #;
14+
show binary logs with gtid;
15+
16+
FLUSH LOGS;
17+
18+
replace_result $master_uuid uuid; replace_column 2 #;
19+
show binary logs with gtid;
20+
21+
sync_slave_with_master;
22+
-- source include/stop_slave.inc
23+
24+
connection master;
25+
insert into t1 values(3);
26+
insert into t1 values(4);
27+
28+
replace_result $master_uuid uuid; replace_column 2 #;
29+
show binary logs with gtid;
30+
31+
FLUSH LOGS;
32+
33+
replace_result $master_uuid uuid; replace_column 2 #;
34+
show binary logs with gtid;
35+
36+
connection slave;
37+
-- source include/start_slave.inc
38+
39+
connection master;
40+
41+
-- echo "GTID sets on master"
42+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
43+
select @@global.gtid_executed , @@global.gtid_purged;
44+
replace_result $master_uuid uuid; replace_column 2 #;
45+
show binary logs with gtid;
46+
47+
sync_slave_with_master;
48+
49+
-- echo "GTID sets on slave"
50+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
51+
select @@global.gtid_executed , @@global.gtid_purged;
52+
53+
replace_result $master_uuid uuid; replace_column 2 #;
54+
show binary logs with gtid;
55+
56+
--source include/stop_slave.inc
57+
58+
59+
connection master;
60+
61+
replace_result $master_uuid uuid; replace_column 2 #;
62+
show binary logs with gtid;
63+
64+
-- let $rpl_server_number= 1
65+
-- let $rpl_start_with_gtids= 1
66+
-- source include/rpl_restart_server.inc
67+
68+
-- echo "GTID sets on master after first restart"
69+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
70+
select @@global.gtid_executed , @@global.gtid_purged;
71+
72+
replace_result $master_uuid uuid; replace_column 2 #;
73+
show binary logs with gtid;
74+
75+
purge binary logs to 'master-bin.000002';
76+
replace_result $master_uuid uuid; replace_column 2 #;
77+
show binary logs with gtid;
78+
79+
-- echo "GTID sets on master after purge"
80+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
81+
select @@global.gtid_executed , @@global.gtid_purged;
82+
83+
-- let $rpl_server_number= 1
84+
-- let $rpl_start_with_gtids= 1
85+
-- source include/rpl_restart_server.inc
86+
87+
-- echo "GTID sets on master after second restart"
88+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
89+
select @@global.gtid_executed , @@global.gtid_purged;
90+
replace_result $master_uuid uuid; replace_column 2 #;
91+
show binary logs with gtid;
92+
93+
connection slave;
94+
change master to master_auto_position=0;
95+
--source include/start_slave.inc
96+
97+
connection master;
98+
drop table t1;
99+
create table t1 (a int);
100+
insert into t1 values(5);
101+
insert into t1 values(6);
102+
FLUSH LOGS;
103+
104+
drop table t1;
105+
106+
-- echo "GTID sets on master finally"
107+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
108+
select @@global.gtid_executed , @@global.gtid_purged;
109+
replace_result $master_uuid uuid; replace_column 2 #;
110+
show binary logs with gtid;
111+
112+
sync_slave_with_master;
113+
114+
-- echo "GTID sets on slave finally"
115+
-- replace_regex /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/UUID/
116+
select @@global.gtid_executed , @@global.gtid_purged;
117+
replace_result $master_uuid uuid; replace_column 2 #;
118+
show binary logs with gtid;
119+
120+
connection master;
121+
--source include/rpl_end.inc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
source include/master-slave.inc;
2+
source include/not_gtid_enabled.inc;
3+
4+
connection master;
5+
let $master_uuid=`select @@server_uuid;`;
6+
create table t1 (a int);
7+
insert into t1 values(1);
8+
insert into t1 values(2);
9+
replace_result $master_uuid uuid; replace_column 2 #;
10+
SHOW BINARY LOGS WITH GTID;
11+
FLUSH LOGS;
12+
insert into t1 values(3);
13+
replace_result $master_uuid uuid; replace_column 2 #;
14+
SHOW BINARY LOGS WITH GTID;
15+
drop table t1;
16+
replace_result $master_uuid uuid; replace_column 2 #;
17+
SHOW BINARY LOGS WITH GTID;
18+
source include/rpl_end.inc;

sql/rpl_gtid.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,7 @@ int gtid_acquire_ownership_multiple(THD *thd);
28702870
#endif // ifndef MYSQL_CLIENT
28712871
class binlog_cmp {
28722872
public:
2873-
bool operator() (std::string s1, std::string s2) {
2873+
bool operator() (std::string s1, std::string s2) const {
28742874
return (s1.length() != s2.length()) ? (s1.length() < s2.length()) :
28752875
(s1 < s2);
28762876
}

sql/rpl_master.cc

+23-1
Original file line numberDiff line numberDiff line change
@@ -2587,11 +2587,12 @@ bool show_master_status(THD* thd)
25872587
25882588
@param thd Pointer to THD object for the client thread executing the
25892589
statement.
2590+
@param with_gtid Whether to include previous_gtid_set (default false)
25902591
25912592
@retval FALSE success
25922593
@retval TRUE failure
25932594
*/
2594-
bool show_binlogs(THD* thd)
2595+
bool show_binlogs(THD* thd, bool with_gtid)
25952596
{
25962597
IO_CACHE *index_file;
25972598
LOG_INFO cur;
@@ -2612,6 +2613,9 @@ bool show_binlogs(THD* thd)
26122613
field_list.push_back(new Item_empty_string("Log_name", 255));
26132614
field_list.push_back(new Item_return_int("File_size", 20,
26142615
MYSQL_TYPE_LONGLONG));
2616+
if (with_gtid)
2617+
field_list.push_back(new Item_empty_string("Prev_gtid_set",
2618+
0)); // max_size seems not to matter
26152619
if (protocol->send_result_set_metadata(&field_list,
26162620
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
26172621
DBUG_RETURN(TRUE);
@@ -2663,6 +2667,24 @@ bool show_binlogs(THD* thd)
26632667
}
26642668
}
26652669
protocol->store(file_length);
2670+
2671+
if (with_gtid)
2672+
{
2673+
auto previous_gtid_set_map = mysql_bin_log.get_previous_gtid_set_map();
2674+
Sid_map sid_map(NULL);
2675+
Gtid_set gtid_set(&sid_map, NULL);
2676+
auto gtid_str = previous_gtid_set_map->at(std::string(fname));
2677+
if (!gtid_str.empty()) // if GTID enabled
2678+
{
2679+
gtid_set.add_gtid_encoding((const uchar*)gtid_str.c_str(),
2680+
gtid_str.length(), NULL);
2681+
char *buf;
2682+
gtid_set.to_string(&buf, &Gtid_set::commented_string_format);
2683+
protocol->store(buf, strlen(buf), &my_charset_bin);
2684+
free(buf);
2685+
}
2686+
}
2687+
26662688
if (protocol->write())
26672689
{
26682690
DBUG_PRINT("info", ("stopping dump thread because protocol->write failed at line %d", __LINE__));

sql/rpl_master.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool show_master_offset(THD* thd, const char* file, ulonglong pos,
4949
const char* gtid_executed, int gtid_executed_length,
5050
bool* need_ok);
5151
bool show_master_status(THD* thd);
52-
bool show_binlogs(THD* thd);
52+
bool show_binlogs(THD* thd, bool with_gtid = false);
5353
void kill_zombie_dump_threads(String *slave_uuid);
5454
void kill_all_dump_threads();
5555

sql/sql_lex.h

+5
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,11 @@ class Query_tables_list
17131713
bool uses_stored_routines() const
17141714
{ return sroutines_list.elements != 0; }
17151715

1716+
/**
1717+
for SHOW BINARY|MASTER LOGS, true iff WITH GTID specified
1718+
*/
1719+
bool with_gtid;
1720+
17161721
private:
17171722

17181723
/**

sql/sql_parse.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3977,7 +3977,7 @@ case SQLCOM_PREPARE:
39773977
/* db ops requested that this work for non-super */
39783978
/* if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
39793979
goto error; */
3980-
res = show_binlogs(thd);
3980+
res = show_binlogs(thd, lex->with_gtid);
39813981
break;
39823982
}
39833983
#endif

sql/sql_yacc.yy

+11-1
Original file line numberDiff line numberDiff line change
@@ -13276,7 +13276,7 @@ show_param:
1327613276
if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
1327713277
MYSQL_YYABORT;
1327813278
}
13279-
| master_or_binary LOGS_SYM
13279+
| master_or_binary LOGS_SYM gtid_bool
1328013280
{
1328113281
Lex->sql_command = SQLCOM_SHOW_BINLOGS;
1328213282
}
@@ -13485,6 +13485,16 @@ show_param:
1348513485
}
1348613486
;
1348713487

13488+
gtid_bool:
13489+
/* empty */
13490+
{
13491+
Lex->with_gtid = false;
13492+
}
13493+
| WITH GTID_SYM
13494+
{
13495+
Lex->with_gtid = true;
13496+
}
13497+
1348813498
opt_show_engine_status_param:
1348913499
/* Empty */
1349013500
{ Lex->status_type= HA_ENGINE_STATUS; }

0 commit comments

Comments
 (0)