forked from percona/percona-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recalculate index statistics periodically
Upstream commit ID : fb-mysql-5.6.35/ee8ca237a15c63ca98904183fd16fb79fb17e1ef PS-4476 : Merge prod-------- Summary: Persisted stats sometimes drift away from the actual sum from sst files. To mitigate this problem, recalculate stats periodically. This is controlled by the rocksdb_stats_recalc_rate global variable which configures the number of indexes to recalculate per second. Implementation details: - Refactor calculate_stats to not depend on handler. - Track indexes left to recalculate in rdb_indexes_to_recalc, and refill when it empties. - Extend existing background thread to recalculate stats on every wake-up. Removed a call to calculate_stats from alter table. This was originally added in facebook/mysql-5.6@3442d47 because uncommitted indexes could not be found in the data dictionary yet, but a subsequent commmit facebook/mysql-5.6@5d2b953 solved this. Also remove fake stats from Rdb_index_stats::merge. This could cause underflow if 1. during recovery, we write sst files with no index stats and 2. on compaction of these sst files, we subtract index stats. Underflow happens because the global count was not incremented during recovery, yet it is subtracted on compaction. Reviewed By: hermanlee Differential Revision: D7482233 fbshipit-source-id: 47286bd
- Loading branch information
Showing
6 changed files
with
173 additions
and
106 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
mysql-test/suite/rocksdb.sys_vars/r/rocksdb_stats_recalc_rate_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,53 @@ | ||
CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; | ||
INSERT INTO valid_values VALUES(100); | ||
INSERT INTO valid_values VALUES(1); | ||
CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; | ||
INSERT INTO invalid_values VALUES('\'aaa\''); | ||
INSERT INTO invalid_values VALUES('\'123\''); | ||
SET @start_global_value = @@global.ROCKSDB_STATS_RECALC_RATE; | ||
SELECT @start_global_value; | ||
@start_global_value | ||
0 | ||
'# Setting to valid values in global scope#' | ||
"Trying to set variable @@global.ROCKSDB_STATS_RECALC_RATE to 100" | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = 100; | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
100 | ||
"Setting the global scope variable back to default" | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = DEFAULT; | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
0 | ||
"Trying to set variable @@global.ROCKSDB_STATS_RECALC_RATE to 1" | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = 1; | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
1 | ||
"Setting the global scope variable back to default" | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = DEFAULT; | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
0 | ||
"Trying to set variable @@session.ROCKSDB_STATS_RECALC_RATE to 444. It should fail because it is not session." | ||
SET @@session.ROCKSDB_STATS_RECALC_RATE = 444; | ||
ERROR HY000: Variable 'rocksdb_stats_recalc_rate' is a GLOBAL variable and should be set with SET GLOBAL | ||
'# Testing with invalid values in global scope #' | ||
"Trying to set variable @@global.ROCKSDB_STATS_RECALC_RATE to 'aaa'" | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = 'aaa'; | ||
Got one of the listed errors | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
0 | ||
"Trying to set variable @@global.ROCKSDB_STATS_RECALC_RATE to '123'" | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = '123'; | ||
Got one of the listed errors | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
0 | ||
SET @@global.ROCKSDB_STATS_RECALC_RATE = @start_global_value; | ||
SELECT @@global.ROCKSDB_STATS_RECALC_RATE; | ||
@@global.ROCKSDB_STATS_RECALC_RATE | ||
0 | ||
DROP TABLE valid_values; | ||
DROP TABLE invalid_values; |
18 changes: 18 additions & 0 deletions
18
mysql-test/suite/rocksdb.sys_vars/t/rocksdb_stats_recalc_rate_basic.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,18 @@ | ||
--source include/have_rocksdb.inc | ||
--source include/have_myisam.inc | ||
|
||
CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; | ||
INSERT INTO valid_values VALUES(100); | ||
INSERT INTO valid_values VALUES(1); | ||
|
||
CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; | ||
INSERT INTO invalid_values VALUES('\'aaa\''); | ||
INSERT INTO invalid_values VALUES('\'123\''); | ||
|
||
--let $sys_var=ROCKSDB_STATS_RECALC_RATE | ||
--let $read_only=0 | ||
--let $session=0 | ||
--source ../include/rocksdb_sys_var.inc | ||
|
||
DROP TABLE valid_values; | ||
DROP TABLE invalid_values; |
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
Oops, something went wrong.