blob: 4f4c8d1f4fa44102ac4f12713b7b6880ad22a5bd (
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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2001-2003
# Sleepycat Software. All rights reserved.
#
# $Id: rep007.tcl,v 11.15 2003/09/25 01:35:39 margo Exp $
#
# TEST rep007
# TEST Replication and bad LSNs
# TEST
# TEST Run a modified version of test001 in a replicated master env.
# TEST Close the client. Make additional changes to master.
# TEST Close the master. Open the client as the new master.
# TEST Make several different changes. Open the old master as
# TEST the client. Verify periodically that contents are correct.
proc rep007 { method { niter 10 } { tnum "007" } args } {
global testdir
puts "Rep$tnum: Replication and bad LSNs."
set orig_tdir $testdir
set largs $args
set omethod [convert_method $method]
env_cleanup $testdir
replsetup $testdir/MSGQUEUEDIR
set masterdir $testdir/MASTERDIR
set clientdir $testdir/CLIENTDIR
set clientdir2 $testdir/CLIENTDIR.2
file mkdir $masterdir
file mkdir $clientdir
file mkdir $clientdir2
# Open a master.
repladd 1
set ma_envcmd "berkdb_env -create -txn nosync -lock_max 2500 \
-home $masterdir -rep_transport \[list 1 replsend\]"
# set ma_envcmd "berkdb_env -create -txn nosync -lock_max 2500 \
# -verbose {rep on} \
# -home $masterdir -rep_transport \[list 1 replsend\]"
set masterenv [eval $ma_envcmd -rep_master]
error_check_good master_env [is_valid_env $masterenv] TRUE
# Open two clients
repladd 2
set cl_envcmd "berkdb_env -create -txn nosync -lock_max 2500 \
-home $clientdir -rep_transport \[list 2 replsend\]"
# set cl_envcmd "berkdb_env -create -txn nosync -lock_max 2500 \
# -verbose {rep on} \
# -home $clientdir -rep_transport \[list 2 replsend\]"
set clientenv [eval $cl_envcmd -rep_client]
error_check_good client_env [is_valid_env $clientenv] TRUE
repladd 3
set cl2_envcmd "berkdb_env -create -txn nosync -lock_max 2500 \
-home $clientdir2 -rep_transport \[list 3 replsend\]"
# set cl2_envcmd "berkdb_env -create -txn nosync -lock_max 2500 \
# -home $clientdir2 -rep_transport \[list 3 replsend\] \
# -verbose {rep on}"
set cl2env [eval $cl2_envcmd -rep_client]
error_check_good client2_env [is_valid_env $cl2env] TRUE
# Bring the clients online by processing the startup messages.
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $masterenv 1]
incr nproced [replprocessqueue $clientenv 2]
incr nproced [replprocessqueue $cl2env 3]
if { $nproced == 0 } {
break
}
}
# Run a modified test001 in the master (and update clients).
puts "\tRep$tnum.a: Running test001 in replicated env."
eval test001 $method $niter 0 0 $tnum -env $masterenv $largs
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $masterenv 1]
incr nproced [replprocessqueue $clientenv 2]
incr nproced [replprocessqueue $cl2env 3]
if { $nproced == 0 } {
break
}
}
# Databases should now have identical contents. We assume we
# know the name of the file created by test001, "test$tnum.db".
set dbname "test$tnum.db"
if { [is_hash $method] == 0 } {
set db1 [berkdb_open -env $masterenv -auto_commit $dbname]
set db2 [berkdb_open -env $clientenv -auto_commit $dbname]
set db3 [berkdb_open -env $cl2env -auto_commit $dbname]
error_check_good compare1and2 \
[db_compare $db1 $db2 $masterdir/$dbname $clientdir/$dbname] 0
error_check_good compare1and3 \
[db_compare $db1 $db3 $masterdir/$dbname $clientdir2/$dbname] 0
error_check_good db1_close [$db1 close] 0
error_check_good db2_close [$db2 close] 0
error_check_good db3_close [$db3 close] 0
}
puts "\tRep$tnum.b: Close client 1 and make master changes."
error_check_good client_close [$clientenv close] 0
# Change master and propagate changes to client 2.
set start $niter
eval test001 $method $niter $start 1 $tnum -env $masterenv $largs
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $masterenv 1]
incr nproced [replprocessqueue $cl2env 3]
if { $nproced == 0 } {
break
}
}
# We need to do a deletion here to cause meta-page updates,
# particularly for queue. Delete the first pair and remember
# what it is -- it should come back after the master is closed
# and reopened as a client.
set db1 [berkdb_open -env $masterenv -auto_commit $dbname]
error_check_good dbopen [is_valid_db $db1] TRUE
set txn [$masterenv txn]
set c [$db1 cursor -txn $txn]
error_check_good db_cursor [is_valid_cursor $c $db1] TRUE
set first [$c get -first]
set pair [lindex [$c get -first] 0]
set key [lindex $pair 0]
set data [lindex $pair 1]
error_check_bad dbcget [llength $key] 0
error_check_good cursor_del [$c del] 0
error_check_good dbcclose [$c close] 0
error_check_good txn_commit [$txn commit] 0
error_check_good db1_close [$db1 close] 0
#
# Process the messages to get them out of the db. This also
# propagates the delete to client 2.
#
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $masterenv 1]
incr nproced [replprocessqueue $cl2env 3]
if { $nproced == 0 } {
break
}
}
# Nuke those for closed client
replclear 2
# Databases 1 and 3 should now have identical contents.
# Database 2 should be different. First check 1 and 3. We
# have to wait to check 2 until the env is open again.
set db1 [berkdb_open -env $masterenv -auto_commit $dbname]
set db3 [berkdb_open -env $cl2env -auto_commit $dbname]
error_check_good compare1and3 \
[db_compare $db1 $db3 $masterdir/$dbname $clientdir2/$dbname] 0
error_check_good db1_close [$db1 close] 0
puts "\tRep$tnum.c: Close master, reopen client as master."
error_check_good master_close [$masterenv close] 0
set newmasterenv [eval $cl_envcmd -rep_master]
# Now we can check that database 2 does not match 3.
if { [is_hash $method] == 0 } {
set db2 [berkdb_open -env $newmasterenv -auto_commit $dbname]
catch {db_compare $db2 $db3 $clientdir/$dbname \
$clientdir2/$dbname} res
error_check_bad compare2and3_must_fail $res 0
error_check_good db2_close [$db2 close] 0
}
error_check_good db3_close [$db3 close] 0
puts "\tRep$tnum.d: Make incompatible changes to new master."
set db [berkdb_open -env $newmasterenv -auto_commit -create $omethod \
test007.db]
error_check_good dbopen [is_valid_db $db] TRUE
set t [$newmasterenv txn]
# Force in a pair {10 10}. This works for all access
# methods and won't overwrite the old first pair for record-based.
set ret [$db put -txn $t 10 [chop_data $method 10]]
error_check_good put $ret 0
error_check_good txn [$t commit] 0
error_check_good dbclose [$db close] 0
eval test001 $method $niter $start 1 $tnum -env $newmasterenv $largs
set cl2rec 0
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $newmasterenv 2]
incr nproced [replprocessqueue $cl2env 3]
# At some point in the processing, client2 should be
# in recovery.
set stat [$cl2env rep_stat]
if { [is_substr $stat "{{In recovery} 1}"] } {
set cl2rec 1
}
if { $nproced == 0 } {
break
}
}
# Nuke those for closed old master
replclear 1
#
# Check that cl2 stats showed we were in recovery and now that
# we're done, we should be out of it.
#
error_check_good cl2rec $cl2rec 1
set stat [$cl2env rep_stat]
error_check_good cl2recover [is_substr $stat "{{In recovery} 0}"] 1
# Databases 2 and 3 should now match.
set db2 [berkdb_open -env $newmasterenv -auto_commit $dbname]
set db3 [berkdb_open -env $cl2env -auto_commit $dbname]
error_check_good compare2and3 \
[db_compare $db2 $db3 $clientdir/$dbname $clientdir2/$dbname] 0
error_check_good db2_close [$db2 close] 0
error_check_good db3_close [$db3 close] 0
puts "\tRep$tnum.e: Open old master as client."
set newclientenv [eval $ma_envcmd -rep_client -recover]
# Bring the newclient online by processing the startup messages.
set ncrec 0
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $newmasterenv 2]
incr nproced [replprocessqueue $newclientenv 1]
set stat [$newclientenv rep_stat]
if { [is_substr $stat "{{In recovery} 1}"] } {
set ncrec 1
}
incr nproced [replprocessqueue $cl2env 3]
if { $nproced == 0 } {
break
}
}
error_check_good ncrec $ncrec 1
set stat [$newclientenv rep_stat]
error_check_good nc2recover [is_substr $stat "{{In recovery} 0}"] 1
# The pair we deleted earlier from the master should now
# have reappeared.
set db1 [berkdb_open -env $newclientenv -auto_commit $dbname]
error_check_good dbopen [is_valid_db $db1] TRUE
set ret [$db1 get -get_both $key [pad_data $method $data]]
error_check_good get_both $ret [list $pair]
error_check_good db1_close [$db1 close] 0
set start [expr $niter * 2]
eval test001 $method $niter $start 1 $tnum -env $newmasterenv $largs
while { 1 } {
set nproced 0
incr nproced [replprocessqueue $newmasterenv 2]
incr nproced [replprocessqueue $newclientenv 1]
incr nproced [replprocessqueue $cl2env 3]
if { $nproced == 0 } {
break
}
}
# Now all 3 should match again.
set db1 [berkdb_open -env $newclientenv -auto_commit $dbname]
set db2 [berkdb_open -env $newmasterenv -auto_commit $dbname]
set db3 [berkdb_open -env $cl2env -auto_commit $dbname]
error_check_good compare1and2 \
[db_compare $db1 $db2 $masterdir/$dbname $clientdir/$dbname] 0
error_check_good compare1and3 \
[db_compare $db1 $db3 $masterdir/$dbname $clientdir2/$dbname] 0
error_check_good db1_close [$db1 close] 0
error_check_good db2_close [$db2 close] 0
error_check_good db3_close [$db3 close] 0
error_check_good newmasterenv_close [$newmasterenv close] 0
error_check_good newclientenv_close [$newclientenv close] 0
error_check_good cl2_close [$cl2env close] 0
replclose $testdir/MSGQUEUEDIR
set testdir $orig_tdir
return
}
|