1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2007-2009 Oracle.  All rights reserved.
4#
5# $Id$
6#
7# TEST	repmgr018
8# TEST	Check repmgr stats.
9# TEST
10# TEST	Start an appointed master and one client. Shut down the client,
11# TEST	run some transactions at the master and verify that there are
12# TEST	acknowledgement failures and one dropped connection. Shut down
13# TEST	and restart client again and verify that there are two dropped
14# TEST	connections.
15# TEST
16# TEST	Run for btree only because access method shouldn't matter.
17# TEST
18proc repmgr018 { method { niter 20 } { tnum "018" } 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 "Repmgr$tnum ($method): Test of repmgr stats."
44	repmgr018_sub $method $niter $tnum $args
45}
46
47proc repmgr018_sub { method niter tnum largs } {
48	global testdir
49	global rep_verbose
50	global verbose_type
51	set nsites 2
52
53	set verbargs ""
54	if { $rep_verbose == 1 } {
55		set verbargs " -verbose {$verbose_type on} "
56	}
57
58	env_cleanup $testdir
59	set ports [available_ports $nsites]
60
61	set masterdir $testdir/MASTERDIR
62	set clientdir $testdir/CLIENTDIR
63
64	file mkdir $masterdir
65	file mkdir $clientdir
66
67	# Use different connection retry timeout values to handle any
68	# collisions from starting sites at the same time by retrying
69	# at different times.
70
71	# Open a master.
72	puts "\tRepmgr$tnum.a: Start a master."
73	set ma_envcmd "berkdb_env_noerr -create $verbargs -errpfx MASTER \
74	    -home $masterdir -txn -rep -thread"
75	set masterenv [eval $ma_envcmd]
76	$masterenv repmgr -ack all -nsites $nsites \
77	    -timeout {conn_retry 20000000} \
78	    -local [list localhost [lindex $ports 0]] \
79	    -start master
80
81	# Open a client
82	puts "\tRepmgr$tnum.b: Start a client."
83	set cl_envcmd "berkdb_env_noerr -create $verbargs -errpfx CLIENT \
84	    -home $clientdir -txn -rep -thread"
85	set clientenv [eval $cl_envcmd]
86	$clientenv 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 $clientenv
92
93	puts "\tRepmgr$tnum.c: Run some transactions at master."
94	eval rep_test $method $masterenv NULL $niter 0 0 0 $largs
95
96	error_check_good perm_no_failed_stat \
97	    [stat_field $masterenv repmgr_stat "Acknowledgement failures"] 0
98
99	error_check_good no_connections_dropped \
100	    [stat_field $masterenv repmgr_stat "Connections dropped"] 0
101
102	$clientenv close
103
104	# Just do a few transactions (i.e., 3 of them), because each one is
105	# expected to time out, and if we did many the test would take a long
106	# time (with no benefit).
107	#
108	puts "\tRepmgr$tnum.d: Run transactions with no client."
109	eval rep_test $method $masterenv NULL 3 $niter $niter 0 $largs
110
111	error_check_bad perm_failed_stat \
112	    [stat_field $masterenv repmgr_stat "Acknowledgement failures"] 0
113
114	# Wait up to 20 seconds when testing for dropped connections. This
115	# corresponds to the master connection_retry timeout.
116	set max_wait 20
117	await_condition {[stat_field $masterenv repmgr_stat \
118	    "Connections dropped"] == 1} $max_wait
119
120	# Bring the client back up, and down, a couple times, to test resetting
121	# of stats.
122	#
123	puts "\tRepmgr$tnum.e: Shut down client (pause), check dropped connection."
124	# Open -recover to clear env region, including startup_done value.
125	set clientenv [eval $cl_envcmd -recover]
126	$clientenv repmgr -ack all -nsites $nsites \
127	    -timeout {conn_retry 10000000} \
128	    -local [list localhost [lindex $ports 1]] \
129	    -remote [list localhost [lindex $ports 0]] \
130	    -start client
131	await_startup_done $clientenv
132	$clientenv close
133
134	await_condition {[stat_field $masterenv repmgr_stat \
135	    "Connections dropped"] == 2} $max_wait
136	$masterenv repmgr_stat -clear
137
138	puts "\tRepmgr$tnum.f: Shut down, pause, check dropped connection (reset)."
139	# Open -recover to clear env region, including startup_done value.
140	set clientenv [eval $cl_envcmd -recover]
141	$clientenv repmgr -ack all -nsites $nsites \
142	    -timeout {conn_retry 10000000} \
143	    -local [list localhost [lindex $ports 1]] \
144	    -remote [list localhost [lindex $ports 0]] \
145	    -start client
146	await_startup_done $clientenv
147	$clientenv close
148
149	await_condition {[stat_field $masterenv repmgr_stat \
150	    "Connections dropped"] == 1} $max_wait
151
152	error_check_good masterenv_close [$masterenv close] 0
153}
154