1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2004,2008 Oracle. All rights reserved. 4# 5# $Id: rep033.tcl,v 12.19 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST rep033 8# TEST Test of internal initialization with rename and remove of dbs. 9# TEST 10# TEST One master, one client. 11# TEST Generate several databases. Replicate to client. 12# TEST Do some renames and removes, both before and after 13# TEST closing the client. 14# 15proc rep033 { method { niter 200 } { tnum "033" } args } { 16 17 source ./include.tcl 18 if { $is_windows9x_test == 1 } { 19 puts "Skipping replication test on Win 9x platform." 20 return 21 } 22 23 # Valid for all access methods. 24 if { $checking_valid_methods } { 25 return "ALL" 26 } 27 28 # This test depends on manipulating logs, so can not be run with 29 # in-memory logging. 30 global mixed_mode_logging 31 if { $mixed_mode_logging > 0 } { 32 puts "Rep$tnum: Skipping for mixed-mode logging." 33 return 34 } 35 36 set args [convert_args $method $args] 37 set omethod [convert_method $method] 38 39 # Run the body of the test with and without recovery, 40 # and with and without cleaning. 41 set envargs "" 42 set cleanopts { noclean clean } 43 set when { before after } 44 foreach r $test_recopts { 45 foreach c $cleanopts { 46 foreach w $when { 47 puts "Rep$tnum ($method $envargs $c $r $w $args):\ 48 Test of internal initialization." 49 rep033_sub $omethod $niter $tnum $envargs \ 50 $r $c $w $args 51 } 52 } 53 } 54} 55 56proc rep033_sub { method niter tnum envargs recargs clean when largs } { 57 global testdir 58 global util_path 59 global rep_verbose 60 global verbose_type 61 62 set verbargs "" 63 if { $rep_verbose == 1 } { 64 set verbargs " -verbose {$verbose_type on} " 65 } 66 67 env_cleanup $testdir 68 69 replsetup $testdir/MSGQUEUEDIR 70 71 set masterdir $testdir/MASTERDIR 72 set clientdir $testdir/CLIENTDIR 73 74 file mkdir $masterdir 75 file mkdir $clientdir 76 77 # Log size is small so we quickly create more than one. 78 # The documentation says that the log file must be at least 79 # four times the size of the in-memory log buffer. 80 set pagesize 4096 81 append largs " -pagesize $pagesize " 82 set log_buf [expr $pagesize * 2] 83 set log_max [expr $log_buf * 4] 84 85 # Open a master. 86 repladd 1 87 set ma_envcmd "berkdb_env_noerr -create -txn nosync \ 88 -log_buffer $log_buf -log_max $log_max $envargs \ 89 -errpfx MASTER $verbargs \ 90 -home $masterdir -rep_transport \[list 1 replsend\]" 91 set masterenv [eval $ma_envcmd $recargs -rep_master] 92 93 # Open a client 94 repladd 2 95 set cl_envcmd "berkdb_env_noerr -create -txn nosync \ 96 -log_buffer $log_buf -log_max $log_max $envargs \ 97 -errpfx CLIENT $verbargs \ 98 -home $clientdir -rep_transport \[list 2 replsend\]" 99 set clientenv [eval $cl_envcmd $recargs -rep_client] 100 101 # Bring the clients online by processing the startup messages. 102 set envlist "{$masterenv 1} {$clientenv 2}" 103 process_msgs $envlist 104 105 # Clobber replication's 30-second anti-archive timer, which will have 106 # been started by client sync-up internal init, so that we can do a 107 # log_archive in a moment. 108 # 109 $masterenv test force noarchive_timeout 110 111 puts "\tRep$tnum.a: Create several databases on master." 112 set oflags " -env $masterenv $method -create -auto_commit " 113 set dbw [eval {berkdb_open_noerr} $oflags $largs w.db] 114 set dbx [eval {berkdb_open_noerr} $oflags $largs x.db] 115 set dby [eval {berkdb_open_noerr} $oflags $largs y.db] 116 set dbz [eval {berkdb_open_noerr} $oflags $largs z.db] 117 error_check_good dbw_close [$dbw close] 0 118 error_check_good dbx_close [$dbx close] 0 119 error_check_good dby_close [$dby close] 0 120 error_check_good dbz_close [$dbz close] 0 121 122 # Update client, then close. 123 process_msgs $envlist 124 125 puts "\tRep$tnum.b: Close client." 126 error_check_good client_close [$clientenv close] 0 127 128 # If we're doing the rename/remove operations before adding 129 # databases A and B, manipulate only the existing files. 130 if { $when == "before" } { 131 rep033_rename_remove $masterenv 132 } 133 134 # Run rep_test in the master (don't update client). 135 # 136 # We'd like to control the names of these dbs, so give 137 # rep_test an existing handle. 138 # 139 puts "\tRep$tnum.c: Create new databases. Populate with rep_test." 140 set dba [eval {berkdb_open_noerr} $oflags $largs a.db] 141 set dbb [eval {berkdb_open_noerr} $oflags $largs b.db] 142 eval rep_test $method $masterenv $dba $niter 0 0 0 0 $largs 143 eval rep_test $method $masterenv $dbb $niter 0 0 0 0 $largs 144 error_check_good dba_close [$dba close] 0 145 error_check_good dbb_close [$dbb close] 0 146 147 # Throw away messages for client. 148 replclear 2 149 150 # If we're doing the rename/remove afterwards, manipulate 151 # all the files including A and B. 152 if { $when == "after" } { 153 rep033_rename_remove $masterenv 154 } 155 error_check_good rename_b [$masterenv dbrename b.db x.db] 0 156 error_check_good remove_a [$masterenv dbremove a.db] 0 157 158 puts "\tRep$tnum.d: Run db_archive on master." 159 set res [eval exec $util_path/db_archive -l -h $masterdir] 160 error_check_bad log.1.present [lsearch -exact $res log.0000000001] -1 161 set res [eval exec $util_path/db_archive -d -h $masterdir] 162 set res [eval exec $util_path/db_archive -l -h $masterdir] 163 error_check_good log.1.gone [lsearch -exact $res log.0000000001] -1 164 165 puts "\tRep$tnum.e: Reopen client ($clean)." 166 if { $clean == "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 set envlist "{$masterenv 1} {$clientenv 2}" 172 process_msgs $envlist 0 NONE err 173 if { $clean == "noclean" } { 174 puts "\tRep$tnum.e.1: Trigger log request" 175 # 176 # When we don't clean, starting the client doesn't 177 # trigger any events. We need to generate some log 178 # records so that the client requests the missing 179 # logs and that will trigger it. 180 # 181 set entries 10 182 eval rep_test $method $masterenv NULL $entries $niter 0 0 0 $largs 183 process_msgs $envlist 0 NONE err 184 } 185 186 puts "\tRep$tnum.f: Verify logs and databases" 187 # 188 # By sending in a NULL for dbname, we only compare logs. 189 # 190 rep_verify $masterdir $masterenv $clientdir $clientenv 1 1 1 NULL 191 # 192 # ... now the databases, manually. X, Y, and C should exist. 193 # 194 set dbnames "x.db w.db c.db" 195 foreach db $dbnames { 196 set db1 [eval \ 197 {berkdb_open_noerr -env $masterenv} $largs {-rdonly $db}] 198 set db2 [eval \ 199 {berkdb_open_noerr -env $clientenv} $largs {-rdonly $db}] 200 201 error_check_good compare:$db [db_compare \ 202 $db1 $db2 $masterdir/$db $clientdir/$db] 0 203 error_check_good db1_close [$db1 close] 0 204 error_check_good db2_close [$db2 close] 0 205 } 206 207 # A, B, and Z should be gone on client. 208 error_check_good dba_gone [file exists $clientdir/a.db] 0 209 error_check_good dbb_gone [file exists $clientdir/b.db] 0 210 # 211 # Currently we cannot remove z.db on the client because 212 # we don't own the file namespace. So, we cannot do 213 # the check below. If that changes, we want the test below. 214 # error_check_good dbz_gone [file exists $clientdir/z.db] 0 215 216 # Clean up. 217 error_check_good masterenv_close [$masterenv close] 0 218 error_check_good clientenv_close [$clientenv close] 0 219 replclose $testdir/MSGQUEUEDIR 220} 221 222proc rep033_rename_remove { env } { 223 224 # Here we manipulate databases W, X, Y, and Z. 225 # Remove W. 226 error_check_good remove_w [$env dbremove w.db] 0 227 228 # Rename X to W, Y to C (an entirely new name). 229 error_check_good rename_x [$env dbrename x.db w.db] 0 230 error_check_good rename_y [$env dbrename y.db c.db] 0 231 232 # Remove Z. 233 error_check_good remove_z [$env dbremove z.db] 0 234} 235