1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2004,2008 Oracle.  All rights reserved.
4#
5# $Id: rep037.tcl,v 12.19 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	rep037
8# TEST	Test of internal initialization and page throttling.
9# TEST
10# TEST	One master, one client, force page throttling.
11# TEST	Generate several log files.
12# TEST	Remove old master log files.
13# TEST	Delete client files and restart client.
14# TEST	Put one more record to the master.
15# TEST  Verify page throttling occurred.
16#
17proc rep037 { method { niter 1500 } { tnum "037" } args } {
18
19	source ./include.tcl
20	if { $is_windows9x_test == 1 } {
21		puts "Skipping replication test on Win 9x platform."
22		return
23	}
24
25	# Valid for all access methods.
26	if { $checking_valid_methods } {
27		return "ALL"
28	}
29
30	set args [convert_args $method $args]
31	set saved_args $args
32
33        # This test needs to set its own pagesize.
34	set pgindex [lsearch -exact $args "-pagesize"]
35	if { $pgindex != -1 } {
36		puts "Rep$tnum: skipping for specific pagesizes"
37		return
38	}
39
40	set logsets [create_logsets 2]
41
42	# Run the body of the test with and without recovery,
43	# and with and without cleaning.
44	set cleanopts { bulk clean noclean }
45	foreach r $test_recopts {
46		foreach c $cleanopts {
47			foreach l $logsets {
48				set logindex [lsearch -exact $l "in-memory"]
49				if { $r == "-recover" && $logindex != -1 } {
50					puts "Skipping rep$tnum for -recover\
51					    with in-memory logs."
52					continue
53				}
54				set args $saved_args
55				puts "Rep$tnum ($method $c $r $args):\
56				    Test of internal init with page throttling."
57				puts "Rep$tnum: Master logs are [lindex $l 0]"
58				puts "Rep$tnum: Client logs are [lindex $l 1]"
59				rep037_sub $method $niter $tnum $l $r $c $args
60			}
61		}
62	}
63}
64
65proc rep037_sub { method niter tnum logset recargs clean largs } {
66	global testdir
67	global util_path
68	global rep_verbose
69	global verbose_type
70
71	set verbargs ""
72	if { $rep_verbose == 1 } {
73		set verbargs " -verbose {$verbose_type on} "
74	}
75
76	env_cleanup $testdir
77
78	replsetup $testdir/MSGQUEUEDIR
79
80	set masterdir $testdir/MASTERDIR
81	set clientdir $testdir/CLIENTDIR
82
83	file mkdir $masterdir
84	file mkdir $clientdir
85
86	# Log size is small so we quickly create more than one.
87	# The documentation says that the log file must be at least
88	# four times the size of the in-memory log buffer.
89	set pagesize 4096
90	append largs " -pagesize $pagesize "
91	set log_max [expr $pagesize * 8]
92
93	set m_logtype [lindex $logset 0]
94	set c_logtype [lindex $logset 1]
95
96	# In-memory logs cannot be used with -txn nosync.
97	set m_logargs [adjust_logargs $m_logtype]
98	set c_logargs [adjust_logargs $c_logtype]
99	set m_txnargs [adjust_txnargs $m_logtype]
100	set c_txnargs [adjust_txnargs $c_logtype]
101
102	#
103	# If using bulk processing, just use clean.  We could add
104	# another control loop to do bulk+clean and then bulk+noclean
105	# but that seems like overkill.
106	#
107	set bulk 0
108	if { $clean == "bulk" } {
109		set bulk 1
110		set clean "clean"
111	}
112	# Open a master.
113	repladd 1
114	set ma_envcmd "berkdb_env_noerr -create $m_txnargs \
115	    $m_logargs -log_max $log_max -errpfx MASTER $verbargs \
116	    -home $masterdir -rep_transport \[list 1 replsend\]"
117	set masterenv [eval $ma_envcmd $recargs -rep_master]
118	$masterenv rep_limit 0 [expr 32 * 1024]
119
120	# Open a client
121	repladd 2
122	set cl_envcmd "berkdb_env_noerr -create $c_txnargs \
123	    $c_logargs -log_max $log_max -errpfx CLIENT $verbargs \
124	    -home $clientdir -rep_transport \[list 2 replsend\]"
125	set clientenv [eval $cl_envcmd $recargs -rep_client]
126	error_check_good client_env [is_valid_env $clientenv] TRUE
127
128	if { $bulk } {
129		error_check_good set_bulk [$masterenv rep_config {bulk on}] 0
130	}
131
132	# Bring the clients online by processing the startup messages.
133	set envlist "{$masterenv 1} {$clientenv 2}"
134	process_msgs $envlist
135
136	# Clobber replication's 30-second anti-archive timer, which will have
137	# been started by client sync-up internal init, so that we can do a
138	# log_archive in a moment.
139	#
140	$masterenv test force noarchive_timeout
141
142	# Run rep_test in the master (and update client).
143	puts "\tRep$tnum.a: Running rep_test in replicated env."
144	set start 0
145	eval rep_test $method $masterenv NULL $niter $start $start 0 0 $largs
146	incr start $niter
147	process_msgs $envlist
148
149	puts "\tRep$tnum.b: Close client."
150	if { $c_logtype != "in-memory" } {
151		set res [eval exec $util_path/db_archive -l -h $clientdir]
152	}
153	set last_client_log [get_logfile $clientenv last]
154	error_check_good client_close [$clientenv close] 0
155
156	set stop 0
157	while { $stop == 0 } {
158		# Run rep_test in the master (don't update client).
159		puts "\tRep$tnum.c: Running rep_test in replicated env."
160	 	eval rep_test \
161		    $method $masterenv NULL $niter $start $start 0 0 $largs
162		incr start $niter
163		replclear 2
164
165		puts "\tRep$tnum.d: Run db_archive on master."
166		if { $m_logtype != "in-memory"} {
167			set res \
168			    [eval exec $util_path/db_archive -d -h $masterdir]
169		}
170		# Make sure that we have a gap between the last client
171		# log and the first master log.
172		set first_master_log [get_logfile $masterenv first]
173		if { $first_master_log > $last_client_log } {
174			set stop 1
175		}
176	}
177
178	puts "\tRep$tnum.e: Reopen client ($clean)."
179	if { $clean == "clean" } {
180		env_cleanup $clientdir
181	}
182	set clientenv [eval $cl_envcmd $recargs -rep_client]
183	error_check_good client_env [is_valid_env $clientenv] TRUE
184	set envlist "{$masterenv 1} {$clientenv 2}"
185	process_msgs $envlist 0 NONE err
186	if { $clean == "noclean" } {
187		puts "\tRep$tnum.e.1: Trigger log request"
188		#
189		# When we don't clean, starting the client doesn't
190		# trigger any events.  We need to generate some log
191		# records so that the client requests the missing
192		# logs and that will trigger it.
193		#
194		set entries 10
195		eval rep_test $method \
196		    $masterenv NULL $entries $niter $start $start 0 $largs
197		process_msgs $envlist 0 NONE err
198	}
199
200	puts "\tRep$tnum.f: Verify logs and databases"
201	rep_verify $masterdir $masterenv $clientdir $clientenv 1
202
203	puts "\tRep$tnum.g: Verify throttling."
204	if { $niter > 1000 } {
205                set nthrottles \
206		    [stat_field $masterenv rep_stat "Transmission limited"]
207		error_check_bad nthrottles $nthrottles -1
208		error_check_bad nthrottles $nthrottles 0
209	}
210
211	# Make sure log files are on-disk or not as expected.
212	check_log_location $masterenv
213	check_log_location $clientenv
214
215	error_check_good masterenv_close [$masterenv close] 0
216	error_check_good clientenv_close [$clientenv close] 0
217	replclose $testdir/MSGQUEUEDIR
218}
219