1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2007-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# TEST repmgr017 8# TEST repmgr in-memory cache overflow test. 9# TEST 10# TEST Start an appointed master site and one client, putting databases, 11# TEST environment regions, logs and replication files in-memory. Set 12# TEST very small cachesize and run enough transactions to overflow cache. 13# TEST Shut down and restart master and client, giving master a larger cache. 14# TEST Run and verify a small number of transactions. 15# TEST 16# TEST Run for btree only because access method shouldn't matter. 17# TEST 18proc repmgr017 { method { niter 1000 } { tnum "017" } args } { 19 20 source ./include.tcl 21 22 if { $is_freebsd_test == 1 } { 23 puts "Skipping replication manager test on FreeBSD platform." 24 return 25 } 26 27 if { $is_windows9x_test == 1 } { 28 puts "Skipping replication test on Win9x platform." 29 return 30 } 31 32 # Skip for all methods except btree. 33 if { $checking_valid_methods } { 34 return btree 35 } 36 if { [is_btree $method] == 0 } { 37 puts "Repmgr$tnum: skipping for non-btree method $method." 38 return 39 } 40 41 set args [convert_args $method $args] 42 43 puts \ 44 "Repmgr$tnum ($method): repmgr in-memory cache overflow test." 45 repmgr017_sub $method $niter $tnum $args 46} 47 48proc repmgr017_sub { method niter tnum largs } { 49 global rep_verbose 50 global verbose_type 51 global databases_in_memory 52 53 # Force databases in-memory for this test but preserve original 54 # value to restore later so that other tests aren't affected. 55 set restore_dbinmem $databases_in_memory 56 set databases_in_memory 1 57 58 # No need for test directories because test is entirely in-memory. 59 60 set nsites 2 61 set ports [available_ports $nsites] 62 set omethod [convert_method $method] 63 64 set verbargs "" 65 if { $rep_verbose == 1 } { 66 set verbargs " -verbose {$verbose_type on} " 67 } 68 69 # In-memory logs cannot be used with -txn nosync. 70 set logargs [adjust_logargs "in-memory"] 71 set txnargs [adjust_txnargs "in-memory"] 72 73 # Use different connection retry timeout values to handle any 74 # collisions from starting sites at the same time by retrying 75 # at different times. 76 77 # Open a master with a very small cache. 78 puts "\tRepmgr$tnum.a: Start a master with a very small cache." 79 set cacheargs "-cachesize {0 32768 1}" 80 set ma_envcmd "berkdb_env_noerr -create $logargs $txnargs $verbargs \ 81 -errpfx MASTER -rep -thread -rep_inmem_files -private $cacheargs" 82 set masterenv [eval $ma_envcmd] 83 $masterenv repmgr -ack all -nsites $nsites \ 84 -timeout {conn_retry 20000000} \ 85 -local [list localhost [lindex $ports 0]] \ 86 -start master 87 88 # Open a client 89 puts "\tRepmgr$tnum.b: Start a client." 90 set cl_envcmd "berkdb_env_noerr -create $logargs $txnargs $verbargs \ 91 -errpfx CLIENT -rep -thread -rep_inmem_files -private" 92 set clientenv [eval $cl_envcmd] 93 $clientenv repmgr -ack all -nsites $nsites \ 94 -timeout {conn_retry 10000000} \ 95 -local [list localhost [lindex $ports 1]] \ 96 -remote [list localhost [lindex $ports 0]] \ 97 -start client 98 await_startup_done $clientenv 99 100 puts "\tRepmgr$tnum.c: Run master transactions and verify full cache." 101 set dbname { "" "test.db" } 102 set mdb [eval "berkdb_open_noerr -create $omethod -auto_commit \ 103 -env $masterenv $largs $dbname"] 104 set stat [catch { 105 rep_test $method $masterenv $mdb $niter 0 0 0 $largs } ret ] 106 error_check_good broke $stat 1 107 error_check_good nomem \ 108 [is_substr $ret "not enough memory"] 1 109 110 puts "\tRepmgr$tnum.d: Close master and client." 111 error_check_good mdb_close [$mdb close] 0 112 error_check_good client_close [$clientenv close] 0 113 # Master close should return invalid argument. 114 catch { $masterenv close } ret2 115 error_check_good needrec [is_substr $ret2 "invalid argument"] 1 116 117 puts "\tRepmgr$tnum.e: Restart master (with larger cache) and client." 118 # Recovery is a no-op with everything in-memory, but specify it 119 # anyway after closing the master environment with an error. 120 set cacheargs "" 121 set masterenv [eval $ma_envcmd -recover] 122 $masterenv repmgr -ack all -nsites $nsites \ 123 -timeout {conn_retry 20000000} \ 124 -local [list localhost [lindex $ports 0]] \ 125 -start master 126 127 # Open -recover to clear env region, including startup_done value. 128 set clientenv [eval $cl_envcmd -recover] 129 $clientenv repmgr -ack all -nsites $nsites \ 130 -timeout {conn_retry 10000000} \ 131 -local [list localhost [lindex $ports 1]] \ 132 -remote [list localhost [lindex $ports 0]] \ 133 -start client 134 await_startup_done $clientenv 135 136 puts "\tRepmgr$tnum.f: Perform small number of transactions on master." 137 set numtxns 10 138 set mdb [eval "berkdb_open_noerr -create $omethod -auto_commit \ 139 -env $masterenv $largs $dbname"] 140 set t [$masterenv txn] 141 for { set i 1 } { $i <= $numtxns } { incr i } { 142 error_check_good db_put \ 143 [eval $mdb put -txn $t $i [chop_data $method data$i]] 0 144 } 145 error_check_good txn_commit [$t commit] 0 146 147 puts "\tRepmgr$tnum.g: Verify transactions on client." 148 set cdb [eval "berkdb_open_noerr -create -mode 0644 $omethod \ 149 -env $clientenv $largs $dbname"] 150 error_check_good reptest_db [is_valid_db $cdb] TRUE 151 for { set i 1 } { $i <= $numtxns } { incr i } { 152 set ret [lindex [$cdb get $i] 0] 153 error_check_good cdb_get $ret [list $i \ 154 [pad_data $method data$i]] 155 } 156 157 # If the test had erroneously created replication files, they would 158 # be in the current working directory. Verify that this didn't happen. 159 puts "\tRepmgr$tnum.h: Verify no replication files on disk." 160 no_rep_files_on_disk "." 161 162 # Restore original databases_in_memory value. 163 set databases_in_memory $restore_dbinmem 164 165 error_check_good cdb_close [$cdb close] 0 166 error_check_good mdb_close [$mdb close] 0 167 error_check_good client_close [$clientenv close] 0 168 error_check_good master_close [$masterenv close] 0 169} 170