Skip to content

Commit 584cb35

Browse files
AliSQLAliSQL
authored andcommitted
[feature] Issue#35: keep all FT files consistent when checkpoint lock is held
AliSQLBackup depends on tokudb_checkpoint_lock to implement hot backup, but invoking ft_close() to a FT file during backup will break the consistency between this FT and the others in the final backup directory, even when checkpoint lock is held, becasue the header of FT is updated by ft_close(). This patch checks whether we are in backup before closing FT, if in backup, don't close FT.
1 parent fc7e697 commit 584cb35

10 files changed

Lines changed: 655 additions & 8 deletions

File tree

mysql-test/suite/rds/r/tokudb.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ MAX(c1)
277277
3
278278
show status like '%tokudb_rows%';
279279
Variable_name Value
280-
Tokudb_rows_inserted 41
281-
Tokudb_rows_read 98
282-
Tokudb_rows_deleted 8
283-
Tokudb_rows_updated 19
280+
Tokudb_rows_inserted ####
281+
Tokudb_rows_read ####
282+
Tokudb_rows_deleted ####
283+
Tokudb_rows_updated ####
284284
show variables like 'tokudb_cpu_nums';
285285
Variable_name Value
286286
tokudb_cpu_nums 0
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
=====1) hotbackup test=====
2+
CREATE TABLE test.t1 (c1 INT PRIMARY KEY, c2 INT, c3 INT) ENGINE=TOKUDB;
3+
INSERT INTO test.t1 VALUES(1111,1111,11111);
4+
CREATE TABLE test.t11 (c1 INT PRIMARY KEY, c2 INT, c3 INT) ENGINE=TOKUDB;
5+
CREATE TABLE test.t2 (c1 INT PRIMARY KEY, c2 INT) ENGINE=TOKUDB;
6+
INSERT INTO test.t2 VALUES(1122,1122);
7+
SET GLOBAL tokudb_checkpoint_on_flush_logs=ON;
8+
FLUSH LOGS;
9+
SET GLOBAL tokudb_checkpoint_on_flush_logs=OFF;
10+
INSERT INTO test.t1 VALUES(1,1,1);
11+
SET GLOBAL TOKUDB_CHECKPOINT_LOCK=ON;
12+
CREATE TABLE test.t22 (c1 INT PRIMARY KEY, c2 INT) ENGINE=TOKUDB;
13+
INSERT INTO test.t22 VALUES(1,1);
14+
INSERT INTO test.t1 VALUES(2,2,2);
15+
FLUSH TABLES WITH READ LOCK;
16+
UNLOCK TABLES;
17+
conn2 write(22,22,22), this row can't visible in new backup instance
18+
INSERT INTO test.t1 VALUES(22222,22222,22222);
19+
FLUSH TABLES;
20+
ALTER TABLE test.t11 RENAME test.t111;
21+
DROP TABLE test.t22;
22+
DROP TABLE test.t111;
23+
SET GLOBAL TOKUDB_CHECKPOINT_LOCK=OFF;
24+
shutdown server
25+
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TOKUDB_FILE_MAP WHERE TABLE_SCHEMA='test' AND TABLE_DICTIONARY_NAME='main';
26+
TABLE_NAME
27+
t1
28+
t11
29+
t2
30+
t22
31+
OPTIMIZE TABLE test.t1;
32+
Table Op Msg_type Msg_text
33+
test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
34+
test.t1 optimize status OK
35+
SELECT * FROM test.t1;
36+
c1 c2 c3
37+
1 1 1
38+
2 2 2
39+
1111 1111 11111
40+
SELECT * FROM test.t2;
41+
c1 c2
42+
1122 1122
43+
DROP TABLE test.t1;
44+
DROP TABLE test.t2;
45+
=====2) crash and recover test=====
46+
CREATE TABLE test.t2 (c1 INT, c2 INT, PRIMARY KEY(c1), CLUSTERING KEY(c2)) ENGINE=TOKUDB;
47+
1
48+
SELECT COUNT(*) FROM test.t2;
49+
COUNT(*)
50+
1000
51+
DROP TABLE test.t2;
52+
=====3) create empty table and shutdown with checkpoint lock=====
53+
CREATE TABLE test.t1 (c1 INT, c2 INT, PRIMARY KEY(c1), CLUSTERING KEY(c2)) ENGINE=TOKUDB;
54+
CREATE TABLE test.t2 (c1 INT) ENGINE=TOKUDB;
55+
shutdown server
56+
SELECT * FROM test.t1;
57+
c1 c2
58+
SELECT * FROM test.t2;
59+
c1
60+
CREATE TABLE test.t3 (c1 INT) ENGINE=TOKUDB;
61+
INSERT INTO test.t3 VALUES(1);
62+
shutdown server
63+
SELECT * FROM test.t3;
64+
c1
65+
1
66+
DROP TABLE test.t1;
67+
DROP TABLE test.t2;
68+
DROP TABLE test.t3;
69+
=====4) alter table with checkpoint lock=====
70+
CREATE TABLE test.t1 (c1 INT PRIMARY KEY, c2 INT) ENGINE=TOKUDB;
71+
INSERT INTO test.t1 VALUES(1,1);
72+
SET GLOBAL TOKUDB_CHECKPOINT_LOCK=ON;
73+
FLUSH TABLES WITH READ LOCK;
74+
UNLOCK TABLES;
75+
ALTER TABLE test.t1 ADD COLUMN `c3` INT;
76+
INSERT INTO test.t1 VALUES(2,2,3);
77+
SET GLOBAL TOKUDB_CHECKPOINT_LOCK=OFF;
78+
shutdown server
79+
OPTIMIZE TABLE test.t1;
80+
Table Op Msg_type Msg_text
81+
test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
82+
test.t1 optimize status OK
83+
SELECT * FROM test.t1;
84+
c1 c2
85+
1 1
86+
DROP TABLE test.t1;
87+
=====5) kill insert/alter/add index when checkpoint lock ON=====
88+
shutdown server
89+
CREATE TABLE test.t1 (c1 INT PRIMARY KEY, c2 INT) ENGINE=TOKUDB;
90+
SET GLOBAL TOKUDB_CHECKPOINT_LOCK=ON;
91+
CREATE TABLE test.t3 (c1 INT PRIMARY KEY, c2 INT) ENGINE=TOKUDB;
92+
ALTER TABLE test.t1 ADD COLUMN `c3` INT;
93+
INSERT INTO test.t1 VALUES(2,2,3);
94+
ALTER TABLE test.t3 ADD INDEX idx_c1c2(c1, c2);
95+
1
96+
SHOW CREATE TABLE test.t1;
97+
Table Create Table
98+
t1 CREATE TABLE `t1` (
99+
`c1` int(11) NOT NULL,
100+
`c2` int(11) DEFAULT NULL,
101+
`c3` int(11) DEFAULT NULL,
102+
PRIMARY KEY (`c1`)
103+
) ENGINE=TokuDB DEFAULT CHARSET=latin1
104+
SHOW CREATE TABLE test.t3;
105+
Table Create Table
106+
t3 CREATE TABLE `t3` (
107+
`c1` int(11) NOT NULL,
108+
`c2` int(11) DEFAULT NULL,
109+
PRIMARY KEY (`c1`),
110+
KEY `idx_c1c2` (`c1`,`c2`)
111+
) ENGINE=TokuDB DEFAULT CHARSET=latin1
112+
DROP TABLE test.t1;
113+
DROP TABLE test.t3;

mysql-test/suite/rds/t/tokudb.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ SELECT MAX(c1) FROM t3;
182182
--let $innodb_status =`show engine tokudb status`
183183
--sleep 2
184184
--let $innodb_status =`show engine tokudb status`
185+
--replace_column 2 ####
185186
show status like '%tokudb_rows%';
186187
show variables like 'tokudb_cpu_nums';
187188

0 commit comments

Comments
 (0)