-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added COM_SEND_REPLICA_STATISTICS & background thread to send lag sta…
…tistics from secondary to primary and store it in information_schema.replica_statistics Summary: * I am adding a new RPC `COM_SEND_REPLICA_STATISTICS`. Slaves will use this RPC to send lag statistics to master. This will be done in the next diff. * In addition, I have added the information_schema table named `replica_statistics` to store the slave lag stats. * Added a new background thread that is started when the `mysqld` process starts and continuously publishes lag statistics from slaves to master every `slave_stats_daemon_interval` seconds. The default values of `slave_stats_daemon_interval` is set to 0, which means do not send lag statistics to master. The unit for this sys_var is seconds. **Points to note -** * The background thread re-uses the connection to master to send stats. It does not reconnect every cycle. * If it is not able to connect to the master in one cycle, it retries the connection in successive cycles until it is able to connect. After this point, it reuses the same connection. * In case of topology changes, the thread is able to reconnect to the new master and send stats. Reviewed By: mzait, lth Differential Revision: D21440060 fbshipit-source-id: 9178c96
- Loading branch information
1 parent
a0a2023
commit 06e7367
Showing
30 changed files
with
1,169 additions
and
313 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
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
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,101 @@ | ||
include/master-slave.inc | ||
Warnings: | ||
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
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. | ||
[connection master] | ||
select @@slave_stats_daemon_interval; | ||
@@slave_stats_daemon_interval | ||
0 | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) = 0 as stats_samples_collected from information_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
set @@GLOBAL.slave_stats_daemon_interval=1; | ||
select @@slave_stats_daemon_interval; | ||
@@slave_stats_daemon_interval | ||
1 | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from information_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
set @@GLOBAL.slave_stats_daemon_interval=1; | ||
select @@slave_stats_daemon_interval; | ||
@@slave_stats_daemon_interval | ||
1 | ||
select sleep(1); | ||
sleep(1) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from information_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
select sleep(1); | ||
sleep(1) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from information_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
set @@GLOBAL.slave_stats_daemon_interval=1; | ||
Master_User = 'root' | ||
Master_Host = '127.0.0.1' | ||
include/stop_slave.inc | ||
change master to master_user='test'; | ||
Warnings: | ||
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
Note 1760 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. | ||
start slave; | ||
Master_User = 'test' | ||
Master_Host = '127.0.0.1' | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select now() - max(timestamp) > 1 as more_than_1_sec_old_most_recent_stats from information_schema.replica_statistics; | ||
more_than_1_sec_old_most_recent_stats | ||
1 | ||
include/stop_slave.inc | ||
change master to master_user='root'; | ||
Warnings: | ||
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
Note 1760 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. | ||
include/start_slave.inc | ||
Master_User = 'root' | ||
Master_Host = '127.0.0.1' | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select now() - max(timestamp) <= 1 as less_than_1_sec_old_most_recent_stats from information_schema.replica_statistics; | ||
less_than_1_sec_old_most_recent_stats | ||
1 | ||
set @@GLOBAL.slave_stats_daemon_interval=1; | ||
set @@GLOBAL.slave_stats_daemon_interval=1; | ||
select * from information_schema.replica_statistics; | ||
SERVER_ID TIMESTAMP MILLI_SEC_BEHIND_MASTER | ||
Stop slave; | ||
reset slave all; | ||
CHANGE MASTER TO MASTER_HOST= 'MASTER_HOST', MASTER_USER= 'root', MASTER_PORT= MASTER_PORT;; | ||
Warnings: | ||
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
Note 1760 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. | ||
start slave; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from information_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
set @@GLOBAL.slave_stats_daemon_interval=0; | ||
Stop slave; | ||
reset slave all; | ||
set @@GLOBAL.slave_stats_daemon_interval=0; | ||
CHANGE MASTER TO MASTER_HOST= 'MASTER_HOST', MASTER_USER= 'root', MASTER_PORT= MASTER_PORT;; | ||
Warnings: | ||
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
Note 1760 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. | ||
start slave; | ||
include/rpl_end.inc |
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
25 changes: 25 additions & 0 deletions
25
mysql-test/suite/sys_vars/r/slave_stats_daemon_interval_basic.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,25 @@ | ||
Default value of slave_stats_daemon_interval is 0 | ||
SELECT @@global.slave_stats_daemon_interval; | ||
@@global.slave_stats_daemon_interval | ||
0 | ||
SELECT @@session.slave_stats_daemon_interval; | ||
ERROR HY000: Variable 'slave_stats_daemon_interval' is a GLOBAL variable | ||
Expected error 'Variable is a GLOBAL variable' | ||
slave_stats_daemon_interval is a dynamic variable (change to 1) | ||
set @@global.slave_stats_daemon_interval = 1; | ||
SELECT @@global.slave_stats_daemon_interval; | ||
@@global.slave_stats_daemon_interval | ||
1 | ||
restore the default value | ||
SET @@global.slave_stats_daemon_interval = 0; | ||
SELECT @@global.slave_stats_daemon_interval; | ||
@@global.slave_stats_daemon_interval | ||
0 | ||
restart the server with non default value (1) | ||
SELECT @@global.slave_stats_daemon_interval; | ||
@@global.slave_stats_daemon_interval | ||
1 | ||
restart the server with the default value (0) | ||
SELECT @@global.slave_stats_daemon_interval; | ||
@@global.slave_stats_daemon_interval | ||
0 |
Oops, something went wrong.