Skip to content

Commit

Permalink
auto deletion of apply logs based on sysvars
Browse files Browse the repository at this point in the history
Summary:
Apply logs are the new trx log on raft followers. We should be aggressive in
reclaiming space consumed by apply logs. This diff adds the support for auto
deletion of apply logs.

Approach:
1. Two new sysvars are added apply_log_retention_num (defaulted to 10 files) and
apply_log_retention_duration (defaulted to 15 mins). These impose (soft) limits
on minimum number of apply logs that need to be retained (in terms of
'number-of-files') and minimum duration of retention (in terms of minutes since
last modified).

2. Auto deletion is triggered whenever an apply log gets rotated after commit of
a trx (in ordered_commit) as part of max_binlog_size check. Auto deletion will
trigger if there are more than "apply_log_retention_num" number of files. The
files which were last modified more than "apply_log_retention_duration" minutes
in the past will be auto deleted (provided these files are not being actively
used currently)

3. To keep things simple, the new limits are only soft limits. Pathological
cases like a user triggering multiple 'flush logs' and system not seeing any
trx activity for a prolonged period is not handled.

Reviewed By: anirbanr-fb

Differential Revision: D22095395

fbshipit-source-id: 29a4040cdcb
  • Loading branch information
bhatvinay authored and facebook-github-bot committed Oct 6, 2020
1 parent 241e01a commit d7dbc9d
Show file tree
Hide file tree
Showing 19 changed files with 1,048 additions and 8 deletions.
7 changes: 7 additions & 0 deletions mysql-test/r/mysqld--help-notwin-profiling.result
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ The following options may be given as the first argument:
--apply-log-index=name
The location and name to use for the file that keeps a
list of the last apply logs for raft
--apply-log-retention-duration[=#]
Minimum duration (mins) that apply logs need to be
retained.
--apply-log-retention-num[=#]
Minimum number of apply logs that need to be retained.
--async-query-counter
Parsing async query info and collection of async query
statistics
Expand Down Expand Up @@ -2296,6 +2301,8 @@ allow-noncurrent-db-rw ON
allow-suspicious-udfs FALSE
apply-log (No default value)
apply-log-index (No default value)
apply-log-retention-duration 15
apply-log-retention-num 10
async-query-counter FALSE
audit-fb-json-functions
audit-instrumented-event AUDIT_OFF
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ The following options may be given as the first argument:
--apply-log-index=name
The location and name to use for the file that keeps a
list of the last apply logs for raft
--apply-log-retention-duration[=#]
Minimum duration (mins) that apply logs need to be
retained.
--apply-log-retention-num[=#]
Minimum number of apply logs that need to be retained.
--async-query-counter
Parsing async query info and collection of async query
statistics
Expand Down Expand Up @@ -2294,6 +2299,8 @@ allow-noncurrent-db-rw ON
allow-suspicious-udfs FALSE
apply-log (No default value)
apply-log-index (No default value)
apply-log-retention-duration 15
apply-log-retention-num 10
async-query-counter FALSE
audit-fb-json-functions
audit-instrumented-event AUDIT_OFF
Expand Down
343 changes: 343 additions & 0 deletions mysql-test/suite/rpl_raft/r/rpl_raft_auto_purge_apply_logs.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,343 @@
include/raft_3_node.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.
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]
show status like 'rpl_raft_role';
Variable_name Value
Rpl_raft_role LEADER
show status like 'rpl_raft_role';
Variable_name Value
Rpl_raft_role FOLLOWER
show status like 'rpl_raft_role';
Variable_name Value
Rpl_raft_role FOLLOWER
create table t1 (a int primary key);
"Inserting rows into t1 on server_1"
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
select count(*) from t1;
count(*)
20
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
"Verifying apply logs on follower: server_2"
show binary logs;
Log_name File_size
apply-logs-13001.000001 #
apply-logs-13001.000002 #
apply-logs-13001.000003 #
apply-logs-13001.000004 #
apply-logs-13001.000005 #
apply-logs-13001.000006 #
apply-logs-13001.000007 #
apply-logs-13001.000008 #
apply-logs-13001.000009 #
apply-logs-13001.000010 #
apply-logs-13001.000011 #
apply-logs-13001.000012 #
apply-logs-13001.000013 #
apply-logs-13001.000014 #
apply-logs-13001.000015 #
apply-logs-13001.000016 #
apply-logs-13001.000017 #
apply-logs-13001.000018 #
apply-logs-13001.000019 #
apply-logs-13001.000020 #
apply-logs-13001.000021 #
apply-logs-13001.000022 #
apply-logs-13001.000023 #
"Verifying apply logs on follower: server_3"
show binary logs;
Log_name File_size
apply-logs-13002.000001 #
apply-logs-13002.000002 #
apply-logs-13002.000003 #
apply-logs-13002.000004 #
apply-logs-13002.000005 #
apply-logs-13002.000006 #
apply-logs-13002.000007 #
apply-logs-13002.000008 #
apply-logs-13002.000009 #
apply-logs-13002.000010 #
apply-logs-13002.000011 #
apply-logs-13002.000012 #
apply-logs-13002.000013 #
apply-logs-13002.000014 #
apply-logs-13002.000015 #
apply-logs-13002.000016 #
apply-logs-13002.000017 #
apply-logs-13002.000018 #
apply-logs-13002.000019 #
apply-logs-13002.000020 #
apply-logs-13002.000021 #
apply-logs-13002.000022 #
apply-logs-13002.000023 #
"Sleep for 70s to expire the logs"
select sleep(70);
sleep(70)
0
"Inserting another row on leader: server_1. This will trigger auto purge on followers"
insert into t1 values(21);
select count(*) from t1;
count(*)
21
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
"Verifying apply logs on follower: server_2"
select count(*) from t1;
count(*)
21
show binary logs;
Log_name File_size
apply-logs-13001.000015 #
apply-logs-13001.000016 #
apply-logs-13001.000017 #
apply-logs-13001.000018 #
apply-logs-13001.000019 #
apply-logs-13001.000020 #
apply-logs-13001.000021 #
apply-logs-13001.000022 #
apply-logs-13001.000023 #
apply-logs-13001.000024 #
"Verifying apply logs on follower: server_3"
select count(*) from t1;
count(*)
21
show binary logs;
Log_name File_size
apply-logs-13002.000015 #
apply-logs-13002.000016 #
apply-logs-13002.000017 #
apply-logs-13002.000018 #
apply-logs-13002.000019 #
apply-logs-13002.000020 #
apply-logs-13002.000021 #
apply-logs-13002.000022 #
apply-logs-13002.000023 #
apply-logs-13002.000024 #
"Transfering leadership: server_1 -> server_2"
include/raft_promote_to_leader.inc
select sleep(10);
sleep(10)
0
select variable_value from information_schema.global_status where variable_name = 'Rpl_raft_role';
variable_value
LEADER
"Inserting some rows into t1 from leader: server_2"
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
"Sleep for 70s to expire the logs"
select sleep(70);
sleep(70)
0
"Inserting another row on leader: server_2. This will trigger auto purge on followers"
insert into t1 values(41);
select count(*) from t1;
count(*)
41
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
"Verifying apply logs on follower: server_1"
select count(*) from t1;
count(*)
41
show binary logs;
Log_name File_size
apply-logs-13000.000012 #
apply-logs-13000.000013 #
apply-logs-13000.000014 #
apply-logs-13000.000015 #
apply-logs-13000.000016 #
apply-logs-13000.000017 #
apply-logs-13000.000018 #
apply-logs-13000.000019 #
apply-logs-13000.000020 #
apply-logs-13000.000021 #
"Verifying apply logs on follower: server_3"
select count(*) from t1;
count(*)
41
show binary logs;
Log_name File_size
apply-logs-13002.000036 #
apply-logs-13002.000037 #
apply-logs-13002.000038 #
apply-logs-13002.000039 #
apply-logs-13002.000040 #
apply-logs-13002.000041 #
apply-logs-13002.000042 #
apply-logs-13002.000043 #
apply-logs-13002.000044 #
apply-logs-13002.000045 #
"Transfering leadership: server_2 -> server_1"
include/raft_promote_to_leader.inc
select variable_value from information_schema.global_status where variable_name = 'Rpl_raft_role';
variable_value
LEADER
"Inserting more rows into t1 from server_1"
select sleep(10);
sleep(10)
0
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
"Sleep for 70s to expire the logs"
select sleep(70);
sleep(70)
0
"Inserting another row on leader: server_1. This will trigger auto purge on followers"
insert into t1 values(61);
select count(*) from t1;
count(*)
61
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
"Verifying apply logs on follower: server_2"
select count(*) from t1;
count(*)
61
show binary logs;
Log_name File_size
apply-logs-13001.000012 #
apply-logs-13001.000013 #
apply-logs-13001.000014 #
apply-logs-13001.000015 #
apply-logs-13001.000016 #
apply-logs-13001.000017 #
apply-logs-13001.000018 #
apply-logs-13001.000019 #
apply-logs-13001.000020 #
apply-logs-13001.000021 #
"Verifying apply logs on follower: server_3"
select count(*) from t1;
count(*)
61
show binary logs;
Log_name File_size
apply-logs-13002.000057 #
apply-logs-13002.000058 #
apply-logs-13002.000059 #
apply-logs-13002.000060 #
apply-logs-13002.000061 #
apply-logs-13002.000062 #
apply-logs-13002.000063 #
apply-logs-13002.000064 #
apply-logs-13002.000065 #
apply-logs-13002.000066 #
drop table t1;
include/sync_slave_sql_with_master.inc
include/sync_slave_sql_with_master.inc
include/rpl_end.inc
Loading

0 comments on commit d7dbc9d

Please sign in to comment.