Skip to content

Commit 10539aa

Browse files
committed
WIP MDEV-39092, and back up non-InnoDB files
1 parent 10f3acb commit 10539aa

10 files changed

Lines changed: 544 additions & 17 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Prepare database
2+
CREATE TABLE tinno (i INTEGER) ENGINE=InnoDB;
3+
INSERT INTO tinno VALUES (1), (2), (3), (4);
4+
CREATE TABLE tariatr (i INTEGER) ENGINE=Aria TRANSACTIONAL=1;
5+
INSERT INTO tariatr VALUES (2), (3), (5), (7);
6+
CREATE TABLE tariant (i INTEGER) ENGINE=Aria TRANSACTIONAL=0;
7+
INSERT INTO tariant VALUES (1), (1), (2), (3), (5);
8+
Back up the database
9+
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
10+
Restore the database
11+
# restart: --datadir=MYSQLTEST_VARDIR/some_directory
12+
Check contents after restore
13+
SELECT * FROM tinno;
14+
i
15+
1
16+
2
17+
3
18+
4
19+
SELECT * FROM tariatr;
20+
i
21+
2
22+
3
23+
5
24+
7
25+
SELECT * FROM tariant;
26+
i
27+
1
28+
1
29+
2
30+
3
31+
5
32+
Warnings:
33+
Error 145 Got error '145 "Table was marked as crashed and should be repaired"' for './test/tariant'
34+
Warning 1034 1 client is using or hasn't closed the table properly
35+
Note 1034 Table is fixed
36+
Restart database in original data directory
37+
# restart
38+
Clean up
39+
DROP TABLE tinno;
40+
DROP TABLE tariatr;
41+
DROP TABLE tariant;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--source include/not_windows.inc
2+
--source include/have_innodb.inc
3+
4+
--echo Prepare database
5+
CREATE TABLE tinno (i INTEGER) ENGINE=InnoDB;
6+
INSERT INTO tinno VALUES (1), (2), (3), (4);
7+
CREATE TABLE tariatr (i INTEGER) ENGINE=Aria TRANSACTIONAL=1;
8+
INSERT INTO tariatr VALUES (2), (3), (5), (7);
9+
CREATE TABLE tariant (i INTEGER) ENGINE=Aria TRANSACTIONAL=0;
10+
INSERT INTO tariant VALUES (1), (1), (2), (3), (5);
11+
12+
--echo Back up the database
13+
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
14+
15+
--echo Restore the database
16+
--disable_query_log
17+
call mtr.add_suppression("InnoDB: Did not find any checkpoint after LSN=");
18+
call mtr.add_suppression("InnoDB: Renaming ib_[0-9]+.log to ib_logfile0");
19+
call mtr.add_suppression("mariadbd: Got error '145 \"Table was marked as crashed and should be repaired\"' for ");
20+
call mtr.add_suppression("Checking table: ");
21+
--enable_query_log
22+
--let $restart_parameters=--datadir=$MYSQLTEST_VARDIR/some_directory
23+
--source include/restart_mysqld.inc
24+
25+
--echo Check contents after restore
26+
SELECT * FROM tinno;
27+
SELECT * FROM tariatr;
28+
SELECT * FROM tariant;
29+
30+
--echo Restart database in original data directory
31+
--let $restart_parameters=
32+
--source include/restart_mysqld.inc
33+
34+
--echo Clean up
35+
DROP TABLE tinno;
36+
DROP TABLE tariatr;
37+
DROP TABLE tariant;
38+
--rmdir $MYSQLTEST_VARDIR/some_directory

mysql-test/suite/backup/backup_innodb,debug.rdiff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
DELETE FROM t;
66
connect backup,localhost,root;
77
+SET DEBUG_SYNC='innodb_backup_start SIGNAL start WAIT_FOR resume';
8-
BACKUP SERVER TO 'MYSQLTEST_VARDIR/some_directory';
8+
BACKUP SERVER TO 'target_directory';
99
+connection default;
1010
+SET DEBUG_SYNC='now WAIT_FOR start';
1111
+INSERT INTO t(a) SELECT * FROM seq_1_to_30000;

mysql-test/suite/backup/backup_innodb.result

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@ CREATE TABLE t(a INT PRIMARY KEY, b CHAR(255) DEFAULT '' NOT NULL, INDEX(b))
22
ENGINE=INNODB;
33
BEGIN;
44
INSERT INTO t SET a=1;
5-
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
5+
BACKUP SERVER TO '$target_directory';
66
ROLLBACK;
77
SELECT * FROM t;
88
a b
99
1
1010
BEGIN;
1111
DELETE FROM t;
1212
connect backup,localhost,root;
13-
BACKUP SERVER TO 'MYSQLTEST_VARDIR/some_directory';
13+
BACKUP SERVER TO 'target_directory';
1414
disconnect backup;
1515
connection default;
1616
ROLLBACK;
1717
SELECT * FROM t;
1818
a b
1919
1
20-
# restart
20+
DELETE FROM t;
21+
# restart: --defaults-file=MYSQLTEST_VARDIR/some_directory/backup.cnf --datadir=MYSQLTEST_VARDIR/some_directory
2122
SELECT * FROM t;
2223
a b
2324
1
25+
DELETE FROM t;
26+
ERROR HY000: Table 't' is read only
27+
# restart
28+
SELECT * FROM t;
29+
a b
2430
DROP TABLE t;

