1-- source include/have_ndb.inc
2-- source include/have_ndb_debug.inc
3-- source suite/ndb/include/backup_restore_setup.inc
4
5--disable_query_log
6set @old_ndb_autoincrement_prefetch_sz = @@session.ndb_autoincrement_prefetch_sz;
7set ndb_autoincrement_prefetch_sz = 1;
8--enable_query_log
9
10use test;
11
12--echo ********************************
13--echo Autoincrement extend pk
14--echo Prepare table + backup with log
15--echo ********************************
16
17create table test.autokey (
18  ak   bigint unsigned not null auto_increment,
19  ok   bigint unsigned not null,
20  data varchar(200) not null,
21  primary key(ak),
22  key(ok))
23engine=ndb;
24
25insert into test.autokey (ok,data) values
26  (1, "1-1"),
27  (1, "1-2"),
28  (1, "1-3"),
29  (1, "1-4"),
30  (2, "2-1"),
31  (2, "2-2"),
32  (2, "2-3"),
33  (3, "3-1"),
34  (3, "3-2"),
35  (3, "3-3");
36
37select * from test.autokey order by data;
38
39--echo Stall backup completion
40--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "all error 10039" >> $NDB_TOOLS_OUTPUT 2>&1
41--echo Run backup
42--source suite/ndb/t/ndb_backup_nowait_start.inc
43
44--echo Make some changes which will be logged...
45insert into test.autokey (ok,data) values
46  (4, "4-1"),
47  (4, "4-2"),
48  (4, "4-3"),
49  (5, "5-1"),
50  (5, "5-2");
51
52update test.autokey set data = concat(data, "-mk2");
53
54# Make some changes to all non-pk cols
55# Null change to ok
56update test.autokey set ok=ok, data=concat(data,"-1");
57# Non-null change to ok, still unique (transactionally)
58# update test.autokey set ok=ok+1, data=concat(data,"-2");
59# update test.autokey set ok=ok-1, data=concat(data,"-3");
60
61delete from test.autokey where ok=2;
62
63--echo Allow backup to complete...
64--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "all error 0" >> $NDB_TOOLS_OUTPUT 2>&1
65
66--source suite/ndb/t/ndb_backup_nowait_wait.inc
67
68select * from test.autokey order by data;
69
70--echo Check next auto-inc value
71insert into test.autokey (ok,data) values (6, "6-1");
72select ak from test.autokey where ok=6;
73
74#--exec $NDB_DESC --no-defaults -dtest autokey
75
76drop table test.autokey;
77
78
79--echo Primary key extended to include another column
80--echo  PK order changed
81--echo  Extra secondary index dropped
82--echo **********************************************
83create table test.autokey (
84  ak   bigint unsigned not null auto_increment,
85  ok   bigint unsigned not null,
86  data varchar(200) not null,
87  primary key(ok,ak))
88engine=ndb partition by key(ok);
89
90--echo Run restore
91--exec $NDB_RESTORE -b $the_backup_id -n 1 -r --allow-pk-changes --ignore-extended-pk-updates $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
92--exec $NDB_RESTORE -b $the_backup_id -n 2 -r --allow-pk-changes --ignore-extended-pk-updates $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
93
94select * from test.autokey order by data;
95
96--echo Check next auto-inc value
97insert into test.autokey (ok,data) values (6, "6-1");
98select ak from test.autokey where ok=6;
99
100#--exec $NDB_DESC --no-defaults -dtest autokey
101
102drop table test.autokey;
103
104
105--echo Primary key extended to include another column
106--echo  PK column demoted
107--echo  !PK column promoted
108--echo  PK order changed
109--echo  Extra secondary index dropped
110--echo **********************************************
111create table test.autokey (
112  ak   bigint unsigned not null auto_increment,
113  ok   int unsigned not null,
114  data varchar(250) not null,
115  primary key(ok,ak))
116engine=ndb partition by key(ok);
117
118--echo Run restore
119--exec $NDB_RESTORE -b $the_backup_id -n 1 -r --allow-pk-changes --ignore-extended-pk-updates --promote-attributes --lossy-conversions $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
120--exec $NDB_RESTORE -b $the_backup_id -n 2 -r --allow-pk-changes --ignore-extended-pk-updates --promote-attributes --lossy-conversions $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
121
122select * from test.autokey order by data;
123
124--echo Check next auto-inc value
125insert into test.autokey (ok,data) values (6, "6-1");
126select ak from test.autokey where ok=6;
127
128#--exec $NDB_DESC --no-defaults -dtest autokey
129
130drop table test.autokey;
131
132
133--echo ********************************
134--echo Autoincrement reduce pk
135--echo Prepare table + backup with log
136--echo ********************************
137create table test.autokey (
138  ak   bigint unsigned not null auto_increment,
139  ok   bigint unsigned not null,
140  data varchar(200) not null,
141  primary key(ok,ak))
142engine=ndb partition by key(ok);
143
144insert into test.autokey (ok,data) values
145  (1, "1-1"),
146  (1, "1-2"),
147  (1, "1-3"),
148  (1, "1-4"),
149  (2, "2-1"),
150  (2, "2-2"),
151  (2, "2-3"),
152  (3, "3-1"),
153  (3, "3-2"),
154  (3, "3-3");
155
156select * from test.autokey order by data;
157
158--echo Stall backup completion
159--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "all error 10039" >> $NDB_TOOLS_OUTPUT 2>&1
160--echo Run backup
161--source suite/ndb/t/ndb_backup_nowait_start.inc
162
163--echo Make some changes which will be logged...
164insert into test.autokey (ok,data) values
165  (4, "4-1"),
166  (4, "4-2"),
167  (4, "4-3"),
168  (5, "5-1"),
169  (5, "5-2");
170
171update test.autokey set data = concat(data, "-mk2");
172delete from test.autokey where ok=2;
173
174--echo Allow backup to complete...
175--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "all error 0" >> $NDB_TOOLS_OUTPUT 2>&1
176
177--source suite/ndb/t/ndb_backup_nowait_wait.inc
178
179select * from test.autokey order by data;
180
181--echo Check next auto-inc value
182insert into test.autokey (ok,data) values (6, "6-1");
183select ak from test.autokey where ok=6;
184
185#--exec $NDB_DESC --no-defaults -dtest autokey
186
187drop table test.autokey;
188
189--echo Primary key reduced down to autoincrement
190--echo  Extra secondary index
191--echo **********************************************
192create table test.autokey (
193  ak   bigint unsigned not null auto_increment,
194  ok   bigint unsigned not null,
195  data varchar(200) not null,
196  primary key(ak),
197  key(ok))
198engine=ndb;
199
200--echo Run restore
201--exec $NDB_RESTORE -b $the_backup_id -n 1 -r --allow-pk-changes --ignore-extended-pk-updates --lossy-conversions $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
202--exec $NDB_RESTORE -b $the_backup_id -n 2 -r --allow-pk-changes --ignore-extended-pk-updates --lossy-conversions $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
203
204select * from test.autokey order by data;
205
206--echo Check next auto-inc value
207insert into test.autokey (ok,data) values (6, "6-1");
208select ak from test.autokey where ok=6;
209
210#--exec $NDB_DESC --no-defaults -dtest autokey
211
212drop table test.autokey;
213
214--echo Primary key reduced down to autoincrement
215--echo  Ex-PK demoted
216--echo  Non-PK demoted
217--echo  Extra secondary index
218--echo **********************************************
219create table test.autokey (
220  ak   bigint unsigned not null auto_increment,
221  ok   int unsigned not null,
222  data varchar(20) not null,
223  primary key(ak),
224  key(ok))
225engine=ndb;
226
227--echo Run restore
228--exec $NDB_RESTORE -b $the_backup_id -n 1 -r --allow-pk-changes --ignore-extended-pk-updates --promote-attributes --lossy-conversions $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
229--exec $NDB_RESTORE -b $the_backup_id -n 2 -r --allow-pk-changes --ignore-extended-pk-updates --promote-attributes --lossy-conversions $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT 2>&1
230
231select * from test.autokey order by data;
232
233--echo Check next auto-inc value
234insert into test.autokey (ok,data) values (6, "6-1");
235select ak from test.autokey where ok=6;
236
237#--exec $NDB_DESC --no-defaults -dtest autokey
238
239drop table test.autokey;
240
241--disable_query_log
242set ndb_autoincrement_prefetch_sz = @old_ndb_autoincrement_prefetch_sz;
243--enable_query_log
244
245--source suite/ndb/include/backup_restore_cleanup.inc
246--remove_file $NDB_TOOLS_OUTPUT
247