3
# Sleepycat Software. All rights reserved.
8
# TEST Test of DB_REP_LOGSONLY.
10
# TEST Run a quick put test in a master environment that has one logs-only
11
# TEST client. Shut down, then run catastrophic recovery in the logs-only
12
# TEST client and check that the database is present and populated.
14
proc rep004 { method { nitems 10 } { tnum "04" } args } {
19
set dbname rep0$tnum.db
21
set omethod [convert_method $method]
22
set oargs [convert_args $method $args]
24
puts "Rep0$tnum: Test of logs-only replication clients"
26
replsetup $testdir/MSGQUEUEDIR
27
set masterdir $testdir/MASTERDIR
29
set clientdir $testdir/CLIENTDIR
31
set logsonlydir $testdir/LOGSONLYDIR
32
file mkdir $logsonlydir
34
# Open a master, a logsonly replica, and a normal client.
36
set masterenv [berkdb_env -create -home $masterdir -txn -rep_master \
37
-rep_transport [list 1 replsend]]
38
error_check_good master_env [is_valid_env $masterenv] TRUE
41
set loenv [berkdb_env -create -home $logsonlydir -txn -rep_logsonly \
42
-rep_transport [list 2 replsend]]
43
error_check_good logsonly_env [is_valid_env $loenv] TRUE
46
set clientenv [berkdb_env -create -home $clientdir -txn -rep_client \
47
-rep_transport [list 3 replsend]]
48
error_check_good client_env [is_valid_env $clientenv] TRUE
51
puts "\tRep0$tnum.a: Populate database."
53
set db [eval {berkdb open -create -mode 0644 -auto_commit} \
54
-env $masterenv $oargs $omethod $dbname]
55
error_check_good dbopen [is_valid_db $db] TRUE
59
while { [gets $did str] != -1 && $count < $nitems } {
60
if { [is_record_based $method] == 1 } {
61
set key [expr $count + 1]
65
set data [reverse $str]
67
set kvals($count) $key
68
set dvals($count) [pad_data $method $data]
70
set txn [$masterenv txn]
71
error_check_good txn($count) [is_valid_txn $txn $masterenv] TRUE
74
{$db put} -txn $txn {$key [chop_data $method $data]}]
75
error_check_good put($count) $ret 0
77
error_check_good commit($count) [$txn commit] 0
82
puts "\tRep0$tnum.b: Sync up clients."
87
incr nproced [replprocessqueue $masterenv 1]
88
incr nproced [replprocessqueue $loenv 2]
89
incr nproced [replprocessqueue $clientenv 3]
91
if { $nproced == 0 } {
97
puts "\tRep0$tnum.c: Get master and logs-only client ahead."
99
while { [gets $did str] != -1 && $newcount < $nitems } {
100
if { [is_record_based $method] == 1 } {
101
set key [expr $count + 1]
105
set data [reverse $str]
107
set kvals($count) $key
108
set dvals($count) [pad_data $method $data]
110
set txn [$masterenv txn]
111
error_check_good txn($count) [is_valid_txn $txn $masterenv] TRUE
114
{$db put} -txn $txn {$key [chop_data $method $data]}]
115
error_check_good put($count) $ret 0
117
error_check_good commit($count) [$txn commit] 0
123
error_check_good db_close [$db close] 0
125
puts "\tRep0$tnum.d: Sync up logs-only client only, then fail over."
130
incr nproced [replprocessqueue $masterenv 1]
131
incr nproced [replprocessqueue $loenv 2]
133
if { $nproced == 0 } {
139
# "Crash" the master, and fail over to the upgradeable client.
140
error_check_good masterenv_close [$masterenv close] 0
143
error_check_good upgrade_client [$clientenv rep_start -master] 0
148
incr nproced [replprocessqueue $clientenv 3]
149
incr nproced [replprocessqueue $loenv 2]
151
if { $nproced == 0 } {
156
error_check_good loenv_close [$loenv close] 0
158
puts "\tRep0$tnum.e: Run catastrophic recovery on logs-only client."
159
set loenv [berkdb_env -create -home $logsonlydir -txn -recover_fatal]
161
puts "\tRep0$tnum.f: Verify logs-only client contents."
162
set lodb [eval {berkdb open} -env $loenv $oargs $omethod $dbname]
163
set loc [$lodb cursor]
165
set cdb [eval {berkdb open} -env $clientenv $oargs $omethod $dbname]
168
# Make sure new master and recovered logs-only replica match.
169
for { set cdbt [$cc get -first] } \
170
{ [llength $cdbt] > 0 } { set cdbt [$cc get -next] } {
171
set lodbt [$loc get -next]
173
error_check_good newmaster_replica_match $cdbt $lodbt
176
# Reset new master cursor.
177
error_check_good cc_close [$cc close] 0
180
for { set lodbt [$loc get -first] } \
181
{ [llength $lodbt] > 0 } { set lodbt [$loc get -next] } {
182
set cdbt [$cc get -next]
184
error_check_good replica_newmaster_match $lodbt $cdbt
187
error_check_good loc_close [$loc close] 0
188
error_check_good lodb_close [$lodb close] 0
189
error_check_good loenv_close [$loenv close] 0
191
error_check_good cc_close [$cc close] 0
192
error_check_good cdb_close [$cdb close] 0
193
error_check_good clientenv_close [$clientenv close] 0
197
replclose $testdir/MSGQUEUEDIR