Skip to content

Commit 6e13886

Browse files
Merge pull request #5415 from percona-ysorokin/dev/PS-9322-8.0-undo_truncation_super_read_only
PS-9322 fix: With super_read_only=1, undo truncation cannot update DD and leaves orphan truncate log files (8.0)
2 parents 341c994 + 22a7caa commit 6e13886

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the connection metadata repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START REPLICA; see the 'START REPLICA Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
# 1: Set replica parameters
7+
set @orig_max_undo_log_size = @@innodb_max_undo_log_size;
8+
set @orig_truncate_frequency = @@innodb_purge_rseg_truncate_frequency;
9+
set global innodb_max_undo_log_size=10485760;
10+
set global innodb_purge_rseg_truncate_frequency=1;
11+
set global super_read_only=1;
12+
13+
# 2: Preparing database
14+
create table t1(id int);
15+
create procedure insert_data()
16+
begin
17+
declare i int;
18+
set i=1;
19+
while(i<=500000) do
20+
insert into t1(id) values(i);
21+
set i=i+1;
22+
end while;
23+
end;$$
24+
begin;
25+
# 3: Inserting data, filling undo logs
26+
call insert_data();
27+
# 4: commit, trigger undo log truncation
28+
commit;
29+
select tablespace_name, file_name from information_schema.files
30+
where file_name like "%undo%";
31+
TABLESPACE_NAME FILE_NAME
32+
innodb_undo_001 ./undo_001
33+
innodb_undo_002 ./undo_002
34+
select name, row_format from information_schema.innodb_tablespaces
35+
where name like '%undo%';
36+
name row_format
37+
innodb_undo_001 Undo
38+
innodb_undo_002 Undo
39+
# 5: undo files undo_001 and undo_002 are expected to exist,
40+
# while files undo_001_trunc.log and undo_002_trunc.log are expected to not exist
41+
undo_001
42+
undo_002
43+
set global innodb_max_undo_log_size=@orig_max_undo_log_size;
44+
set global innodb_purge_rseg_truncate_frequency=@orig_truncate_frequency;
45+
set global super_read_only = 0;
46+
set global read_only = 0;
47+
drop procedure insert_data;
48+
drop table t1;
49+
include/rpl_end.inc
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--source include/have_debug.inc
2+
# The test requires a debug build, in order to trigger
3+
# a purge using innodb_purge_run_now=ON .
4+
5+
--source include/master-slave.inc
6+
7+
--echo # 1: Set replica parameters
8+
connection slave;
9+
10+
set @orig_max_undo_log_size = @@innodb_max_undo_log_size;
11+
set @orig_truncate_frequency = @@innodb_purge_rseg_truncate_frequency;
12+
13+
# Trigger truncation of undo log files once they occupy more than 10MB
14+
# which is the minimum value of innodb_max_undo_log_size
15+
set global innodb_max_undo_log_size=10485760;
16+
set global innodb_purge_rseg_truncate_frequency=1;
17+
set global super_read_only=1;
18+
19+
--echo
20+
--echo # 2: Preparing database
21+
connection master;
22+
23+
create table t1(id int);
24+
25+
delimiter $$;
26+
create procedure insert_data()
27+
begin
28+
declare i int;
29+
set i=1;
30+
while(i<=500000) do
31+
insert into t1(id) values(i);
32+
set i=i+1;
33+
end while;
34+
end;$$
35+
delimiter ;$$
36+
37+
begin;
38+
39+
--echo # 3: Inserting data, filling undo logs
40+
call insert_data();
41+
42+
--echo # 4: commit, trigger undo log truncation
43+
commit;
44+
sync_slave_with_master;
45+
46+
connection slave;
47+
48+
--source include/wait_innodb_all_purged.inc
49+
50+
51+
# expecting two undo files, and no undo_*_trunc.log files remaining
52+
53+
select tablespace_name, file_name from information_schema.files
54+
where file_name like "%undo%";
55+
select name, row_format from information_schema.innodb_tablespaces
56+
where name like '%undo%';
57+
58+
let $MYSQLD_DATADIR = `select @@datadir`;
59+
60+
--echo # 5: undo files undo_001 and undo_002 are expected to exist,
61+
--echo # while files undo_001_trunc.log and undo_002_trunc.log are expected to not exist
62+
list_files $MYSQLD_DATADIR undo_0*;
63+
64+
set global innodb_max_undo_log_size=@orig_max_undo_log_size;
65+
set global innodb_purge_rseg_truncate_frequency=@orig_truncate_frequency;
66+
set global super_read_only = 0;
67+
set global read_only = 0;
68+
connection master;
69+
drop procedure insert_data;
70+
drop table t1;
71+
--source include/rpl_end.inc

storage/innobase/srv/srv0srv.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
8080
#include "row0log.h"
8181
#include "row0mysql.h"
8282
#include "sql/current_thd.h"
83+
#include "sql/sql_class.h"
8384
#include "sql_thd_internal_api.h"
8485
#include "srv0mon.h"
8586

@@ -3438,6 +3439,9 @@ void srv_purge_coordinator_thread() {
34383439

34393440
THD *thd = create_internal_thd();
34403441

3442+
// Allow purge in read only mode as well.
3443+
thd->set_skip_readonly_check();
3444+
34413445
purge_sys->is_this_a_purge_thread = true;
34423446

34433447
ulint n_total_purged = ULINT_UNDEFINED;

0 commit comments

Comments
 (0)