1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2004-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# TEST rep029 8# TEST Test of internal initialization. 9# TEST 10# TEST One master, one client. 11# TEST Generate several log files. 12# TEST Remove old master log files. 13# TEST Delete client files and restart client. 14# TEST Put one more record to the master. 15# 16proc rep029 { method { niter 200 } { tnum "029" } args } { 17 18 source ./include.tcl 19 global databases_in_memory 20 global repfiles_in_memory 21 22 if { $is_windows9x_test == 1 } { 23 puts "Skipping replication test on Win 9x platform." 24 return 25 } 26 if { $checking_valid_methods } { 27 return "ALL" 28 } 29 global passwd 30 global has_crypto 31 32 set args [convert_args $method $args] 33 set saved_args $args 34 35 # Set up for on-disk or in-memory databases. 36 set msg "using on-disk databases" 37 if { $databases_in_memory } { 38 set msg "using named in-memory databases" 39 if { [is_queueext $method] } { 40 puts -nonewline "Skipping rep$tnum for method " 41 puts "$method with named in-memory databases." 42 return 43 } 44 } 45 46 set msg2 "and on-disk replication files" 47 if { $repfiles_in_memory } { 48 set msg2 "and in-memory replication files" 49 } 50 51 # This test needs to set its own pagesize. 52 set pgindex [lsearch -exact $args "-pagesize"] 53 if { $pgindex != -1 } { 54 puts "Rep$tnum: skipping for specific pagesizes" 55 return 56 } 57 58 set logsets [create_logsets 2] 59 60 # Run the body of the test with and without recovery, 61 # and with and without cleaning. Skip recovery with in-memory 62 # logging - it doesn't make sense. 63 set opts { bulk clean noclean } 64 foreach r $test_recopts { 65 foreach c $opts { 66 foreach l $logsets { 67 set logindex [lsearch -exact $l "in-memory"] 68 if { $r == "-recover" && $logindex != -1 } { 69 puts "Skipping rep$tnum for -recover\ 70 with in-memory logs." 71 continue 72 } 73 set envargs "" 74 set args $saved_args 75 puts "Rep$tnum ($method $envargs $r $c $args):\ 76 Test of internal initialization $msg $msg2." 77 puts "Rep$tnum: Master logs are [lindex $l 0]" 78 puts "Rep$tnum: Client logs are [lindex $l 1]" 79 rep029_sub $method $niter $tnum $envargs \ 80 $l $r $c $args 81 82 # Skip encrypted tests if not supported. 83 if { $has_crypto == 0 || $databases_in_memory } { 84 continue 85 } 86 87 # Run same set of tests with security. 88 # 89 append envargs " -encryptaes $passwd " 90 append args " -encrypt " 91 puts "Rep$tnum ($method $envargs $r $c $args):\ 92 Test of internal initialization $msg $msg2." 93 puts "Rep$tnum: Master logs are [lindex $l 0]" 94 puts "Rep$tnum: Client logs are [lindex $l 1]" 95 rep029_sub $method $niter $tnum $envargs \ 96 $l $r $c $args 97 } 98 } 99 } 100} 101 102proc rep029_sub { method niter tnum envargs logset recargs opts largs } { 103 global testdir 104 global passwd 105 global util_path 106 global databases_in_memory 107 global repfiles_in_memory 108 global rep_verbose 109 global verbose_type 110 111 set verbargs "" 112 if { $rep_verbose == 1 } { 113 set verbargs " -verbose {$verbose_type on} " 114 } 115 116 set repmemargs "" 117 if { $repfiles_in_memory } { 118 set repmemargs "-rep_inmem_files " 119 } 120 121 env_cleanup $testdir 122 123 replsetup $testdir/MSGQUEUEDIR 124 125 set masterdir $testdir/MASTERDIR 126 set clientdir $testdir/CLIENTDIR 127 128 file mkdir $masterdir 129 file mkdir $clientdir 130 131 # Log size is small so we quickly create more than one. 132 # The documentation says that the log file must be at least 133 # four times the size of the in-memory log buffer. 134 set pagesize 4096 135 append largs " -pagesize $pagesize " 136 set log_max [expr $pagesize * 8] 137 138 set m_logtype [lindex $logset 0] 139 set c_logtype [lindex $logset 1] 140 141 # In-memory logs cannot be used with -txn nosync. 142 set m_logargs [adjust_logargs $m_logtype] 143 set c_logargs [adjust_logargs $c_logtype] 144 set m_txnargs [adjust_txnargs $m_logtype] 145 set c_txnargs [adjust_txnargs $c_logtype] 146 147 # Open a master. 148 repladd 1 149 set ma_envcmd "berkdb_env_noerr -create $m_txnargs $repmemargs \ 150 $m_logargs -log_max $log_max $envargs $verbargs \ 151 -errpfx MASTER -home $masterdir \ 152 -rep_transport \[list 1 replsend\]" 153 set masterenv [eval $ma_envcmd $recargs -rep_master] 154 155 # Open a client 156 repladd 2 157 set cl_envcmd "berkdb_env_noerr -create $c_txnargs $repmemargs \ 158 $c_logargs -log_max $log_max $envargs $verbargs \ 159 -errpfx CLIENT -home $clientdir \ 160 -rep_transport \[list 2 replsend\]" 161 set clientenv [eval $cl_envcmd $recargs -rep_client] 162 163 # Bring the clients online by processing the startup messages. 164 set envlist "{$masterenv 1} {$clientenv 2}" 165 process_msgs $envlist 166 167 # Clobber replication's 30-second anti-archive timer, which will have 168 # been started by client sync-up internal init, so that we can do a 169 # log_archive in a moment. 170 # 171 $masterenv test force noarchive_timeout 172 173 # Run rep_test in the master (and update client). 174 puts "\tRep$tnum.a: Running rep_test in replicated env." 175 set start 0 176 eval rep_test $method $masterenv NULL $niter $start $start 0 $largs 177 incr start $niter 178 process_msgs $envlist 0 NONE err 179 error_check_good process_msgs $err 0 180 181 if { [lsearch $envargs "-encrypta*"] !=-1 } { 182 set enc "-P $passwd" 183 } else { 184 set enc "" 185 } 186 187 # Find out what exists on the client. We need to loop until 188 # the first master log file > last client log file. 189 puts "\tRep$tnum.b: Close client." 190 if { $c_logtype != "in-memory" } { 191 set res [eval exec $util_path/db_archive $enc -l -h $clientdir] 192 } 193 set last_client_log [get_logfile $clientenv last] 194 error_check_good client_close [$clientenv close] 0 195 196 set stop 0 197 while { $stop == 0 } { 198 # Run rep_test in the master (don't update client). Each time 199 # through the loop, start at the same $start value (i.e., don't 200 # increment $start). Since all we're trying to do is to fill up 201 # the log, it doesn't matter whether we insert new records or 202 # rewrite existing ones. But if we insert new records we might 203 # fill up the cache, which is fatal in the in-memory database 204 # case. 205 # 206 puts "\tRep$tnum.c: Running rep_test in replicated env." 207 eval rep_test $method $masterenv NULL $niter $start $start 0 $largs 208 replclear 2 209 210 puts "\tRep$tnum.d: Run db_archive on master." 211 if { $m_logtype != "in-memory"} { 212 set res [eval exec $util_path/db_archive $enc -d -h $masterdir] 213 } 214 set first_master_log [get_logfile $masterenv first] 215 if { $first_master_log > $last_client_log } { 216 set stop 1 217 } 218 } 219 220 puts "\tRep$tnum.e: Reopen client ($opts)." 221 if { $opts == "clean" } { 222 env_cleanup $clientdir 223 } 224 if { $opts == "bulk" } { 225 error_check_good bulk [$masterenv rep_config {bulk on}] 0 226 } 227 set clientenv [eval $cl_envcmd $recargs -rep_client] 228 error_check_good client_env [is_valid_env $clientenv] TRUE 229 set envlist "{$masterenv 1} {$clientenv 2}" 230 process_msgs $envlist 0 NONE err 231 error_check_good process_msgs $err 0 232 if { $opts != "clean" } { 233 puts "\tRep$tnum.e.1: Trigger log request" 234 # 235 # When we don't clean, starting the client doesn't 236 # trigger any events. We need to generate some log 237 # records so that the client requests the missing 238 # logs and that will trigger it. 239 # 240 set entries 10 241 eval rep_test\ 242 $method $masterenv NULL $entries $start $start 0 $largs 243 incr start $entries 244 process_msgs $envlist 0 NONE err 245 error_check_good process_msgs $err 0 246 } 247 248 puts "\tRep$tnum.f: Verify databases" 249 # 250 # If doing bulk testing, turn it off now so that it forces us 251 # to flush anything currently in the bulk buffer. We need to 252 # do this because rep_test might have aborted a transaction on 253 # its last iteration and those log records would still be in 254 # the bulk buffer causing the log comparison to fail. 255 # 256 if { $opts == "bulk" } { 257 puts "\tRep$tnum.f.1: Turn off bulk transfers." 258 error_check_good bulk [$masterenv rep_config {bulk off}] 0 259 process_msgs $envlist 0 NONE err 260 error_check_good process_msgs $err 0 261 } 262 263 # 264 # !!! This test CANNOT use rep_verify for logs due to encryption. 265 # Just compare databases. We either have to copy in 266 # all the code in rep_verify to adjust the beginning LSN 267 # or skip the log check for just this one test. 268 269 rep_verify $masterdir $masterenv $clientdir $clientenv 1 1 0 270 271 # Add records to the master and update client. 272 puts "\tRep$tnum.g: Add more records and check again." 273 set entries 10 274 eval rep_test $method $masterenv NULL $entries $start $start 0 $largs 275 incr start $entries 276 process_msgs $envlist 0 NONE err 277 error_check_good process_msgs $err 0 278 279 rep_verify $masterdir $masterenv $clientdir $clientenv 1 1 0 280 281 set bulkxfer [stat_field $masterenv rep_stat "Bulk buffer transfers"] 282 if { $opts == "bulk" } { 283 error_check_bad bulkxferon $bulkxfer 0 284 } else { 285 error_check_good bulkxferoff $bulkxfer 0 286 } 287 288 error_check_good masterenv_close [$masterenv close] 0 289 error_check_good clientenv_close [$clientenv close] 0 290 replclose $testdir/MSGQUEUEDIR 291} 292 293