-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathrunit
executable file
·224 lines (163 loc) · 5.63 KB
/
runit
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
bash -n "$0" | exit 1
source ${TESTSROOTDIR}/tools/runit_common.sh
# Debug variable
debug=0
dbnm=$1
if [ "x$dbnm" == "x" ] ; then
echo "need a DB name"
exit 1
fi
# Number of insert_records function calls
nins=0
function update_records
{
j=0
nrecs=$1
echo "Updating $nrecs records."
echo "" > update.out
while [[ $j -lt $nrecs ]]; do
cdb2sql ${CDB2_OPTIONS} $dbnm default "update t1 set c=c+10000 where a = $j" >> update.out
let j=j+1
done
}
function insert_records
{
j=$1
nstop=$2
let nins=nins+1
insfl=insert${nins}.out
echo "Inserting $((nstop-j+1)) records ($j to $nstop)."
echo "" > $insfl
while [[ $j -le $nstop ]]; do
cdb2sql ${CDB2_OPTIONS} $dbnm default "insert into t1(a,b,c) values ($j,'test1$j',$j)" &>> $insfl
# use for compare? echo "a=$j, b='test1$j', c='$j'" >> rows.out
let j=j+1
done
}
echo "Test with insert, SC should not fail"
#cdb2sql ${CDB2_OPTIONS} $dbnm default "exec procedure sys.cmd.send('debg 800')"
cdb2sql ${CDB2_OPTIONS} $dbnm default "drop table t1"
cdb2sql ${CDB2_OPTIONS} $dbnm default "create table t1 { `cat t1_1.csc2 ` }"
insert_records 1 2000
assertcnt t1 2000
#check via select * from t1 | make sure that a == b == c == 'test'$
insert_records 2001 3000 &
echo "Alter table to t1_2 version while doing inserts"
sleep 1
cdb2sql ${CDB2_OPTIONS} $dbnm default "alter table t1 { `cat t1_2.csc2 ` }"
ret=$?
if [[ "$ret" != 0 ]]; then
failexit "Schemachange rc=$rc, but it should have succeeded"
fi
wait
assertcnt t1 3000
do_verify t1
echo "Alter table to t1_1 version"
cdb2sql ${CDB2_OPTIONS} $dbnm default "alter table t1 { `cat t1_1.csc2 ` }"
assertcnt t1 3000
do_verify t1
update_records 3000 &
echo "Alter table to t1_2 version while doing updates"
sleep 1
cdb2sql ${CDB2_OPTIONS} $dbnm default "alter table t1 { `cat t1_2.csc2 ` }"
ret=$?
if [[ "$ret" != 0 ]]; then
failexit "Schemachange rc=$rc, but it should have succeeded"
fi
wait
assertcnt t1 3000
do_verify t1
function do_alter_and_update (){
#updates fail (deadlock?):
#[update t1 set c=c+10000 where 1] failed with rc 304 unable to update record
cdb2sql ${CDB2_OPTIONS} $dbnm default "alter table t1 { `cat t1_1.csc2 ` }"
assertcnt t1 3000
do_verify t1
(cdb2sql ${CDB2_OPTIONS} $dbnm default "alter table t1 { `cat t1_2.csc2 ` }" || touch alter.failed) &
sleep 0.1
cdb2sql ${CDB2_OPTIONS} $dbnm default "update t1 set c=c+10000 where 1" > update.out
ret=$?
if [[ "$ret" != 0 ]]; then
failexit "Schemachange rc=$rc, but it should have succeeded"
fi
wait
assertcnt t1 3000
do_verify t1
if [ -f alter.failed ] ; then
failexit "Alter while updating where 1"
fi
}
do_alter_and_update
function do_rebuild_and_update (){
#rebuild and update fail...2 problems:
#1. not found in new IX, when key a and key c
#2. dup in new IX, when only key c
(cdb2sql ${CDB2_OPTIONS} $dbnm default "rebuild t1" || touch rebuild.failed) &
sleep 0.1
cdb2sql ${CDB2_OPTIONS} $dbnm default "update t1 set c=c+10000 where 1" > update.out
ret=$?
if [[ "$ret" != 0 ]]; then
failexit "Schemachange rc=$rc, but it should have succeeded"
fi
wait
assertcnt t1 3000
do_verify t1
if [ -f rebuild.failed ] ; then
failexit "Rebuild while updating where 1"
fi
}
insert_records 3001 4000 &
echo "Alter into t1_3.csc2"
sleep 1
cdb2sql ${CDB2_OPTIONS} $dbnm default "alter table t1 { `cat t1_3.csc2 ` }"
ret=$?
if [[ "$ret" != 0 ]]; then
failexit "Test Failed: Schemachange rc=$rc, but it should have succeeded"
fi
wait
assertcnt t1 4000
do_verify t1
echo "Alter into t1_4.csc2 while update/deleting"
master=`cdb2sql --tabs ${CDB2_OPTIONS} $dbnm default 'exec procedure sys.cmd.send("bdb cluster")' | grep MASTER | cut -f1 -d":" | tr -d '[:space:]'`
cdb2sql ${CDB2_OPTIONS} --host $master $dbnm "PUT SCHEMACHANGE CONVERTSLEEP 30"
(cdb2sql ${CDB2_OPTIONS} --host $master $dbnm "alter table t1 { `cat t1_4.csc2 ` }" &> alter.out || touch alter.failed) &
sleep 15
cdb2sql ${CDB2_OPTIONS} $dbnm default "delete from t1 where a % 2 = 1"
if [ $? -ne 0 ] ; then
failexit "failed to delete while altering to t1_4"
fi
cdb2sql ${CDB2_OPTIONS} $dbnm default "update t1 set a = a + 10000 where 1"
if [ $? -ne 0 ] ; then
failexit "failed to update while altering to t1_4"
fi
wait
if [ -f alter.failed ] ; then
failexit "Alter to t1_4.csc2 failed, but it should have succeeded"
fi
do_verify t1
echo "Add default null field"
master=`cdb2sql --tabs ${CDB2_OPTIONS} $dbnm default 'exec procedure sys.cmd.send("bdb cluster")' | grep MASTER | cut -f1 -d":" | tr -d '[:space:]'`
cdb2sql ${CDB2_OPTIONS} --host $master $dbnm "PUT SCHEMACHANGE CONVERTSLEEP 0"
cdb2sql ${CDB2_OPTIONS} --host $master $dbnm "CREATE TABLE t2 { schema {int a} }"
cdb2sql ${CDB2_OPTIONS} --host $master $dbnm "INSERT INTO t2(a) VALUES (1)"
if [ $? -ne 0 ] ; then
failexit "failed to insert to t2"
fi
cdb2sql ${CDB2_OPTIONS} --host $master $dbnm 'ALTER table t2 { schema {int a int b null=yes} keys {dup "IX_A" = a + b} }'
cdb2sql ${CDB2_OPTIONS} $dbnm default "exec procedure sys.cmd.verify('t2')" &> verify.out
if ! grep succeeded verify.out > /dev/null ; then
failexit "Verify t2"
fi
cdb2sql ${CDB2_OPTIONS} $dbnm default "update t2 set b = 1 where a = 1"
if [ $? -ne 0 ] ; then
failexit "failed to update after adding null field"
fi
echo "Add new field without dbstore or null=yes"
cdb2sql ${CDB2_OPTIONS} $dbnm default "DROP TABLE IF EXISTS t3"
cdb2sql ${CDB2_OPTIONS} $dbnm default "CREATE TABLE t3 { schema {int a} }"
cdb2sql ${CDB2_OPTIONS} $dbnm default "ALTER TABLE t3 { schema {int a int b int c null=yes} }"
if [ $? -eq 0 ] ; then
failexit "failed to detect bad schema"
fi
echo "Success"