1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2007-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# TEST repmgr011 8# TEST repmgr two site strict majority test. 9# TEST 10# TEST Start an appointed master and one client with 2 site strict 11# TEST majority set. Shut down the master site, wait and verify that 12# TEST the client site was not elected master. Start up master site 13# TEST and verify that transactions are processed as expected. 14# TEST 15# TEST Run for btree only because access method shouldn't matter. 16# TEST 17proc repmgr011 { method { niter 100 } { tnum "011" } args } { 18 19 source ./include.tcl 20 21 if { $is_freebsd_test == 1 } { 22 puts "Skipping replication manager test on FreeBSD platform." 23 return 24 } 25 26 if { $is_windows9x_test == 1 } { 27 puts "Skipping replication test on Win9x platform." 28 return 29 } 30 31 # Skip for all methods except btree. 32 if { $checking_valid_methods } { 33 return btree 34 } 35 if { [is_btree $method] == 0 } { 36 puts "Repmgr$tnum: skipping for non-btree method $method." 37 return 38 } 39 40 set args [convert_args $method $args] 41 42 puts "Repmgr$tnum ($method): repmgr two site strict majority test." 43 repmgr011_sub $method $niter $tnum $args 44} 45 46proc repmgr011_sub { method niter tnum largs } { 47 global testdir 48 global rep_verbose 49 global verbose_type 50 set nsites 2 51 52 set verbargs "" 53 if { $rep_verbose == 1 } { 54 set verbargs " -verbose {$verbose_type on} " 55 } 56 57 env_cleanup $testdir 58 set ports [available_ports $nsites] 59 60 set clientdir $testdir/CLIENTDIR 61 set clientdir2 $testdir/CLIENTDIR2 62 63 file mkdir $clientdir 64 file mkdir $clientdir2 65 66 # Use different connection retry timeout values to handle any 67 # collisions from starting sites at the same time by retrying 68 # at different times. 69 70 # Open first client as master and set 2site_strict. 71 puts "\tRepmgr$tnum.a: Start first client as master." 72 set cl_envcmd "berkdb_env_noerr -create $verbargs \ 73 -errpfx CLIENT -home $clientdir -txn -rep -thread" 74 set clientenv [eval $cl_envcmd] 75 $clientenv repmgr -ack all -nsites $nsites \ 76 -timeout {conn_retry 20000000} \ 77 -local [list localhost [lindex $ports 0]] \ 78 -start master 79 error_check_good c1strict [$clientenv rep_config {mgr2sitestrict on}] 0 80 81 # Open second client and set 2site_strict. 82 puts "\tRepmgr$tnum.b: Start second client." 83 set cl2_envcmd "berkdb_env_noerr -create $verbargs \ 84 -errpfx CLIENT2 -home $clientdir2 -txn -rep -thread" 85 set clientenv2 [eval $cl2_envcmd] 86 $clientenv2 repmgr -ack all -nsites $nsites \ 87 -timeout {conn_retry 10000000} \ 88 -local [list localhost [lindex $ports 1]] \ 89 -remote [list localhost [lindex $ports 0]] \ 90 -start client 91 await_startup_done $clientenv2 92 error_check_good c2strict [$clientenv2 rep_config \ 93 {mgr2sitestrict on}] 0 94 95 # 96 # Use of -ack all guarantees replication complete before repmgr send 97 # function returns and rep_test finishes. 98 # 99 puts "\tRepmgr$tnum.c: Run first set of transactions at master." 100 eval rep_test $method $clientenv NULL $niter 0 0 0 $largs 101 102 puts "\tRepmgr$tnum.d: Verifying client database contents." 103 rep_verify $clientdir $clientenv $clientdir2 $clientenv2 1 1 1 104 105 puts "\tRepmgr$tnum.e: Shut down first client (current master)." 106 error_check_good client_close [$clientenv close] 0 107 108 puts "\tRepmgr$tnum.f: Wait, then verify no master." 109 tclsleep 20 110 error_check_bad c2_master [stat_field $clientenv2 rep_stat "Master"] 1 111 112 puts "\tRepmgr$tnum.g: Restart first client as master" 113 set clientenv [eval $cl_envcmd] 114 $clientenv repmgr -ack all -nsites $nsites \ 115 -timeout {conn_retry 20000000} \ 116 -local [list localhost [lindex $ports 0]] \ 117 -remote [list localhost [lindex $ports 1]] \ 118 -start master 119 await_expected_master $clientenv 120 121 puts "\tRepmgr$tnum.h: Run second set of transactions at master." 122 eval rep_test $method $clientenv NULL $niter $niter 0 0 $largs 123 124 puts "\tRepmgr$tnum.i: Verifying client database contents." 125 rep_verify $clientdir $clientenv $clientdir2 $clientenv2 1 1 1 126 127 error_check_good client2_close [$clientenv2 close] 0 128 error_check_good client_close [$clientenv close] 0 129} 130