forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 0
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: This diff is a port of D21440060 (facebook@06e7367) (facebook@06e7367) from mysql-5.6.35 to mysql-8.0 * 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 `write_stats_frequency` seconds. The default values of `write_stats_frequency` is set to 0, which means do not send lag statistics to master. The unit for this sys_var is seconds. Also added another sys_var `write_stats_count` to control the number of data points to cache in replica_statistics table per secondary **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. Differential Revision: D24659846
- Loading branch information
1 parent
eddb59d
commit b015dd3
Showing
58 changed files
with
1,896 additions
and
190 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
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,197 @@ | ||
include/master-slave.inc | ||
[connection master] | ||
######################################################################################################## | ||
### Case 1: Stats are not sent by default i.e. interval value set to 0 | ||
######################################################################################################## | ||
select @@write_stats_frequency; | ||
@@write_stats_frequency | ||
0 | ||
select @@write_stats_count; | ||
@@write_stats_count | ||
0 | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) = 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
######################################################################################################## | ||
### Case 2: Stats are sent when interval value is set > 0 on slaves | ||
######################################################################################################## | ||
set @@GLOBAL.write_stats_frequency=1; | ||
select @@write_stats_frequency; | ||
@@write_stats_frequency | ||
1 | ||
set @@GLOBAL.write_stats_count=10; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
######################################################################################################## | ||
### Case 2.1: Dynamically updating write_stats_count updates the number of data points in replica_statistics | ||
######################################################################################################## | ||
set @@GLOBAL.write_stats_frequency=1; | ||
select @@write_stats_frequency; | ||
@@write_stats_frequency | ||
1 | ||
set @@GLOBAL.write_stats_count=1; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) = 1 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
set @@GLOBAL.write_stats_count=0; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) = 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
set @@GLOBAL.write_stats_count=2; | ||
select sleep(3); | ||
sleep(3) | ||
0 | ||
select count(*) = 2 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
######################################################################################################## | ||
### Case 2.5: Connection is restored and stats are sent to master after it stops and restarts | ||
######################################################################################################## | ||
set @@GLOBAL.write_stats_frequency=1; | ||
select @@write_stats_frequency; | ||
@@write_stats_frequency | ||
1 | ||
set @@GLOBAL.write_stats_count=10; | ||
select sleep(1); | ||
sleep(1) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
select sleep(1); | ||
sleep(1) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
######################################################################################################## | ||
### Case 3: In case of master promotions, slave thread is able to reconnet to new master. | ||
### In this test, I point the slave to an unavailable new master and then re-point it back to original | ||
### master to verify if stats communication resumes. | ||
######################################################################################################## | ||
set @@GLOBAL.write_stats_frequency=1; | ||
Master_User = 'root' | ||
Master_Host = '127.0.0.1' | ||
include/stop_slave.inc | ||
change master to master_user='test'; | ||
start slave; | ||
include/wait_for_slave_io_error.inc [errno=1045] | ||
Master_User = 'test' | ||
Master_Host = '127.0.0.1' | ||
set @@GLOBAL.write_stats_count=10; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select now() - max(timestamp) > 1 as more_than_1_sec_old_most_recent_stats from performance_schema.replica_statistics; | ||
more_than_1_sec_old_most_recent_stats | ||
1 | ||
include/stop_slave_sql.inc | ||
change master to master_user='root'; | ||
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 performance_schema.replica_statistics; | ||
less_than_1_sec_old_most_recent_stats | ||
1 | ||
######################################################################################################## | ||
### Case 3.5: Slave should be able to handle reconnections to master. It should reuse the existing | ||
### thread for sending slave stats and should not spawn a new one. | ||
######################################################################################################## | ||
select @@write_stats_frequency; | ||
@@write_stats_frequency | ||
1 | ||
set @@GLOBAL.write_stats_frequency=1; | ||
set @@GLOBAL.write_stats_count=10; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
select id from information_schema.processlist where command='Binlog Dump' into @id; | ||
kill @id; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select now() - max(timestamp) <= 1 as less_than_1_sec_old_most_recent_stats from performance_schema.replica_statistics; | ||
less_than_1_sec_old_most_recent_stats | ||
1 | ||
######################################################################################################## | ||
### Case 3.5: Secondary is not stuck waiting for primary to send OK packet in case something goes wrong | ||
### It should timeout and move on. | ||
######################################################################################################## | ||
select @@write_stats_frequency; | ||
@@write_stats_frequency | ||
1 | ||
set @@GLOBAL.write_stats_frequency=1; | ||
set @@GLOBAL.write_stats_count=10; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
include/stop_slave.inc | ||
include/start_slave.inc | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select now() - max(timestamp) <= 1 as less_than_1_sec_old_most_recent_stats from performance_schema.replica_statistics; | ||
less_than_1_sec_old_most_recent_stats | ||
1 | ||
######################################################################################################## | ||
### Case 4: Promote slave to master and master to slave. Old master(new slave) should be able to send | ||
### stats to new master(old slave) | ||
######################################################################################################## | ||
set @@GLOBAL.write_stats_count=10; | ||
set @@GLOBAL.write_stats_frequency=1; | ||
set @@GLOBAL.write_stats_count=10; | ||
set @@GLOBAL.write_stats_frequency=1; | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) from performance_schema.replica_statistics where (now() - timestamp) <= 1; | ||
count(*) | ||
0 | ||
include/stop_slave.inc | ||
reset slave all; | ||
CHANGE MASTER TO MASTER_HOST= 'MASTER_HOST', MASTER_USER= 'root', MASTER_PORT= MASTER_PORT;; | ||
include/start_slave.inc | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select sleep(2); | ||
sleep(2) | ||
0 | ||
select count(*) > 0 as stats_samples_collected from performance_schema.replica_statistics; | ||
stats_samples_collected | ||
1 | ||
######################################################################################################## | ||
### Cleanup | ||
### Reset the topology, swap master and slaves again | ||
######################################################################################################## | ||
set @@GLOBAL.write_stats_count=0; | ||
set @@GLOBAL.write_stats_frequency=0; | ||
include/stop_slave.inc | ||
reset slave all; | ||
set @@GLOBAL.write_stats_count=0; | ||
set @@GLOBAL.write_stats_frequency=0; | ||
CHANGE MASTER TO MASTER_HOST= 'MASTER_HOST', MASTER_USER= 'root', MASTER_PORT= MASTER_PORT;; | ||
include/start_slave.inc | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"Checking the data dictionary properties ..." | ||
SUBSTRING_INDEX(SUBSTRING(properties, LOCATE('PS_VERSION', properties), 30), ';', 1) | ||
PS_VERSION=80028007 | ||
PS_VERSION=80028008 | ||
"Checking the performance schema database structure ..." | ||
CHECK STATUS | ||
The tables in the performance_schema were last changed in MySQL 8.0.28-007 | ||
The tables in the performance_schema were last changed in MySQL 8.0.28-008 |
11 changes: 11 additions & 0 deletions
11
mysql-test/suite/perfschema/r/ddl_replica_statistics.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,11 @@ | ||
ALTER TABLE performance_schema.replica_statistics | ||
ADD COLUMN foo integer; | ||
ERROR 42000: Access denied for user 'root'@'localhost' to database 'performance_schema' | ||
TRUNCATE TABLE performance_schema.replica_statistics; | ||
ERROR 42000: DROP command denied to user 'root'@'localhost' for table 'replica_statistics' | ||
ALTER TABLE performance_schema.replica_statistics | ||
ADD INDEX test_index(SERVER_ID); | ||
ERROR 42000: Access denied for user 'root'@'localhost' to database 'performance_schema' | ||
CREATE UNIQUE INDEX test_index ON | ||
performance_schema.replica_statistics(SERVER_ID); | ||
ERROR 42000: Access denied for user 'root'@'localhost' to database 'performance_schema' |
Oops, something went wrong.