1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2002, 2010 Oracle and/or its affiliates. All rights reserved.
8
# TEST Repeated shutdown/restart replication test
10
# TEST Run a quick put test in a replicated master environment;
11
# TEST start up, shut down, and restart client processes, with
12
# TEST and without recovery. To ensure that environment state
13
# TEST is transient, use DB_PRIVATE.
15
proc rep003 { method { tnum "003" } args } {
17
global rep003_dbname rep003_omethod rep003_oargs
18
global repfiles_in_memory
20
# Skip for record-based methods.
21
if { $checking_valid_methods } {
23
foreach method $valid_methods {
24
if { [is_record_based $method] != 1 } {
25
lappend test_methods $method
30
if { [is_record_based $method] } {
31
puts "Rep$tnum: Skipping for method $method"
35
set msg2 "with on-disk replication files"
36
if { $repfiles_in_memory } {
37
set msg2 "with in-memory replication files"
40
set rep003_dbname rep003.db
41
set rep003_omethod [convert_method $method]
42
set rep003_oargs [convert_args $method $args]
44
# Run the body of the test with and without recovery. If we're
45
# testing in-memory logging, skip the combination of recovery
46
# and in-memory logging -- it doesn't make sense.
48
set logsets [create_logsets 2]
49
foreach recopt $test_recopts {
51
set logindex [lsearch -exact $l "in-memory"]
52
if { $recopt == "-recover" && $logindex != -1 } {
53
puts "Rep$tnum: Skipping for\
54
in-memory logs with -recover."
57
puts "Rep$tnum ($method $recopt):\
58
Replication repeated-startup test $msg2."
59
puts "Rep$tnum: Master logs are [lindex $l 0]"
60
puts "Rep$tnum: Client logs are [lindex $l 1]"
61
rep003_sub $method $tnum $l $recopt $args
66
proc rep003_sub { method tnum logset recargs largs } {
68
global repfiles_in_memory
73
if { $rep_verbose == 1 } {
74
set verbargs " -verbose {$verbose_type on} "
78
if { $repfiles_in_memory } {
79
set repmemargs "-rep_inmem_files "
84
replsetup $testdir/MSGQUEUEDIR
86
set masterdir $testdir/MASTERDIR
87
set clientdir $testdir/CLIENTDIR
92
set m_logtype [lindex $logset 0]
93
set c_logtype [lindex $logset 1]
95
# In-memory logs require a large log buffer, and cannot
96
# be used with -txn nosync. This test already requires
97
# -txn, so adjust the logargs only.
98
set m_logargs [adjust_logargs $m_logtype]
99
set c_logargs [adjust_logargs $c_logtype]
103
set env_cmd(M) "berkdb_env_noerr -create -log_max 1000000 \
104
-errpfx MASTER $verbargs $repmemargs \
105
-home $masterdir -txn $m_logargs -rep_master \
106
-rep_transport \[list 1 replsend\]"
107
set masterenv [eval $env_cmd(M) $recargs]
108
error_check_good master_env [is_valid_env $masterenv] TRUE
110
puts "\tRep$tnum.a: Simple client startup test."
113
rep003_put $masterenv A1 a-one
117
set env_cmd(C) "berkdb_env_noerr -create -private -home $clientdir \
118
-txn $c_logargs -errpfx CLIENT $verbargs $repmemargs \
119
-rep_client -rep_transport \[list 2 replsend\]"
120
set clientenv [eval $env_cmd(C) $recargs]
121
error_check_good client_env [is_valid_env $clientenv] TRUE
123
# Put another quick item.
124
rep003_put $masterenv A2 a-two
126
# Loop, processing first the master's messages, then the client's,
127
# until both queues are empty.
128
set envlist "{$masterenv 1} {$clientenv 2}"
129
process_msgs $envlist
131
rep003_check $clientenv A1 a-one
132
rep003_check $clientenv A2 a-two
134
error_check_good clientenv_close [$clientenv close] 0
137
# Now reopen the client after doing another put.
138
puts "\tRep$tnum.b: Client restart."
139
rep003_put $masterenv B1 b-one
141
set clientenv [eval $env_cmd(C)]
142
error_check_good client_env [is_valid_env $clientenv] TRUE
144
# Loop letting the client and master sync up and get the
145
# environment initialized. It's a new client env so
146
# reinitialize the envlist as well.
147
set envlist "{$masterenv 1} {$clientenv 2}"
148
process_msgs $envlist
150
# The items from part A should be present at all times--
151
# if we roll them back, we've screwed up. [#5709]
152
rep003_check $clientenv A1 a-one
153
rep003_check $clientenv A2 a-two
155
rep003_put $masterenv B2 b-two
157
# Loop, processing first the master's messages, then the client's,
158
# until both queues are empty.
162
incr nproced [replprocessqueue $masterenv 1]
163
incr nproced [replprocessqueue $clientenv 2]
165
# The items from part A should be present at all times--
166
# if we roll them back, we've screwed up. [#5709]
167
rep003_check $clientenv A1 a-one
168
rep003_check $clientenv A2 a-two
170
if { $nproced == 0 } {
175
rep003_check $clientenv B1 b-one
176
rep003_check $clientenv B2 b-two
178
error_check_good clientenv_close [$clientenv close] 0
182
# Now reopen the client after a recovery.
183
puts "\tRep$tnum.c: Client restart after recovery."
184
rep003_put $masterenv C1 c-one
186
set clientenv [eval $env_cmd(C) -recover]
187
error_check_good client_env [is_valid_env $clientenv] TRUE
189
# Loop, processing first the master's messages, then the client's,
190
# until both queues are empty.
191
set envlist "{$masterenv 1} {$clientenv 2}"
192
process_msgs $envlist
194
# The items from part A should be present at all times--
195
# if we roll them back, we've screwed up. [#5709]
196
rep003_check $clientenv A1 a-one
197
rep003_check $clientenv A2 a-two
198
rep003_check $clientenv B1 b-one
199
rep003_check $clientenv B2 b-two
201
rep003_put $masterenv C2 c-two
203
# Loop, processing first the master's messages, then the client's,
204
# until both queues are empty.
208
# The items from part A should be present at all times--
209
# if we roll them back, we've screwed up. [#5709]
210
rep003_check $clientenv A1 a-one
211
rep003_check $clientenv A2 a-two
212
rep003_check $clientenv B1 b-one
213
rep003_check $clientenv B2 b-two
215
incr nproced [replprocessqueue $masterenv 1]
216
incr nproced [replprocessqueue $clientenv 2]
218
if { $nproced == 0 } {
223
rep003_check $clientenv C1 c-one
224
rep003_check $clientenv C2 c-two
226
error_check_good clientenv_close [$clientenv close] 0
230
# Now reopen the client after a catastrophic recovery.
231
puts "\tRep$tnum.d: Client restart after catastrophic recovery."
232
rep003_put $masterenv D1 d-one
234
set clientenv [eval $env_cmd(C) -recover_fatal]
235
error_check_good client_env [is_valid_env $clientenv] TRUE
237
# Loop, processing first the master's messages, then the client's,
238
# until both queues are empty.
239
set envlist "{$masterenv 1} {$clientenv 2}"
240
process_msgs $envlist
241
rep003_put $masterenv D2 d-two
243
# Loop, processing first the master's messages, then the client's,
244
# until both queues are empty.
248
# The items from part A should be present at all times--
249
# if we roll them back, we've screwed up. [#5709]
250
rep003_check $clientenv A1 a-one
251
rep003_check $clientenv A2 a-two
252
rep003_check $clientenv B1 b-one
253
rep003_check $clientenv B2 b-two
254
rep003_check $clientenv C1 c-one
255
rep003_check $clientenv C2 c-two
257
incr nproced [replprocessqueue $masterenv 1]
258
incr nproced [replprocessqueue $clientenv 2]
260
if { $nproced == 0 } {
265
rep003_check $clientenv D1 d-one
266
rep003_check $clientenv D2 d-two
268
error_check_good clientenv_close [$clientenv close] 0
270
error_check_good masterenv_close [$masterenv close] 0
271
replclose $testdir/MSGQUEUEDIR
274
proc rep003_put { masterenv key data } {
275
global rep003_dbname rep003_omethod rep003_oargs
277
set db [eval {berkdb_open_noerr -create -env $masterenv -auto_commit} \
278
$rep003_omethod $rep003_oargs $rep003_dbname]
279
error_check_good rep3_put_open($key,$data) [is_valid_db $db] TRUE
281
set txn [$masterenv txn]
282
error_check_good rep3_put($key,$data) [$db put -txn $txn $key $data] 0
283
error_check_good rep3_put_txn_commit($key,$data) [$txn commit] 0
285
error_check_good rep3_put_close($key,$data) [$db close] 0
288
proc rep003_check { env key data } {
291
set db [berkdb_open_noerr -rdonly -env $env $rep003_dbname]
292
error_check_good rep3_check_open($key,$data) [is_valid_db $db] TRUE
294
set dbt [$db get $key]
295
error_check_good rep3_check($key,$data) \
296
[lindex [lindex $dbt 0] 1] $data
298
error_check_good rep3_put_close($key,$data) [$db close] 0