mysql-test/suite/backup/backup_innodb.test

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ ENGINE=INNODB;
77
BEGIN;
88
INSERT INTO t SET a=1;
99

10-
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
11-
--rmdir $MYSQLTEST_VARDIR/some_directory
10+
--let $target_directory=/tmp/some_directory$MTR_COMBINATION_ARCHIVED
11+
# comment out the following line (and some more, including rmdir),
12+
# to test cross-filesystem copy
13+
--let $target_directory=$MYSQLTEST_VARDIR/some_directory
14+
15+
# Clean up after a previous failed test, in case we are retrying.
16+
--error 0,1
17+
--rmdir $target_directory
18+
19+
evalp BACKUP SERVER TO '$target_directory';
20+
--rmdir $target_directory
1221
ROLLBACK;
1322
# BACKUP SERVER will implicitly commit the current transaction
1423
SELECT * FROM t;
@@ -19,31 +28,50 @@ DELETE FROM t;
1928
--connect backup,localhost,root
2029
if ($have_debug) {
2130
SET DEBUG_SYNC='innodb_backup_start SIGNAL start WAIT_FOR resume';
22-
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
23-
send_eval BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
31+
--replace_result $target_directory target_directory
32+
send_eval BACKUP SERVER TO '$target_directory';
2433
--connection default
2534
SET DEBUG_SYNC='now WAIT_FOR start';
2635
INSERT INTO t(a) SELECT * FROM seq_1_to_30000;
2736
SET DEBUG_SYNC='now SIGNAL resume';
2837
--connection backup
38+
# FIXME: outside PMEM we may get ER_ERROR_ON_RENAME
2939
--reap
3040
}
3141
if (!$have_debug) {
32-
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
33-
eval BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
42+
--replace_result $target_directory target_directory
43+
eval BACKUP SERVER TO '$target_directory';
3444
}
3545

3646
--disconnect backup
3747
--connection default
3848
ROLLBACK;
3949
SELECT * FROM t;
50+
DELETE FROM t;
4051

41-
let $datadir=`SELECT @@datadir`;
42-
--source include/shutdown_mysqld.inc
43-
#--rmdir $datadir
44-
#--move_file $MYSQLTEST_VARDIR/some_directory $datadir
45-
--rmdir $MYSQLTEST_VARDIR/some_directory
46-
--source include/start_mysqld.inc
52+
if ($MARIADB_UPGRADE_EXE) {
53+
let target_directory=$target_directory;
54+
perl;
55+
open IN, "<", "$ENV{MYSQLTEST_VARDIR}/my.cnf";
56+
open OUT, ">>", "$ENV{target_directory}/backup.cnf";
57+
print OUT while (<IN>);
58+
close(IN);
59+
close(OUT);
60+
EOF
61+
}
62+
if (!$MARIADB_UPGRADE_EXE) {
63+
--exec cat $MYSQLTEST_VARDIR/my.cnf >> $target_directory/backup.cnf
64+
}
65+
--let $restart_parameters=--defaults-file=$target_directory/backup.cnf --datadir=$target_directory
66+
--source include/restart_mysqld.inc
4767

68+
SELECT * FROM t;
69+
# we must have started up with nonzero innodb_log_recovery_target
70+
--error ER_OPEN_AS_READONLY
71+
DELETE FROM t;
72+
--let $restart_parameters=
73+
--source include/restart_mysqld.inc
4874
SELECT * FROM t;
4975
DROP TABLE t;
76+
77+
--rmdir $target_directory

storage/innobase/handler/backup_innodb.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ class InnoDB_backup
594594
@param c offset of the FILE_CHECKPOINT mini-transaction
595595
@return error code
596596
@retval 0 on success */
597-
static int write_checkpoint(int dst, uint64_t c) noexcept
597+
static int write_checkpoint(IF_WIN(HANDLE,int) dst, uint64_t c) noexcept
598598
{
599599
#ifdef _WIN32
600600
using tpool::pwrite;

storage/maria/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ SET(ARIA_SOURCES ma_init.c ma_open.c ma_extra.c ma_info.c ma_rkey.c
4545
ha_maria.h maria_def.h ma_recovery_util.c ma_servicethread.c
4646
ma_norec.c
4747
ma_crypt.c ma_backup.c
48+
ma_backup.cc ma_backup.h
4849
)
4950

5051
IF(APPLE)

storage/maria/ha_maria.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <myisampack.h>
2424
#include <my_bit.h>
2525
#include "ha_maria.h"
26+
#include "ma_backup.h"
2627
#include "trnman_public.h"
2728
#include "trnman.h"
2829

@@ -3942,6 +3943,9 @@ static int ha_maria_init(void *p)
39423943
maria_hton->prepare_for_backup= maria_prepare_for_backup;
39433944
maria_hton->end_backup= maria_end_backup;
39443945
maria_hton->update_optimizer_costs= aria_update_optimizer_costs;
3946+
maria_hton->backup_start= aria_backup_start;
3947+
maria_hton->backup_step= aria_backup_step;
3948+
maria_hton->backup_end= aria_backup_end;
39453949

39463950
/* TODO: decide if we support Maria being used for log tables */
39473951
maria_hton->flags= (HTON_CAN_RECREATE | HTON_SUPPORT_LOG_TABLES |

0 commit comments

Comments
 (0)