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