1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2004,2008 Oracle. All rights reserved. 4# 5# $Id: rep055.tcl,v 1.16 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST rep055 8# TEST Test of internal initialization and log archiving. 9# TEST 10# TEST One master, one client. 11# TEST Generate several log files. 12# TEST Remove old master log files and generate several more. 13# TEST Get list of archivable files from db_archive and restart client. 14# TEST As client is in the middle of internal init, remove 15# TEST the log files returned earlier by db_archive. 16# 17proc rep055 { method { niter 200 } { tnum "055" } args } { 18 19 source ./include.tcl 20 global mixed_mode_logging 21 22 if { $is_windows9x_test == 1 } { 23 puts "Skipping replication test on Win 9x platform." 24 return 25 } 26 27 # Valid for all access methods. 28 if { $checking_valid_methods } { 29 return "ALL" 30 } 31 32 # This test needs to set its own pagesize. 33 set pgindex [lsearch -exact $args "-pagesize"] 34 if { $pgindex != -1 } { 35 puts "Rep$tnum: skipping for specific pagesizes" 36 return 37 } 38 39 # This test is all about log archive issues, so don't run with 40 # in-memory logging. 41 if { $mixed_mode_logging > 0 } { 42 puts "Rep$tnum: Skipping for mixed-mode logging." 43 return 44 } 45 46 # Run the body of the test with and without recovery, 47 # and with and without cleaning. 48 set opts { clean noclean } 49 foreach r $test_recopts { 50 foreach c $opts { 51 puts "Rep$tnum ($method $r $c $args):\ 52 Test of internal initialization." 53 rep055_sub $method $niter $tnum $r $c $args 54 55 } 56 } 57} 58 59proc rep055_sub { method niter tnum recargs opts largs } { 60 global testdir 61 global passwd 62 global util_path 63 global rep_verbose 64 global verbose_type 65 66 set verbargs "" 67 if { $rep_verbose == 1 } { 68 set verbargs " -verbose {$verbose_type on} " 69 } 70 71 env_cleanup $testdir 72 73 replsetup $testdir/MSGQUEUEDIR 74 75 set masterdir $testdir/MASTERDIR 76 set clientdir $testdir/CLIENTDIR 77 78 file mkdir $masterdir 79 file mkdir $clientdir 80 81 # Log size is small so we quickly create more than one. 82 set pagesize 4096 83 append largs " -pagesize $pagesize " 84 set log_buf [expr $pagesize * 2] 85 set log_max [expr $log_buf * 4] 86 87 # Open a master. 88 repladd 1 89 set ma_envcmd "berkdb_env_noerr -create -txn nosync $verbargs \ 90 -log_buffer $log_buf -log_max $log_max -errpfx MASTER \ 91 -home $masterdir -rep_transport \[list 1 replsend\]" 92 set masterenv [eval $ma_envcmd $recargs -rep_master] 93 $masterenv rep_limit 0 0 94 95 # Open a client 96 repladd 2 97 set cl_envcmd "berkdb_env_noerr -create -txn nosync $verbargs \ 98 -log_buffer $log_buf -log_max $log_max -errpfx CLIENT \ 99 -home $clientdir -rep_transport \[list 2 replsend\]" 100 set clientenv [eval $cl_envcmd $recargs -rep_client] 101 $clientenv rep_limit 0 0 102 103 # Bring the clients online by processing the startup messages. 104 set envlist "{$masterenv 1} {$clientenv 2}" 105 process_msgs $envlist 106 107 # Clobber replication's 30-second anti-archive timer, which will have 108 # been started by client sync-up internal init, so that we can do a 109 # log_archive in a moment. 110 # 111 $masterenv test force noarchive_timeout 112 113 # Run rep_test in the master (and update client). 114 puts "\tRep$tnum.a: Running rep_test in replicated env." 115 eval rep_test $method $masterenv NULL $niter 0 0 0 0 $largs 116 process_msgs $envlist 117 118 puts "\tRep$tnum.b: Close client." 119 error_check_good client_close [$clientenv close] 0 120 121 # Find out what exists on the client. We need to loop until 122 # the first master log file > last client log file. 123 # This forces internal init to happen. 124 125 set res [eval exec $util_path/db_archive -l -h $clientdir] 126 set last_client_log [lindex [lsort $res] end] 127 set stop 0 128 while { $stop == 0 } { 129 # Run rep_test in the master (don't update client). 130 puts "\tRep$tnum.c: Running rep_test in replicated env." 131 eval rep_test $method $masterenv NULL $niter 0 0 0 0 $largs 132 replclear 2 133 134 puts "\tRep$tnum.d: Run db_archive on master." 135 set res [eval exec $util_path/db_archive -d -h $masterdir] 136 set res [eval exec $util_path/db_archive -l -h $masterdir] 137 if { [lsearch -exact $res $last_client_log] == -1 } { 138 set stop 1 139 } 140 } 141 142 # Find out what exists on the master. We need to loop until 143 # the master log changes. This is required so that we can 144 # have a log_archive waiting to happen. 145 # 146 set res [eval exec $util_path/db_archive -l -h $masterdir] 147 set last_master_log [lindex [lsort $res] end] 148 set stop 0 149 puts "\tRep$tnum.e: Move master logs forward again." 150 while { $stop == 0 } { 151 # Run rep_test in the master (don't update client). 152 eval rep_test $method $masterenv NULL $niter 0 0 0 0 $largs 153 replclear 2 154 155 set res [eval exec $util_path/db_archive -l -h $masterdir] 156 set last_log [lindex [lsort $res] end] 157 if { $last_log != $last_master_log } { 158 set stop 1 159 } 160 } 161 162 puts "\tRep$tnum.f: Get list of files for removal." 163 set logs [eval exec $util_path/db_archive -h $masterdir] 164 165 puts "\tRep$tnum.g: Reopen client ($opts)." 166 if { $opts == "clean" } { 167 env_cleanup $clientdir 168 } 169 set clientenv [eval $cl_envcmd $recargs -rep_client] 170 error_check_good client_env [is_valid_env $clientenv] TRUE 171 $clientenv rep_limit 0 0 172 set envlist "{$masterenv 1} {$clientenv 2}" 173 # 174 # Process messages once to get partially through internal init. 175 # 176 proc_msgs_once $envlist NONE err 177 178 if { $opts != "clean" } { 179 puts "\tRep$tnum.g.1: Trigger log request" 180 # 181 # When we don't clean, starting the client doesn't 182 # trigger any events. We need to generate some log 183 # records so that the client requests the missing 184 # logs and that will trigger it. 185 # 186 set entries 10 187 eval rep_test $method $masterenv NULL $entries $niter 0 0 0 $largs 188 # 189 # Process messages three times to get us into internal init 190 # but not enough to get us all the way through it. 191 # 192 proc_msgs_once $envlist NONE err 193 proc_msgs_once $envlist NONE err 194 proc_msgs_once $envlist NONE err 195 } 196 197 # 198 # Now in the middle of internal init, remove the log files 199 # db_archive reported earlier. 200 # 201 foreach l $logs { 202 fileremove -f $masterdir/$l 203 } 204 # 205 # Now finish processing all the messages. 206 # 207 process_msgs $envlist 0 NONE err 208 puts "\tRep$tnum.h: Verify logs and databases" 209 rep_verify $masterdir $masterenv $clientdir $clientenv 1 210 211 error_check_good masterenv_close [$masterenv close] 0 212 error_check_good clientenv_close [$clientenv close] 0 213 replclose $testdir/MSGQUEUEDIR 214} 215