1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2004,2008 Oracle. All rights reserved. 4# 5# $Id: rep052.tcl,v 12.18 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST rep052 8# TEST Test of replication with NOWAIT. 9# TEST 10# TEST One master, one client. After initializing 11# TEST everything normally, close client and let the 12# TEST master get ahead -- far enough that the master 13# TEST no longer has the client's last log file. 14# TEST Reopen the client and turn on NOWAIT. 15# TEST Process a few messages to get the client into 16# TEST recovery mode, and verify that lockout occurs 17# TEST on a txn API call (txn_begin) and an env API call. 18# TEST Process all the messages and verify that lockout 19# TEST is over. 20 21proc rep052 { method { niter 200 } { tnum "052" } args } { 22 23 source ./include.tcl 24 if { $is_windows9x_test == 1 } { 25 puts "Skipping replication test on Win 9x platform." 26 return 27 } 28 29 # Valid for all access methods. 30 if { $checking_valid_methods } { 31 return "ALL" 32 } 33 34 set args [convert_args $method $args] 35 set saved_args $args 36 37 # This test needs to set its own pagesize. 38 set pgindex [lsearch -exact $args "-pagesize"] 39 if { $pgindex != -1 } { 40 puts "Rep$tnum: skipping for specific pagesizes" 41 return 42 } 43 44 set logsets [create_logsets 2] 45 set saved_args $args 46 47 # Run the body of the test with and without recovery. Skip 48 # recovery with in-memory logging - it doesn't make sense. 49 foreach r $test_recopts { 50 foreach l $logsets { 51 set logindex [lsearch -exact $l "in-memory"] 52 if { $r == "-recover" && $logindex != -1 } { 53 puts "Skipping rep$tnum for -recover\ 54 with in-memory logs." 55 continue 56 } 57 set envargs "" 58 set args $saved_args 59 puts "Rep$tnum ($method $envargs $r $args):\ 60 Test lockouts with REP_NOWAIT." 61 puts "Rep$tnum: Master logs are [lindex $l 0]" 62 puts "Rep$tnum: Client logs are [lindex $l 1]" 63 rep052_sub $method $niter $tnum $envargs \ 64 $l $r $args 65 } 66 } 67} 68 69proc rep052_sub { method niter tnum envargs logset recargs largs } { 70 global testdir 71 global util_path 72 global rep_verbose 73 global verbose_type 74 75 set verbargs "" 76 if { $rep_verbose == 1 } { 77 set verbargs " -verbose {$verbose_type on} " 78 } 79 80 env_cleanup $testdir 81 82 replsetup $testdir/MSGQUEUEDIR 83 84 set masterdir $testdir/MASTERDIR 85 set clientdir $testdir/CLIENTDIR 86 87 file mkdir $masterdir 88 file mkdir $clientdir 89 90 # Log size is small so we quickly create more than one. 91 # The documentation says that the log file must be at least 92 # four times the size of the in-memory log buffer. 93 set pagesize 4096 94 append largs " -pagesize $pagesize " 95 set log_max [expr $pagesize * 8] 96 97 set m_logtype [lindex $logset 0] 98 set c_logtype [lindex $logset 1] 99 100 # In-memory logs cannot be used with -txn nosync. 101 set m_txnargs [adjust_txnargs $m_logtype] 102 set c_txnargs [adjust_txnargs $c_logtype] 103 set m_logargs [adjust_logargs $m_logtype] 104 set c_logargs [adjust_logargs $c_logtype] 105 106 # Open a master. 107 repladd 1 108 set ma_envcmd "berkdb_env_noerr -create $m_txnargs $verbargs \ 109 $m_logargs -log_max $log_max $envargs -errpfx MASTER \ 110 -home $masterdir -rep_transport \[list 1 replsend\]" 111 set masterenv [eval $ma_envcmd $recargs -rep_master] 112 $masterenv rep_limit 0 0 113 114 # Open a client 115 repladd 2 116 set cl_envcmd "berkdb_env_noerr -create $c_txnargs $verbargs \ 117 $c_logargs -log_max $log_max $envargs -errpfx CLIENT \ 118 -home $clientdir -rep_transport \[list 2 replsend\]" 119 set clientenv [eval $cl_envcmd $recargs -rep_client] 120 $clientenv rep_limit 0 0 121 122 # Bring the clients online by processing the startup messages. 123 set envlist "{$masterenv 1} {$clientenv 2}" 124 process_msgs $envlist 125 126 # Clobber replication's 30-second anti-archive timer, which will have 127 # been started by client sync-up internal init, so that we can do a 128 # log_archive in a moment. 129 # 130 $masterenv test force noarchive_timeout 131 132 # Run rep_test in the master (and update client). 133 puts "\tRep$tnum.a: Running rep_test in replicated env." 134 set start 0 135 eval rep_test $method $masterenv NULL $niter $start $start 0 0 $largs 136 incr start $niter 137 process_msgs $envlist 138 139 # Find out what exists on the client before closing. We'll need 140 # to loop until the first master log file > last client log file. 141 set last_client_log [get_logfile $clientenv last] 142 143 puts "\tRep$tnum.b: Close client." 144 error_check_good client_close [$clientenv close] 0 145 146 # Find out what exists on the client. We need to loop until 147 # the first master log file > last client log file. 148 149 set stop 0 150 while { $stop == 0 } { 151 # Run rep_test in the master (don't update client). 152 puts "\tRep$tnum.c: Running rep_test in replicated env." 153 eval rep_test \ 154 $method $masterenv NULL $niter $start $start 0 0 $largs 155 incr start $niter 156 replclear 2 157 158 puts "\tRep$tnum.d: Run db_archive on master." 159 if { $m_logtype != "in-memory" } { 160 set res \ 161 [eval exec $util_path/db_archive -d -h $masterdir] 162 } 163 # Make sure we have a gap between the last client log and 164 # the first master log. This is easy with on-disk logs, since 165 # we archive, but will take longer with in-memory logging. 166 set first_master_log [get_logfile $masterenv first] 167 if { $first_master_log > $last_client_log } { 168 set stop 1 169 } 170 } 171 172 puts "\tRep$tnum.e: Reopen client." 173 env_cleanup $clientdir 174 set clientenv [eval $cl_envcmd $recargs -rep_client] 175 error_check_good client_env [is_valid_env $clientenv] TRUE 176 $clientenv rep_limit 0 0 177 set envlist "{$masterenv 1} {$clientenv 2}" 178 179 # Turn on nowait. 180 $clientenv rep_config {nowait on} 181 182 # Process messages a few times, just enough to get client 183 # into lockout/recovery mode, but not enough to complete recovery. 184 set iter 3 185 for { set i 0 } { $i < $iter } { incr i } { 186 set nproced [proc_msgs_once $envlist NONE err] 187 } 188 189 puts "\tRep$tnum.f: Verify we are locked out of txn API calls." 190 if { [catch { set txn [$clientenv txn] } res] } { 191 error_check_good txn_lockout [is_substr $res "DB_REP_LOCKOUT"] 1 192 } else { 193 error "FAIL:[timestamp] Not locked out of txn API calls." 194 } 195 196 puts "\tRep$tnum.g: Verify we are locked out of env API calls." 197 if { [catch { set stat [$clientenv lock_stat] } res] } { 198 error_check_good env_lockout [is_substr $res "DB_REP_LOCKOUT"] 1 199 } else { 200 error "FAIL:[timestamp] Not locked out of env API calls." 201 } 202 203 # Now catch up and make sure we're not locked out anymore. 204 process_msgs $envlist 205 206 puts "\tRep$tnum.h: No longer locked out of txn API calls." 207 if { [catch { set txn [$clientenv txn] } res] } { 208 puts "FAIL: unable to start txn: $res" 209 } else { 210 error_check_good txn_no_lockout [$txn commit] 0 211 } 212 213 puts "\tRep$tnum.i: No longer locked out of env API calls." 214 if { [catch { set stat [$clientenv rep_stat] } res] } { 215 puts "FAIL: unable to make env call: $res" 216 } 217 218 puts "\tRep$tnum.h: Verify logs and databases" 219 rep_verify $masterdir $masterenv $clientdir $clientenv 1 220 221 error_check_good masterenv_close [$masterenv close] 0 222 error_check_good clientenv_close [$clientenv close] 0 223 replclose $testdir/MSGQUEUEDIR 224} 225