1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2001,2008 Oracle. All rights reserved. 4# 5# $Id: rep001.tcl,v 12.19 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST rep001 8# TEST Replication rename and forced-upgrade test. 9# TEST 10# TEST Run rep_test in a replicated master environment. 11# TEST Verify that the database on the client is correct. 12# TEST Next, remove the database, close the master, upgrade the 13# TEST client, reopen the master, and make sure the new master can 14# TEST correctly run rep_test and propagate it in the other direction. 15 16proc rep001 { method { niter 1000 } { tnum "001" } args } { 17 global passwd 18 global has_crypto 19 20 source ./include.tcl 21 if { $is_windows9x_test == 1 } { 22 puts "Skipping replication test on Win9x platform." 23 return 24 } 25 26 if { $checking_valid_methods } { 27 return "ALL" 28 } 29 30 # Rep056 runs rep001 with in-memory named databases. 31 set inmem 0 32 set msg "using regular named databases" 33 if { $tnum == "056" } { 34 set inmem 1 35 set msg "using in-memory named databases" 36 if { [is_queueext $method] == 1 } { 37 puts "Skipping rep$tnum for method $method" 38 return 39 } 40 } 41 42 # Run tests with and without recovery. If we're doing testing 43 # of in-memory logging, skip the combination of recovery 44 # and in-memory logging -- it doesn't make sense. 45 set logsets [create_logsets 2] 46 set saved_args $args 47 48 foreach recopt $test_recopts { 49 foreach l $logsets { 50 set logindex [lsearch -exact $l "in-memory"] 51 if { $recopt == "-recover" && $logindex != -1 } { 52 puts "Skipping test with -recover for in-memory logs." 53 continue 54 } 55 set envargs "" 56 set args $saved_args 57 puts -nonewline "Rep$tnum: Replication sanity test " 58 puts "($method $recopt), $msg." 59 puts "Rep$tnum: Master logs are [lindex $l 0]" 60 puts "Rep$tnum: Client logs are [lindex $l 1]" 61 rep001_sub $method \ 62 $niter $tnum $envargs $l $recopt $inmem $args 63 64 # Skip encrypted tests if not supported. 65 if { $has_crypto == 0 || $inmem } { 66 continue 67 } 68 69 # Run the same tests with security. In-memory 70 # databases don't work with encryption. 71 append envargs " -encryptaes $passwd " 72 append args " -encrypt " 73 puts "Rep$tnum: Replication and security sanity test\ 74 ($method $recopt)." 75 puts "Rep$tnum: Master logs are [lindex $l 0]" 76 puts "Rep$tnum: Client logs are [lindex $l 1]" 77 rep001_sub $method \ 78 $niter $tnum $envargs $l $recopt $inmem $args 79 } 80 } 81} 82 83proc rep001_sub { method niter tnum envargs logset recargs inmem largs } { 84 source ./include.tcl 85 global testdir 86 global encrypt 87 global rep_verbose 88 global verbose_type 89 90 set verbargs "" 91 if { $rep_verbose == 1 } { 92 set verbargs " -verbose {$verbose_type on} " 93 } 94 95 env_cleanup $testdir 96 97 replsetup $testdir/MSGQUEUEDIR 98 99 set masterdir $testdir/MASTERDIR 100 set clientdir $testdir/CLIENTDIR 101 102 file mkdir $masterdir 103 file mkdir $clientdir 104 105 set m_logtype [lindex $logset 0] 106 set c_logtype [lindex $logset 1] 107 108 set verify_subset \ 109 [expr { $m_logtype == "in-memory" || $c_logtype == "in-memory" }] 110 111 # In-memory logs require a large log buffer, and cannot 112 # be used with -txn nosync. Adjust the args for master 113 # and client. 114 set m_logargs [adjust_logargs $m_logtype] 115 set c_logargs [adjust_logargs $c_logtype] 116 set m_txnargs [adjust_txnargs $m_logtype] 117 set c_txnargs [adjust_txnargs $c_logtype] 118 119 # Open a master. 120 repladd 1 121 set env_cmd(M) "berkdb_env_noerr -create \ 122 -log_max 1000000 $envargs $m_logargs $recargs $verbargs \ 123 -home $masterdir -errpfx MASTER $m_txnargs -rep_master \ 124 -rep_transport \[list 1 replsend\]" 125 set masterenv [eval $env_cmd(M)] 126 127 # Open a client 128 repladd 2 129 set env_cmd(C) "berkdb_env_noerr -create \ 130 -log_max 1000000 $envargs $c_logargs $recargs $verbargs \ 131 -home $clientdir -errpfx CLIENT $c_txnargs -rep_client \ 132 -rep_transport \[list 2 replsend\]" 133 set clientenv [eval $env_cmd(C)] 134 135 # Bring the client online by processing the startup messages. 136 set envlist "{$masterenv 1} {$clientenv 2}" 137 process_msgs $envlist 138 139 # Clobber replication's 30-second anti-archive timer, which will have 140 # been started by client sync-up internal init, so that we can do a 141 # db_remove in a moment. 142 # 143 $masterenv test force noarchive_timeout 144 145 # Run rep_test in the master (and update client). 146 puts "\tRep$tnum.a:\ 147 Running rep_test in replicated env ($envargs $recargs)." 148 eval rep_test $method $masterenv NULL $niter 0 0 0 $inmem $largs 149 process_msgs $envlist 150 151 puts "\tRep$tnum.b: Verifying client database contents." 152 if { $inmem } { 153 set dbname { "" "test.db" } 154 } else { 155 set dbname "test.db" 156 } 157 158 rep_verify $masterdir $masterenv $clientdir $clientenv $verify_subset 1 1 $dbname 159 160 # Remove the file (and update client). 161 puts "\tRep$tnum.c: Remove the file on the master and close master." 162 error_check_good remove \ 163 [eval {$masterenv dbremove} -auto_commit $dbname] 0 164 error_check_good masterenv_close [$masterenv close] 0 165 process_msgs $envlist 166 167 puts "\tRep$tnum.d: Upgrade client." 168 set newmasterenv $clientenv 169 error_check_good upgrade_client [$newmasterenv rep_start -master] 0 170 171 # Run rep_test in the new master 172 puts "\tRep$tnum.e: Running rep_test in new master." 173 eval rep_test $method $newmasterenv NULL $niter 0 0 0 $inmem $largs 174 set envlist "{$newmasterenv 2}" 175 process_msgs $envlist 176 177 puts "\tRep$tnum.f: Reopen old master as client and catch up." 178 # Throttle master so it can't send everything at once 179 $newmasterenv rep_limit 0 [expr 64 * 1024] 180 set newclientenv [eval {berkdb_env_noerr -create -recover} \ 181 $envargs -txn nosync -errpfx NEWCLIENT \ 182 {-home $masterdir -rep_client -rep_transport [list 1 replsend]}] 183 set envlist "{$newclientenv 1} {$newmasterenv 2}" 184 process_msgs $envlist 185 186 # If we're running with a low number of iterations, we might 187 # not have had to throttle the data transmission; skip the check. 188 if { $niter > 200 } { 189 set nthrottles \ 190 [stat_field $newmasterenv rep_stat "Transmission limited"] 191 error_check_bad nthrottles $nthrottles -1 192 error_check_bad nthrottles $nthrottles 0 193 } 194 195 # Run a modified rep_test in the new master (and update client). 196 puts "\tRep$tnum.g: Running rep_test in new master." 197 eval rep_test $method \ 198 $newmasterenv NULL $niter $niter $niter 0 $inmem $largs 199 process_msgs $envlist 200 201 # Verify the database in the client dir. 202 puts "\tRep$tnum.h: Verifying new client database contents." 203 204 rep_verify \ 205 $masterdir $newmasterenv $clientdir $newclientenv $verify_subset 1 1 $dbname 206 207 error_check_good newmasterenv_close [$newmasterenv close] 0 208 error_check_good newclientenv_close [$newclientenv close] 0 209 210 if { [lsearch $envargs "-encrypta*"] !=-1 } { 211 set encrypt 1 212 } 213 error_check_good verify \ 214 [verify_dir $clientdir "\tRep$tnum.k: " 0 0 1] 0 215 replclose $testdir/MSGQUEUEDIR 216} 217