4b46cbbb3c8254eacfb33c3e11d33261517cdd40
[vlendec/samba-autobuild/.git] / ctdb / tests / simple / 70_recoverpdbbyseqnum.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 The tunable RecoverPDBBySeqNum controls how we perform recovery
7 on persistent databases.
8 The default is that persistent databases are recovered exactly the same
9 way as normal databases. That is that we recover record by record.
10
11 If RecoverPDBBySeqNum is set to 1 AND if a record with the key
12 "__db_sequence_number__" can be found in the database, then instead we will
13 perform the recovery by picking the copy of the database from the node
14 that has the highest sequence number and ignore the content on all other
15 nodes.
16
17
18 Prerequisites:
19
20 * An active CTDB cluster with at least 2 active nodes.
21
22 Steps:
23
24 1. Verify that the status on all of the ctdb nodes is 'OK'.
25 2. create a persistent test database
26 3. test that RecoveryPDBBySeqNum==0 and no seqnum record blends the database
27    during recovery
28 4. test that RecoveryPDBBySeqNum==0 and seqnum record blends the database
29    during recovery
30 5. test that RecoveryPDBBySeqNum==1 and no seqnum record blends the database
31    during recovery
32 6. test that RecoveryPDBBySeqNum==1 and seqnum record does not blend the database
33    during recovery
34
35 Expected results:
36
37 * that 3,4,5 will blend the databases and that 6 will recovery the highest seqnum
38   database
39
40 EOF
41 }
42
43 . ctdb_test_functions.bash
44
45 ctdb_test_init "$@"
46
47 set -e
48
49 cluster_is_healthy
50
51 try_command_on_node 0 "$CTDB listnodes"
52 num_nodes=$(echo "$out" | wc -l)
53
54 # create a temporary persistent database to test with
55 echo create persistent test database persistent_test.tdb
56 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb attach persistent_test.tdb persistent
57
58
59 # set RecoverPDBBySeqNum=0
60 echo "setting RecoverPDBBySeqNum to 0"
61 try_command_on_node -q all $CTDB_TEST_WRAPPER ctdb setvar RecoverPDBBySeqNum 0
62
63
64
65 # 3,
66 # If RecoverPDBBySeqNum==0  and no __db_sequence_number__
67 # recover record by record
68 #
69 # wipe database
70 echo
71 echo test that RecoverPDBBySeqNum==0 and no __db_sequence_number__ blends the database during recovery
72 echo wipe the test database
73 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb wipedb persistent_test.tdb
74
75 # add one record to node 0   key==ABC  data==ABC
76 TDB=`try_command_on_node -v -q 0 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
77 echo "store key(ABC) data(ABC) on node 0"
78 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x414243 0x070000000000000000000000000000000000000000000000414243
79 #
80 # add one record to node 1   key==DEF  data==DEF
81 TDB=`try_command_on_node -v -q 1 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
82 echo "store key(DEF) data(DEF) on node 1"
83 try_command_on_node -q 1 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x444546 0x070000000000000000000000000000000000000000000000444546
84
85 # force a recovery
86 echo force a recovery
87 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb recover
88
89 # check that we now have both records on node 0
90 num_records=$(try_command_on_node -v -pq 0 $CTDB_TEST_WRAPPER ctdb cattdb persistent_test.tdb | grep key | egrep "ABC|DEF" | wc -l)
91 [ $num_records != "2" ] && {
92     echo "BAD: we did not end up with the expected two records after the recovery"
93     exit 1
94 }
95 echo "OK. databases were blended"
96
97
98
99 # 4,
100 # If RecoverPDBBySeqNum==0  and __db_sequence_number__
101 # recover record by record
102 #
103 # wipe database
104 echo
105 echo test that RecoverPDBBySeqNum==0 and __db_sequence_number__ blends the database during recovery
106 echo wipe the test database
107 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb wipedb persistent_test.tdb
108
109 echo "add __db_sequence_number__==5 record to all nodes"
110 try_command_on_node -v 0 $CTDB_TEST_WRAPPER ctdb nodestatus all | grep pnn | sed -e"s/^pnn://" -e "s/ .*//" | while read PNN; do
111     TDB=`try_command_on_node -v -q $PNN $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
112     try_command_on_node -q $PNN $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x5f5f64625f73657175656e63655f6e756d6265725f5f00 0x0700000000000000000000000000000000000000000000000500000000000000
113 done
114
115 # add one record to node 0   key==ABC  data==ABC
116 TDB=`try_command_on_node -v -q 0 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
117 echo "store key(ABC) data(ABC) on node 0"
118 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x414243 0x070000000000000000000000000000000000000000000000414243
119 echo "add __db_sequence_number__==7 record to node 0"
120 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x5f5f64625f73657175656e63655f6e756d6265725f5f00 0x0700000000000000000000000000000000000000000000000700000000000000
121
122 # add one record to node 1   key==DEF  data==DEF
123 TDB=`try_command_on_node -v -q 1 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
124 echo "store key(DEF) data(DEF) on node 1"
125 try_command_on_node -q 1 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x444546 0x070000000000000000000000000000000000000000000000444546
126 echo "add __db_sequence_number__==8 record to node 1"
127 try_command_on_node -q 1 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x5f5f64625f73657175656e63655f6e756d6265725f5f00 0x0700000000000000000000000000000000000000000000000800000000000000
128
129 # force a recovery
130 echo force a recovery
131 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb recover
132
133 # check that we now have both records on node 0
134 num_records=$(try_command_on_node -v -pq 0 $CTDB_TEST_WRAPPER ctdb cattdb persistent_test.tdb | grep key | egrep "ABC|DEF" | wc -l)
135 [ $num_records != "2" ] && {
136     echo "BAD: we did not end up with the expected two records after the recovery"
137     exit 1
138 }
139 echo "OK. databases were blended"
140
141
142
143 # set RecoverPDBBySeqNum=1
144 echo
145 echo "setting RecoverPDBBySeqNum to 1"
146 try_command_on_node -q all $CTDB_TEST_WRAPPER ctdb setvar RecoverPDBBySeqNum 1
147
148
149
150 # 5,
151 # If RecoverPDBBySeqNum==1  and no __db_sequence_number__
152 # recover record by record
153 #
154 # wipe database
155 echo
156 echo test that RecoverPDBBySeqNum==1 and no __db_sequence_number__ blends the database during recovery
157 echo wipe the test database
158 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb wipedb persistent_test.tdb
159
160 # add one record to node 0   key==ABC  data==ABC
161 TDB=`try_command_on_node -v -q 0 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
162 echo "store key(ABC) data(ABC) on node 0"
163 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x414243 0x070000000000000000000000000000000000000000000000414243
164
165 # add one record to node 1   key==DEF  data==DEF
166 TDB=`try_command_on_node -v -q 1 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
167 echo "store key(DEF) data(DEF) on node 1"
168 try_command_on_node -q 1 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x444546 0x070000000000000000000000000000000000000000000000444546
169
170 # force a recovery
171 echo force a recovery
172 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb recover
173
174 # check that we now have both records on node 0
175 num_records=$(try_command_on_node -v -pq 0 $CTDB_TEST_WRAPPER ctdb cattdb persistent_test.tdb | grep key | egrep "ABC|DEF" | wc -l)
176 [ $num_records != "2" ] && {
177     echo "BAD: we did not end up with the expected two records after the recovery"
178     exit 1
179 }
180 echo "OK. databases were blended"
181
182
183
184 # 6,
185 # If RecoverPDBBySeqNum==1  and __db_sequence_number__
186 # recover whole database
187 #
188 # wipe database
189 echo
190 echo test that RecoverPDBBySeqNum==1 and __db_sequence_number__ does not blend the database during recovery
191 echo wipe the test database
192 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb wipedb persistent_test.tdb
193
194 echo "add __db_sequence_number__==5 record to all nodes"
195 try_command_on_node -v 0 $CTDB_TEST_WRAPPER ctdb nodestatus all | grep pnn | sed -e"s/^pnn://" -e "s/ .*//" | while read PNN; do
196     TDB=`try_command_on_node -v -q $PNN $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
197     try_command_on_node -q $PNN $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x5f5f64625f73657175656e63655f6e756d6265725f5f00 0x0700000000000000000000000000000000000000000000000500000000000000
198 done
199
200
201 # add one record to node 0   key==ABC  data==ABC
202 TDB=`try_command_on_node -v -q 0 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
203 echo "store key(ABC) data(ABC) on node 0"
204 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x414243 0x070000000000000000000000000000000000000000000000414243
205 echo "add __db_sequence_number__==7 record to node 0"
206 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x5f5f64625f73657175656e63655f6e756d6265725f5f00 0x0700000000000000000000000000000000000000000000000700000000000000
207
208 # add one record to node 1   key==DEF  data==DEF
209 TDB=`try_command_on_node -v -q 1 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
210 echo "store key(DEF) data(DEF) on node 1"
211 try_command_on_node -q 1 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x444546 0x070000000000000000000000000000000000000000000000444546
212 echo "add __db_sequence_number__==8 record to node 1"
213 try_command_on_node -q 1 $CTDB_TEST_WRAPPER ctdb tstore $TDB 0x5f5f64625f73657175656e63655f6e756d6265725f5f00 0x0700000000000000000000000000000000000000000000000800000000000000
214
215 # force a recovery
216 echo force a recovery
217 try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb recover
218
219 # check that we now have both records on node 0
220 num_records=$(try_command_on_node -v -pq 0 $CTDB_TEST_WRAPPER ctdb cattdb persistent_test.tdb | grep key | egrep "ABC|DEF" | wc -l)
221 [ $num_records != "1" ] && {
222     echo "BAD: we did not end up with the expected single record after the recovery"
223     exit 1
224 }
225
226 echo "OK. databases were not blended"
227
228
229
230 # set RecoverPDBBySeqNum=1
231 echo "setting RecoverPDBBySeqNum back to 0"
232 try_command_on_node -q all $CTDB_TEST_WRAPPER ctdb setvar RecoverPDBBySeqNum 0