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
304
305
306
307
308
309
310
311
312
313
314
315
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2001-2006
# Oracle Corporation. All rights reserved.
#
# $Id: rep021.tcl,v 12.9 2006/08/24 14:46:37 bostic Exp $
#
# TEST rep021
# TEST Replication and multiple environments.
# TEST Run similar tests in separate environments, making sure
# TEST that some data overlaps. Then, "move" one client env
# TEST from one replication group to another and make sure that
# TEST we do not get divergent logs. We either match the first
# TEST record and end up with identical logs or we get an error.
# TEST Verify all client logs are identical if successful.
#
proc rep021 { method { nclients 3 } { tnum "021" } args } {
source ./include.tcl
if { $is_windows9x_test == 1 } {
puts "Skipping replication test on Win 9x platform."
return
}
# Run for all access methods.
if { $checking_valid_methods } {
return "ALL"
}
set args [convert_args $method $args]
set logsets [create_logsets [expr $nclients + 1]]
# Run the body of the test with and without recovery.
foreach r $test_recopts {
foreach l $logsets {
set logindex [lsearch -exact $l "in-memory"]
if { $r == "-recover" && $logindex != -1 } {
puts "Rep$tnum: Skipping\
for in-memory logs with -recover."
continue
}
puts "Rep$tnum ($method $r):\
Replication and $nclients recovered clients in sync."
puts "Rep$tnum: Master logs are [lindex $l 0]"
for { set i 0 } { $i < $nclients } { incr i } {
puts "Rep$tnum: Client $i logs are\
[lindex $l [expr $i + 1]]"
}
rep021_sub $method $nclients $tnum $l $r $args
}
}
}
proc rep021_sub { method nclients tnum logset recargs largs } {
global testdir
global util_path
set orig_tdir $testdir
env_cleanup $testdir
replsetup $testdir/MSGQUEUEDIR
set niter 100
set offset 5
set masterdir $testdir/MASTERDIR
set masterdir2 $testdir/MASTERDIR.NEW
file mkdir $masterdir
file mkdir $masterdir2
set m_logtype [lindex $logset 0]
set m_logargs [adjust_logargs $m_logtype]
set m_txnargs [adjust_txnargs $m_logtype]
# We want to run the test 3 times in 2 separate repl envs.
# This is a little bit tricky due to how we manage replication
# in Tcl. It assumes one replication group.
# This is tricky because we need to manage/clear the repl
# message queues for the different groups when running
# to one group or the other.
# To accomplish this we run entirely in the 2nd group first.
# We set it up and then close all its envs. Then we run
# to the 1st group, and set it up. Then we add in a client
# from the 2nd group into the existing 1st group.
# Although we're doing them in separate parts, this is
# a description of what we're doing.
#
# 1. First add divergent data to database:
# RepGrp1: Add niter data from 0 to database.
# RepGrp2: Add niter data from offset to database.
# This gives us overlapping data in the databases, but they're
# additions will be at different offsets in the log files.
#
# 2. Add identical data to both databases.
# RepGrp1: Add niter data from niter + offset to database.
# RepGrp2: Add niter data from niter + offset to database.
# This gives us identical data in the databases and logs.
#
# 3. Again add divergent data to databases.
# RepGrp1: Add niter data from niter*2+offset to database.
# RepGrp2: Add niter data from niter*2+offset*2 to database.
# This gives us overlapping data in the databases, but they're
# additions will be at different offsets in the log files.
#
# 4. Add a client from one group to the other. Then try
# to sync up that client. We should get a failure with
# one of the non-matching error messages:
# "Too few log files to sync with master"
# "Client was never part of master's environment"
# Open a 2nd master. Make all the 2nd env ids >= 10.
# For the 2nd group, just have 1 master and 1 client.
repladd 10
set ma2_envcmd "berkdb_env -create $m_txnargs \
$m_logargs -home $masterdir2 \
-rep_master -rep_transport \[list 10 replsend\]"
# set ma2_envcmd "berkdb_env -create $m_txnargs \
# $m_logargs -home $masterdir2 \
# -errpfx MASTER2 -verbose {rep on} \
# -rep_master -rep_transport \[list 10 replsend\]"
set menv2 [eval $ma2_envcmd $recargs]
error_check_good master2_env [is_valid_env $menv2] TRUE
set clientdir2 $testdir/CLIENTDIR.NEW
file mkdir $clientdir2
set id2 11
set c_logtype($id2) [lindex $logset 1]
set c_logargs($id2) [adjust_logargs $c_logtype($id2)]
set c_txnargs($id2) [adjust_txnargs $c_logtype($id2)]
set id2 11
repladd $id2
set cl2_envcmd "berkdb_env -create $c_txnargs($id2) \
$c_logargs($id2) -home $clientdir2 \
-rep_client -rep_transport \[list $id2 replsend\]"
# set cl2_envcmd "berkdb_env -create $c_txnargs($id2) \
# -errpfx CLIENT2 -verbose {rep on} \
# $c_logargs($id2) -home $clientdir2 \
# -rep_client -rep_transport \[list $id2 replsend\]"
set clenv2 [eval $cl2_envcmd $recargs]
error_check_good client_env [is_valid_env $clenv2] TRUE
set testfile "test$tnum.db"
set omethod [convert_method $method]
set masterdb2 [eval {berkdb_open_noerr -env $menv2 -auto_commit \
-create -mode 0644} $largs $omethod $testfile]
error_check_good dbopen [is_valid_db $masterdb2] TRUE
#
# Process startup messages
#
set env2list {}
lappend env2list "$menv2 10"
lappend env2list "$clenv2 $id2"
process_msgs $env2list
#
# Set up the three runs of rep_test. We need the starting
# point for each phase of the test for each group.
#
set e1phase1 0
set e2phase1 $offset
set e1phase2 [expr $niter + $offset]
set e2phase2 $e1phase2
set e1phase3 [expr $e1phase2 + $niter]
set e2phase3 [expr $e2phase2 + $niter + $offset]
puts "\tRep$tnum.a: Running rep_test in 2nd replicated env."
eval rep_test $method $menv2 $masterdb2 $niter $e2phase1 1 1 0 $largs
eval rep_test $method $menv2 $masterdb2 $niter $e2phase2 1 1 0 $largs
eval rep_test $method $menv2 $masterdb2 $niter $e2phase3 1 1 0 $largs
error_check_good mdb_cl [$masterdb2 close] 0
process_msgs $env2list
puts "\tRep$tnum.b: Close 2nd replicated env. Open primary."
error_check_good mdb_cl [$clenv2 close] 0
error_check_good mdb_cl [$menv2 close] 0
replclose $testdir/MSGQUEUEDIR
#
# Run recovery in client now to blow away region files so
# that this client comes in as a "new" client and announces itself.
#
set stat [catch {eval exec $util_path/db_recover -h $clientdir2} result]
error_check_good stat $stat 0
#
# Now we've run in the 2nd env. We have everything we need
# set up and existing in that env. Now run the test in the
# 1st env and then we'll try to add in the client.
#
replsetup $testdir/MSGQUEUEDIR
# Open a master.
repladd 1
set ma_envcmd "berkdb_env -create $m_txnargs \
$m_logargs -home $masterdir \
-rep_master -rep_transport \[list 1 replsend\]"
# set ma_envcmd "berkdb_env -create $m_txnargs \
# $m_logargs -home $masterdir \
# -errpfx MASTER -verbose {rep on} \
# -rep_master -rep_transport \[list 1 replsend\]"
set menv [eval $ma_envcmd $recargs]
error_check_good master_env [is_valid_env $menv] TRUE
for {set i 0} {$i < $nclients} {incr i} {
set clientdir($i) $testdir/CLIENTDIR.$i
file mkdir $clientdir($i)
set c_logtype($i) [lindex $logset [expr $i + 1]]
set c_logargs($i) [adjust_logargs $c_logtype($i)]
set c_txnargs($i) [adjust_txnargs $c_logtype($i)]
set id($i) [expr 2 + $i]
repladd $id($i)
set cl_envcmd($i) "berkdb_env -create $c_txnargs($i) \
$c_logargs($i) -home $clientdir($i) \
-rep_client -rep_transport \[list $id($i) replsend\]"
# set cl_envcmd($i) "berkdb_env -create $c_txnargs($i) \
# $c_logargs($i) -home $clientdir($i) \
# -errpfx CLIENT$i -verbose {rep on} \
# -rep_client -rep_transport \[list $id($i) replsend\]"
set clenv($i) [eval $cl_envcmd($i) $recargs]
error_check_good client_env [is_valid_env $clenv($i)] TRUE
}
set masterdb [eval {berkdb_open_noerr -env $menv -auto_commit \
-create -mode 0644} $largs $omethod $testfile]
error_check_good dbopen [is_valid_db $masterdb] TRUE
# Bring the clients online by processing the startup messages.
set envlist {}
lappend envlist "$menv 1"
for { set i 0 } { $i < $nclients } { incr i } {
lappend envlist "$clenv($i) $id($i)"
}
process_msgs $envlist
# Run a modified test001 in the master (and update clients).
puts "\tRep$tnum.c: Running rep_test in primary replicated env."
eval rep_test $method $menv $masterdb $niter $e1phase1 1 1 0 $largs
eval rep_test $method $menv $masterdb $niter $e1phase2 1 1 0 $largs
eval rep_test $method $menv $masterdb $niter $e1phase3 1 1 0 $largs
error_check_good mdb_cl [$masterdb close] 0
# Process any close messages.
process_msgs $envlist
puts "\tRep$tnum.d: Add unrelated client into replication group."
set i $nclients
set orig $nclients
set nclients [expr $nclients + 1]
set clientdir($i) $clientdir2
set id($i) [expr 2 + $i]
repladd $id($i)
set cl_envcmd($i) "berkdb_env_noerr -create -txn nosync \
-home $clientdir($i) \
-rep_client -rep_transport \[list $id($i) replsend\]"
# set cl_envcmd($i) "berkdb_env -create -txn nosync \
# -errpfx CLIENT$i -verbose {rep on} \
# -home $clientdir($i) \
# -rep_client -rep_transport \[list $id($i) replsend\]"
set clenv($i) [eval $cl_envcmd($i) $recargs]
error_check_good client_env [is_valid_env $clenv($i)] TRUE
lappend envlist "$clenv($i) $id($i)"
fileremove -f $clientdir2/prlog.orig
set stat [catch {eval exec $util_path/db_printlog \
-h $clientdir2 >> $clientdir2/prlog.orig} result]
set err 0
process_msgs $envlist 0 NONE err
puts "\tRep$tnum.e: Close all envs and run recovery in clients."
error_check_good menv_cl [$menv close] 0
for {set i 0} {$i < $nclients} {incr i} {
error_check_good cl$i.close [$clenv($i) close] 0
set hargs($i) "-h $clientdir($i)"
}
set i [expr $nclients - 1]
fileremove -f $clientdir($i)/prlog
set stat [catch {eval exec $util_path/db_printlog \
-h $clientdir($i) >> $clientdir($i)/prlog} result]
#
# If we got an error, then the log should match the original
# and the error message should tell us the client was never
# part of this environment.
#
if { $err != 0 } {
puts "\tRep$tnum.f: Verify client log matches original."
error_check_good log_cmp(orig,$i) \
[filecmp $clientdir($i)/prlog.orig $clientdir($i)/prlog] 0
puts "\tRep$tnum.g: Verify client error."
error_check_good errchk [is_substr $err \
"Client was never part"] 1
} else {
puts "\tRep$tnum.f: Verify client log doesn't match original."
error_check_good log_cmp(orig,$i) \
[filecmp $clientdir($i)/prlog.orig $clientdir($i)/prlog] 1
puts "\tRep$tnum.g: Verify new client log matches master."
set stat [catch {eval exec $util_path/db_printlog \
-h $masterdir >& $masterdir/prlog} result]
fileremove -f $clientdir($i)/prlog
set stat [catch {eval exec $util_path/db_printlog \
-h $clientdir($i) >> $clientdir($i)/prlog} result]
error_check_good stat_prlog $stat 0
error_check_good log_cmp(master,$i) \
[filecmp $masterdir/prlog $clientdir($i)/prlog] 0
}
replclose $testdir/MSGQUEUEDIR
set testdir $orig_tdir
return
}
|