Skip to content

Commit

Permalink
Fix issues 1200 and 1295, add rocksdb_compact_lzero_now global variab…
Browse files Browse the repository at this point in the history
…le (facebook#1309)

Summary:
This fixes issue 1295 and has a workaround for issue 1200. facebook#1200
facebook#1295

The fix for issue 1295 is to get the value of the base level from RocksDB rather than assuming that L0 compacts into L1 because L1 might not be the base level when dynamic leveled compaction is used -- in that case the base level can be Ln where n > 1 because L1 isn't needed yet.

There are two workarounds for issue 1200. The hacky one is to sleep for 1 second between requesting memtable flush and L0 -> base_level compaction.

The alternative is to add a new global variable, rocksdb_compact_lzero_now, that when set will request L0 -> base_level compaction. This allows a client to first set rocksdb_force_flush_memtable_now, wait for that to finish, then set rocksdb_compact_lzero_now.

Other changes:
* rocksdb_force_flush_memtable_now default value changed to OFF to match what is done for rocksdb_force_flush_memtable_and_lzero_now and rocksdb_compact_lzero_now
* confirm that the value to which these variables are set can be parsed, that wasn't done for all of them
* don't raise an error when these are set to OFF, that will be a no-op

Note: these variables are triggers, an action is taken when this is done: set global var = ON | true | 1

But these variables always show the value 0 (OFF, false). Their value doesn't change.

Pull Request resolved: facebook#1309

Differential Revision: D45789784
  • Loading branch information
mdcallag authored and inikep committed May 15, 2024
1 parent 8862085 commit d8e4501
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 49 deletions.
6 changes: 4 additions & 2 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,8 @@ The following options may be given as the first argument:
(Defaults to on; use --skip-rocksdb-commit-time-batch-for-recovery to disable.)
--rocksdb-compact-cf=name
Compact column family
--rocksdb-compact-lzero-now
Compacts all L0 files.
--rocksdb-compaction-history[=name]
Enable or disable ROCKSDB_COMPACTION_HISTORY plugin.
Possible values are ON, OFF, FORCE (don't start if the
Expand Down Expand Up @@ -2147,7 +2149,6 @@ The following options may be given as the first argument:
--rocksdb-force-flush-memtable-now
Forces memstore flush which may block all write requests
so be careful
(Defaults to on; use --skip-rocksdb-force-flush-memtable-now to disable.)
--rocksdb-force-index-records-in-range=#
Used to override the result of records_in_range() when
FORCE INDEX is used.
Expand Down Expand Up @@ -3633,6 +3634,7 @@ rocksdb-column-default-value-as-expression TRUE
rocksdb-commit-in-the-middle FALSE
rocksdb-commit-time-batch-for-recovery TRUE
rocksdb-compact-cf
rocksdb-compact-lzero-now FALSE
rocksdb-compaction-history ON
rocksdb-compaction-readahead-size 2097152
rocksdb-compaction-sequential-deletes 0
Expand Down Expand Up @@ -3686,7 +3688,7 @@ rocksdb-flush-log-at-trx-commit 1
rocksdb-force-compute-memtable-stats TRUE
rocksdb-force-compute-memtable-stats-cachetime 60000000
rocksdb-force-flush-memtable-and-lzero-now FALSE
rocksdb-force-flush-memtable-now TRUE
rocksdb-force-flush-memtable-now FALSE
rocksdb-force-index-records-in-range 0
rocksdb-global-info ON
rocksdb-ignore-unknown-options TRUE
Expand Down
3 changes: 2 additions & 1 deletion mysql-test/suite/rocksdb/r/rocksdb.result
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ rocksdb_column_default_value_as_expression ON
rocksdb_commit_in_the_middle OFF
rocksdb_commit_time_batch_for_recovery ON
rocksdb_compact_cf
rocksdb_compact_lzero_now OFF
rocksdb_compaction_readahead_size 2097152
rocksdb_compaction_sequential_deletes 0
rocksdb_compaction_sequential_deletes_count_sd OFF
Expand Down Expand Up @@ -984,7 +985,7 @@ rocksdb_flush_log_at_trx_commit 1
rocksdb_force_compute_memtable_stats ON
rocksdb_force_compute_memtable_stats_cachetime 0
rocksdb_force_flush_memtable_and_lzero_now OFF
rocksdb_force_flush_memtable_now ON
rocksdb_force_flush_memtable_now OFF
rocksdb_force_index_records_in_range 0
rocksdb_ignore_unknown_options ON
rocksdb_index_type kBinarySearch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('false');
CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;
SET @start_global_value = @@global.ROCKSDB_COMPACT_LZERO_NOW;
SELECT @start_global_value;
@start_global_value
0
'# Setting to valid values in global scope#'
"Trying to set variable @@global.ROCKSDB_COMPACT_LZERO_NOW to 1"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = 1;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_COMPACT_LZERO_NOW to on"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = on;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_COMPACT_LZERO_NOW to true"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = true;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_COMPACT_LZERO_NOW to 0"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = 0;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_COMPACT_LZERO_NOW to off"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = off;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_COMPACT_LZERO_NOW to false"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = false;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
"Trying to set variable @@session.ROCKSDB_COMPACT_LZERO_NOW to 444. It should fail because it is not session."
SET @@session.ROCKSDB_COMPACT_LZERO_NOW = 444;
ERROR HY000: Variable 'rocksdb_compact_lzero_now' is a GLOBAL variable and should be set with SET GLOBAL
'# Testing with invalid values in global scope #'
SET @@global.ROCKSDB_COMPACT_LZERO_NOW = @start_global_value;
SELECT @@global.ROCKSDB_COMPACT_LZERO_NOW;
@@global.ROCKSDB_COMPACT_LZERO_NOW
0
DROP TABLE valid_values;
DROP TABLE invalid_values;
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('false');
CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;
SET @start_global_value = @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
SELECT @start_global_value;
Expand All @@ -18,6 +21,26 @@ SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW to on"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = on;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW to true"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = true;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW to 0"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = 0;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
Expand All @@ -28,8 +51,18 @@ SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW to on"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = on;
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW to off"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = off;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW to false"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW = false;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_AND_LZERO_NOW
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,82 @@ CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('false');
CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO invalid_values VALUES(0);
INSERT INTO invalid_values VALUES('off');
INSERT INTO invalid_values VALUES('false');
SET @start_global_value = @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
SELECT @start_global_value;
@start_global_value
1
0
'# Setting to valid values in global scope#'
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to 1"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = 1;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to on"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = on;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to true"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = true;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
"Trying to set variable @@session.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to 444. It should fail because it is not session."
SET @@session.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = 444;
ERROR HY000: Variable 'rocksdb_force_flush_memtable_now' is a GLOBAL variable and should be set with SET GLOBAL
'# Testing with invalid values in global scope #'
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to 0"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = 0;
Got one of the listed errors
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to off"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = off;
Got one of the listed errors
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
0
"Trying to set variable @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to false"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = false;
Got one of the listed errors
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = DEFAULT;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
0
"Trying to set variable @@session.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW to 444. It should fail because it is not session."
SET @@session.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = 444;
ERROR HY000: Variable 'rocksdb_force_flush_memtable_now' is a GLOBAL variable and should be set with SET GLOBAL
'# Testing with invalid values in global scope #'
SET @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW = @start_global_value;
SELECT @@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW;
@@global.ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
1
0
DROP TABLE valid_values;
DROP TABLE invalid_values;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--source include/have_rocksdb.inc

CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('false');

CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;

--let $sys_var=ROCKSDB_COMPACT_LZERO_NOW
--let $read_only=0
--let $session=0
--let $sticky=1
--source ../include/rocksdb_sys_var.inc

DROP TABLE valid_values;
DROP TABLE invalid_values;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('false');

CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('false');

CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO invalid_values VALUES(0);
INSERT INTO invalid_values VALUES('off');
INSERT INTO invalid_values VALUES('false');

--let $sys_var=ROCKSDB_FORCE_FLUSH_MEMTABLE_NOW
--let $read_only=0
Expand Down
Loading

0 comments on commit d8e4501

Please sign in to comment.