1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2003,2008 Oracle. All rights reserved. 4# 5# $Id: rep006.tcl,v 12.19 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST rep006 8# TEST Replication and non-rep env handles. 9# TEST 10# TEST Run a modified version of test001 in a replicated master 11# TEST environment; verify that the database on the client is correct. 12# TEST Next, create a non-rep env handle to the master env. 13# TEST Attempt to open the database r/w to force error. 14 15proc rep006 { method { niter 1000 } { tnum "006" } 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 set logsets [create_logsets 2] 23 24 # All access methods are allowed. 25 if { $checking_valid_methods } { 26 return "ALL" 27 } 28 29 # Run the body of the test with and without recovery. 30 foreach r $test_recopts { 31 foreach l $logsets { 32 set logindex [lsearch -exact $l "in-memory"] 33 if { $r == "-recover" && $logindex != -1 } { 34 puts "Rep$tnum: Skipping for in-memory logs\ 35 with -recover." 36 continue 37 } 38 puts "Rep$tnum ($method $r):\ 39 Replication and non-rep env handles" 40 puts "Rep$tnum: Master logs are [lindex $l 0]" 41 puts "Rep$tnum: Client logs are [lindex $l 1]" 42 rep006_sub $method $niter $tnum $l $r $args 43 } 44 } 45} 46 47proc rep006_sub { method niter tnum logset recargs largs } { 48 source ./include.tcl 49 global testdir 50 global is_hp_test 51 global rep_verbose 52 global verbose_type 53 54 set verbargs "" 55 if { $rep_verbose == 1 } { 56 set verbargs " -verbose {$verbose_type on} " 57 } 58 59 env_cleanup $testdir 60 61 replsetup $testdir/MSGQUEUEDIR 62 63 set masterdir $testdir/MASTERDIR 64 set clientdir $testdir/CLIENTDIR 65 66 file mkdir $masterdir 67 file mkdir $clientdir 68 69 set m_logtype [lindex $logset 0] 70 set c_logtype [lindex $logset 1] 71 72 # In-memory logs require a large log buffer, and cannot 73 # be used with -txn nosync. 74 set m_logargs [adjust_logargs $m_logtype] 75 set c_logargs [adjust_logargs $c_logtype] 76 set m_txnargs [adjust_txnargs $m_logtype] 77 set c_txnargs [adjust_txnargs $c_logtype] 78 79 if { [is_record_based $method] == 1 } { 80 set checkfunc test001_recno.check 81 } else { 82 set checkfunc test001.check 83 } 84 85 # Open a master. 86 repladd 1 87 set max_locks 2500 88 set env_cmd(M) "berkdb_env_noerr -create -log_max 1000000 \ 89 -lock_max_objects $max_locks -lock_max_locks $max_locks \ 90 -home $masterdir -errpfx MASTER $verbargs \ 91 $m_txnargs $m_logargs -rep_master -rep_transport \ 92 \[list 1 replsend\]" 93 set masterenv [eval $env_cmd(M) $recargs] 94 95 # Open a client 96 repladd 2 97 set env_cmd(C) "berkdb_env_noerr -create $c_txnargs $c_logargs \ 98 -lock_max_objects $max_locks -lock_max_locks $max_locks \ 99 -home $clientdir -errpfx CLIENT $verbargs \ 100 -rep_client -rep_transport \[list 2 replsend\]" 101 set clientenv [eval $env_cmd(C) $recargs] 102 103 # Bring the client online by processing the startup messages. 104 set envlist "{$masterenv 1} {$clientenv 2}" 105 process_msgs $envlist 106 107 # Run a modified test001 in the master (and update client). 108 puts "\tRep$tnum.a: Running test001 in replicated env." 109 eval rep_test $method $masterenv NULL $niter 0 0 0 0 $largs 110 process_msgs $envlist 111 112 # Verify the database in the client dir. 113 puts "\tRep$tnum.b: Verifying client database contents." 114 set testdir [get_home $masterenv] 115 set t1 $testdir/t1 116 set t2 $testdir/t2 117 set t3 $testdir/t3 118 open_and_dump_file test.db $clientenv $t1 \ 119 $checkfunc dump_file_direction "-first" "-next" 120 121 # Determine whether this build is configured with --enable-debug_rop 122 # or --enable-debug_wop; we'll need to skip portions of the test if so. 123 # Also check for *not* configuring with diagnostic. That similarly 124 # forces a different code path and we need to skip portions. 125 set conf [berkdb getconfig] 126 set skip_for_config 0 127 if { [is_substr $conf "debug_rop"] == 1 \ 128 || [is_substr $conf "debug_wop"] == 1 \ 129 || [is_substr $conf "diagnostic"] == 0 } { 130 set skip_for_config 1 131 } 132 133 # Skip if configured with --enable-debug_rop or --enable-debug_wop 134 # or without --enable-diagnostic, 135 # because the checkpoint won't fail in those cases. 136 if { $skip_for_config == 1 } { 137 puts "\tRep$tnum.c: Skipping based on configuration." 138 } else { 139 puts "\tRep$tnum.c: Verifying non-master db_checkpoint." 140 set stat \ 141 [catch {exec $util_path/db_checkpoint -h $masterdir -1} ret] 142 error_check_good open_err $stat 1 143 error_check_good \ 144 open_err1 [is_substr $ret "attempting to modify"] 1 145 } 146 147 # We have to skip this bit for HP-UX because we can't open an env 148 # twice, and for debug_rop/debug_wop because the open won't fail. 149 if { $is_hp_test == 1 } { 150 puts "\tRep$tnum.d: Skipping for HP-UX." 151 } elseif { $skip_for_config == 1 } { 152 puts "\tRep$tnum.d: Skipping based on configuration." 153 } else { 154 puts "\tRep$tnum.d: Verifying non-master access." 155 156 set rdenv [eval {berkdb_env_noerr} \ 157 -home $masterdir $verbargs] 158 error_check_good rdenv [is_valid_env $rdenv] TRUE 159 # 160 # Open the db read/write which will cause it to try to 161 # write out a log record, which should fail. 162 # 163 set stat \ 164 [catch {berkdb_open_noerr -env $rdenv test.db} ret] 165 error_check_good open_err $stat 1 166 error_check_good \ 167 open_err1 [is_substr $ret "attempting to modify"] 1 168 error_check_good rdenv_close [$rdenv close] 0 169 } 170 171 process_msgs $envlist 172 173 error_check_good masterenv_close [$masterenv close] 0 174 error_check_good clientenv_close [$clientenv close] 0 175 176 error_check_good verify \ 177 [verify_dir $clientdir "\tRep$tnum.e: " 0 0 1] 0 178 replclose $testdir/MSGQUEUEDIR 179} 180