1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2003,2008 Oracle. All rights reserved. 4# 5# $Id: rep011.tcl,v 12.15 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST rep011 8# TEST Replication: test open handle across an upgrade. 9# TEST 10# TEST Open and close test database in master environment. 11# TEST Update the client. Check client, and leave the handle 12# TEST to the client open as we close the masterenv and upgrade 13# TEST the client to master. Reopen the old master as client 14# TEST and catch up. Test that we can still do a put to the 15# TEST handle we created on the master while it was still a 16# TEST client, and then make sure that the change can be 17# TEST propagated back to the new client. 18 19proc rep011 { method { tnum "011" } args } { 20 global has_crypto 21 global passwd 22 23 source ./include.tcl 24 if { $is_windows9x_test == 1 } { 25 puts "Skipping replication test on Win 9x platform." 26 return 27 } 28 29 # Run for all access methods. 30 if { $checking_valid_methods } { 31 return "ALL" 32 } 33 34 set logsets [create_logsets 2] 35 foreach r $test_recopts { 36 foreach l $logsets { 37 set logindex [lsearch -exact $l "in-memory"] 38 if { $r == "-recover" && $logindex != -1 } { 39 puts "Rep$tnum: Skipping\ 40 for in-memory logs with -recover." 41 continue 42 } 43 set envargs "" 44 puts "Rep$tnum.a ($r $envargs):\ 45 Test upgrade of open handles ($method)." 46 puts "Rep$tnum: Master logs are [lindex $l 0]" 47 puts "Rep$tnum: Client logs are [lindex $l 1]" 48 rep011_sub $method $tnum $envargs $l $r $args 49 50 if { $has_crypto == 0 } { 51 continue 52 } 53 append envargs " -encryptaes $passwd " 54 append args " -encrypt " 55 56 puts "Rep$tnum.b ($r $envargs):\ 57 Open handle upgrade test with encryption ($method)." 58 puts "Rep$tnum: Master logs are [lindex $l 0]" 59 puts "Rep$tnum: Client logs are [lindex $l 1]" 60 rep011_sub $method $tnum $envargs $l $r $args 61 } 62 } 63} 64 65proc rep011_sub { method tnum envargs logset recargs largs } { 66 source ./include.tcl 67 global testdir 68 global encrypt 69 global rep_verbose 70 global verbose_type 71 72 set verbargs "" 73 if { $rep_verbose == 1 } { 74 set verbargs " -verbose {$verbose_type on} " 75 } 76 77 env_cleanup $testdir 78 79 replsetup $testdir/MSGQUEUEDIR 80 81 set masterdir $testdir/MASTERDIR 82 set clientdir $testdir/CLIENTDIR 83 84 file mkdir $masterdir 85 file mkdir $clientdir 86 87 set m_logtype [lindex $logset 0] 88 set c_logtype [lindex $logset 1] 89 90 # In-memory logs require a large log buffer, and cannot 91 # be used with -txn nosync. 92 set m_logargs [adjust_logargs $m_logtype] 93 set c_logargs [adjust_logargs $c_logtype] 94 set m_txnargs [adjust_txnargs $m_logtype] 95 set c_txnargs [adjust_txnargs $c_logtype] 96 97 # Open a master. 98 repladd 1 99 set env_cmd(M) "berkdb_env_noerr -create -log_max 1000000 \ 100 $m_logargs $envargs $verbargs -home $masterdir \ 101 $m_txnargs -errpfx MASTER -rep_master -rep_transport \ 102 \[list 1 replsend\]" 103 set masterenv [eval $env_cmd(M) $recargs] 104 105 # Open a client 106 repladd 2 107 set env_cmd(C) "berkdb_env_noerr -create \ 108 $c_logargs $envargs $verbargs -home $clientdir \ 109 $c_txnargs -errpfx CLIENT -rep_client -rep_transport \ 110 \[list 2 replsend\]" 111 set clientenv [eval $env_cmd(C) $recargs] 112 113 # Bring the client online by processing the startup messages. 114 set envlist "{$masterenv 1} {$clientenv 2}" 115 process_msgs $envlist 116 117 # Open a test database on the master so we can test having 118 # handles open across an upgrade. 119 puts "\tRep$tnum.a:\ 120 Opening test database for post-upgrade client logging test." 121 set master_upg_db [berkdb_open_noerr \ 122 -create -auto_commit -btree -env $masterenv rep$tnum-upg.db] 123 set puttxn [$masterenv txn] 124 error_check_good master_upg_db_put \ 125 [$master_upg_db put -txn $puttxn hello world] 0 126 error_check_good puttxn_commit [$puttxn commit] 0 127 error_check_good master_upg_db_close [$master_upg_db close] 0 128 129 # Update the client. 130 process_msgs $envlist 131 132 # Open the cross-upgrade database on the client and check its contents. 133 set client_upg_db [berkdb_open_noerr \ 134 -create -auto_commit -btree -env $clientenv rep$tnum-upg.db] 135 error_check_good client_upg_db_get [$client_upg_db get hello] \ 136 [list [list hello world]] 137 # !!! We use this handle later. Don't close it here. 138 139 # Close master. 140 puts "\tRep$tnum.b: Close master." 141 error_check_good masterenv_close [$masterenv close] 0 142 143 puts "\tRep$tnum.c: Upgrade client." 144 set newmasterenv $clientenv 145 error_check_good upgrade_client [$newmasterenv rep_start -master] 0 146 147 puts "\tRep$tnum.d: Reopen old master as client and catch up." 148 set newclientenv [eval {berkdb_env_noerr -create -recover} $envargs \ 149 -txn nosync -errpfx NEWCLIENT $verbargs \ 150 {-home $masterdir -rep_client -rep_transport [list 1 replsend]}] 151 set envlist "{$newclientenv 1} {$newmasterenv 2}" 152 process_msgs $envlist 153 154 # Test put to the database handle we opened back when the new master 155 # was a client. 156 puts "\tRep$tnum.e: Test put to handle opened before upgrade." 157 set puttxn [$newmasterenv txn] 158 error_check_good client_upg_db_put \ 159 [$client_upg_db put -txn $puttxn hello there] 0 160 error_check_good puttxn_commit [$puttxn commit] 0 161 process_msgs $envlist 162 163 # Close the new master's handle for the upgrade-test database; we 164 # don't need it. Then check to make sure the client did in fact 165 # update the database. 166 puts "\tRep$tnum.f: Test that client did update the database." 167 error_check_good client_upg_db_close [$client_upg_db close] 0 168 set newclient_upg_db \ 169 [berkdb_open_noerr -env $newclientenv rep$tnum-upg.db] 170 error_check_good newclient_upg_db_get [$newclient_upg_db get hello] \ 171 [list [list hello there]] 172 error_check_good newclient_upg_db_close [$newclient_upg_db close] 0 173 174 error_check_good newmasterenv_close [$newmasterenv close] 0 175 error_check_good newclientenv_close [$newclientenv close] 0 176 177 if { [lsearch $envargs "-encrypta*"] !=-1 } { 178 set encrypt 1 179 } 180 error_check_good verify \ 181 [verify_dir $clientdir "\tRep$tnum.g: " 0 0 1] 0 182 replclose $testdir/MSGQUEUEDIR 183} 184