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