summaryrefslogtreecommitdiffstats
path: root/storage/rocksdb/mysql-test/rocksdb/t/add_index_inplace_crash.test
blob: 4f34cbe8f8a53b11dbcd28dcd05f534d104f88a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--source include/have_rocksdb.inc
--source include/have_debug.inc
--source include/have_partition.inc
--source include/not_valgrind.inc

--disable_warnings
drop table if exists t1;
--enable_warnings

#
# test crash recovery
#

CREATE TABLE t1 (a INT, b INT, KEY ka(a), KEY kab(a,b)) ENGINE=RocksDB;
INSERT INTO t1 (a, b) VALUES (1, 5);
INSERT INTO t1 (a, b) VALUES (2, 6);
INSERT INTO t1 (a, b) VALUES (3, 7);

--echo # crash_during_online_index_creation
flush logs;

--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
SET SESSION debug_dbug="+d,crash_during_online_index_creation";
--error 2013
ALTER TABLE t1 ADD INDEX kb(b), ALGORITHM=INPLACE;

--enable_reconnect
--source include/wait_until_connected_again.inc

SET SESSION debug_dbug="-d,crash_during_online_index_creation";

SHOW CREATE TABLE t1;
CHECK TABLE t1;

DROP TABLE t1;

#
# Test crash recovery with partitioned tables
#
CREATE TABLE t1 (i INT, j INT, k INT, PRIMARY KEY (i), KEY(j)) ENGINE = ROCKSDB PARTITION BY KEY(i) PARTITIONS 4;

--disable_query_log
let $max = 100;
let $i = 1;
while ($i <= $max) {
  let $insert = INSERT INTO t1 VALUES ($i, $i, $i);
  inc $i;
  eval $insert;
}
--enable_query_log

--echo # crash_during_index_creation_partition
flush logs;

--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
SET SESSION debug_dbug="+d,crash_during_index_creation_partition";
--error 2013
ALTER TABLE t1 ADD INDEX kij(i,j), ALGORITHM=INPLACE;

--enable_reconnect
--source include/wait_until_connected_again.inc

SET SESSION debug_dbug="-d,crash_during_index_creation_partition";

SHOW CREATE TABLE t1;

# here, the index numbers should be higher because previously 4 index numbers
# were allocated for the partitioned table
ALTER TABLE t1 ADD INDEX kij(i,j), ALGORITHM=INPLACE;

SELECT * FROM t1 ORDER BY i LIMIT 10;
SELECT COUNT(*) FROM t1;

DROP TABLE t1;

#
# Test rollback on partitioned tables for inplace alter
#
CREATE TABLE t1 (i INT, j INT, k INT, PRIMARY KEY (i), KEY(j)) ENGINE = ROCKSDB PARTITION BY KEY(i) PARTITIONS 4;

--disable_query_log
let $max = 100;
let $i = 1;
while ($i <= $max) {
  let $insert = INSERT INTO t1 VALUES ($i, $i, $i);
  inc $i;
  eval $insert;
}
--enable_query_log

--echo # crash_during_index_creation_partition
flush logs;

SET SESSION debug_dbug="+d,myrocks_simulate_index_create_rollback";

--error 1105
ALTER TABLE t1 ADD INDEX kij(i,j), ALGORITHM=INPLACE;
SET SESSION debug_dbug="-d,myrocks_simulate_index_create_rollback";
SHOW CREATE TABLE t1;

# here, the index numbers should be higher because previously 4 index numbers
# were allocated for the partitioned table
ALTER TABLE t1 ADD INDEX kij(i,j), ALGORITHM=INPLACE;

SHOW CREATE TABLE t1;
SELECT COUNT(*) FROM t1;

DROP TABLE t1;

# Cleanup temporary #sql files.  In the future server will remove these
# automatically but for now we need to do the delete explicit

--disable_query_log
--disable_result_log
let $datadir=`select @@datadir`;
--remove_files_wildcard $datadir/test #sql*
--enable_result_log
--enable_query_log