summaryrefslogtreecommitdiff
path: root/db/test/rep003.tcl
blob: c9a2e793a30cec587cc552e724ba81a233399bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2002-2006
#	Oracle Corporation.  All rights reserved.
#
# $Id: rep003.tcl,v 12.7 2006/08/24 14:46:37 bostic Exp $
#
# TEST  	rep003
# TEST	Repeated shutdown/restart replication test
# TEST
# TEST	Run a quick put test in a replicated master environment;
# TEST	start up, shut down, and restart client processes, with
# TEST	and without recovery.  To ensure that environment state
# TEST	is transient, use DB_PRIVATE.

proc rep003 { method { tnum "003" } args } {
	source ./include.tcl
	global rep003_dbname rep003_omethod rep003_oargs

	if { $is_windows9x_test == 1 } {
		puts "Skipping replication test on Win 9x platform."
		return
	}

	# Skip for record-based methods.
	if { $checking_valid_methods } {
		set test_methods {}
		foreach method $valid_methods {
			if { [is_record_based $method] != 1 } {
				lappend test_methods $method
			}
		}
		return $test_methods
	}
	if { [is_record_based $method] } {
		puts "Rep$tnum: Skipping for method $method"
		return
	}

	set rep003_dbname rep003.db
	set rep003_omethod [convert_method $method]
	set rep003_oargs [convert_args $method $args]

	# Run the body of the test with and without recovery.  If we're
	# testing in-memory logging, skip the combination of recovery
	# and in-memory logging -- it doesn't make sense.

	set logsets [create_logsets 2]
	foreach recopt $test_recopts {
		foreach l $logsets {
			set logindex [lsearch -exact $l "in-memory"]
			if { $recopt == "-recover" && $logindex != -1 } {
				puts "Rep$tnum: Skipping for\
				    in-memory logs with -recover."
				continue
			}
			puts "Rep$tnum ($method $recopt):\
			    Replication repeated-startup test."
			puts "Rep$tnum: Master logs are [lindex $l 0]"
			puts "Rep$tnum: Client logs are [lindex $l 1]"
			rep003_sub $method $tnum $l $recopt $args
		}
	}
}

proc rep003_sub { method tnum logset recargs largs } {
	source ./include.tcl

	env_cleanup $testdir

	replsetup $testdir/MSGQUEUEDIR

	set masterdir $testdir/MASTERDIR
	set clientdir $testdir/CLIENTDIR

	file mkdir $masterdir
	file mkdir $clientdir

	set m_logtype [lindex $logset 0]
	set c_logtype [lindex $logset 1]

	# In-memory logs require a large log buffer, and cannot
	# be used with -txn nosync.  This test already requires
	# -txn, so adjust the logargs only.
	set m_logargs [adjust_logargs $m_logtype]
	set c_logargs [adjust_logargs $c_logtype]

	# Open a master.
	repladd 1
	set env_cmd(M) "berkdb_env_noerr -create -log_max 1000000 \
	    -errpfx MASTER -errfile /dev/stderr \
	    -home $masterdir -txn $m_logargs -rep_master \
	    -rep_transport \[list 1 replsend\]"
	set masterenv [eval $env_cmd(M) $recargs]
	error_check_good master_env [is_valid_env $masterenv] TRUE

	puts "\tRep$tnum.a: Simple client startup test."

	# Put item one.
	rep003_put $masterenv A1 a-one

	# Open a client.
	repladd 2
	set env_cmd(C) "berkdb_env_noerr -create -private -home $clientdir \
	    -txn $c_logargs -errpfx CLIENT -errfile /dev/stderr \
	    -rep_client -rep_transport \[list 2 replsend\]"
	set clientenv [eval $env_cmd(C) $recargs]
	error_check_good client_env [is_valid_env $clientenv] TRUE

	# Put another quick item.
	rep003_put $masterenv A2 a-two

	# Loop, processing first the master's messages, then the client's,
	# until both queues are empty.
	set envlist "{$masterenv 1} {$clientenv 2}"
	process_msgs $envlist

	rep003_check $clientenv A1 a-one
	rep003_check $clientenv A2 a-two

	error_check_good clientenv_close [$clientenv close] 0
	replclear 2

	# Now reopen the client after doing another put.
	puts "\tRep$tnum.b: Client restart."
	rep003_put $masterenv B1 b-one

	unset clientenv
	set clientenv [berkdb_env_noerr -create -private -home $clientdir -txn \
	    -rep_client -rep_transport [list 2 replsend]]
	error_check_good client_env [is_valid_env $clientenv] TRUE

	# Loop letting the client and master sync up and get the
	# environment initialized.  It's a new client env so
	# reinitialize the envlist as well.
	set envlist "{$masterenv 1} {$clientenv 2}"
	process_msgs $envlist

	# The items from part A should be present at all times--
	# if we roll them back, we've screwed up. [#5709]
	rep003_check $clientenv A1 a-one
	rep003_check $clientenv A2 a-two

	rep003_put $masterenv B2 b-two

	# Loop, processing first the master's messages, then the client's,
	# until both queues are empty.
	while { 1 } {
		set nproced 0

		incr nproced [replprocessqueue $masterenv 1]
		incr nproced [replprocessqueue $clientenv 2]

		# The items from part A should be present at all times--
		# if we roll them back, we've screwed up. [#5709]
		rep003_check $clientenv A1 a-one
		rep003_check $clientenv A2 a-two

		if { $nproced == 0 } {
			break
		}
	}

	rep003_check $clientenv B1 b-one
	rep003_check $clientenv B2 b-two

	error_check_good clientenv_close [$clientenv close] 0

	replclear 2

	# Now reopen the client after a recovery.
	puts "\tRep$tnum.c: Client restart after recovery."
	rep003_put $masterenv C1 c-one

	unset clientenv
	set clientenv [berkdb_env_noerr -create -private -home $clientdir -txn \
	    -recover -rep_client -rep_transport [list 2 replsend]]
	error_check_good client_env [is_valid_env $clientenv] TRUE

	# Loop, processing first the master's messages, then the client's,
	# until both queues are empty.
	set envlist "{$masterenv 1} {$clientenv 2}"
	process_msgs $envlist

	# The items from part A should be present at all times--
	# if we roll them back, we've screwed up. [#5709]
	rep003_check $clientenv A1 a-one
	rep003_check $clientenv A2 a-two
	rep003_check $clientenv B1 b-one
	rep003_check $clientenv B2 b-two

	rep003_put $masterenv C2 c-two

	# Loop, processing first the master's messages, then the client's,
	# until both queues are empty.
	while { 1 } {
		set nproced 0

		# The items from part A should be present at all times--
		# if we roll them back, we've screwed up. [#5709]
		rep003_check $clientenv A1 a-one
		rep003_check $clientenv A2 a-two
		rep003_check $clientenv B1 b-one
		rep003_check $clientenv B2 b-two

		incr nproced [replprocessqueue $masterenv 1]
		incr nproced [replprocessqueue $clientenv 2]

		if { $nproced == 0 } {
			break
		}
	}

	rep003_check $clientenv C1 c-one
	rep003_check $clientenv C2 c-two

	error_check_good clientenv_close [$clientenv close] 0

	replclear 2

	# Now reopen the client after a catastrophic recovery.
	puts "\tRep$tnum.d: Client restart after catastrophic recovery."
	rep003_put $masterenv D1 d-one

	unset clientenv
	set clientenv [berkdb_env_noerr -create -private -home $clientdir -txn \
	    -recover_fatal -rep_client -rep_transport [list 2 replsend]]
	error_check_good client_env [is_valid_env $clientenv] TRUE

	# Loop, processing first the master's messages, then the client's,
	# until both queues are empty.
	set envlist "{$masterenv 1} {$clientenv 2}"
	process_msgs $envlist
	rep003_put $masterenv D2 d-two

	# Loop, processing first the master's messages, then the client's,
	# until both queues are empty.
	while { 1 } {
		set nproced 0

		# The items from part A should be present at all times--
		# if we roll them back, we've screwed up. [#5709]
		rep003_check $clientenv A1 a-one
		rep003_check $clientenv A2 a-two
		rep003_check $clientenv B1 b-one
		rep003_check $clientenv B2 b-two
		rep003_check $clientenv C1 c-one
		rep003_check $clientenv C2 c-two

		incr nproced [replprocessqueue $masterenv 1]
		incr nproced [replprocessqueue $clientenv 2]

		if { $nproced == 0 } {
			break
		}
	}

	rep003_check $clientenv D1 d-one
	rep003_check $clientenv D2 d-two

	error_check_good clientenv_close [$clientenv close] 0

	error_check_good masterenv_close [$masterenv close] 0
	replclose $testdir/MSGQUEUEDIR
}

proc rep003_put { masterenv key data } {
	global rep003_dbname rep003_omethod rep003_oargs

	set db [eval {berkdb_open_noerr -create -env $masterenv -auto_commit} \
	    $rep003_omethod $rep003_oargs $rep003_dbname]
	error_check_good rep3_put_open($key,$data) [is_valid_db $db] TRUE

	set txn [$masterenv txn]
	error_check_good rep3_put($key,$data) [$db put -txn $txn $key $data] 0
	error_check_good rep3_put_txn_commit($key,$data) [$txn commit] 0

	error_check_good rep3_put_close($key,$data) [$db close] 0
}

proc rep003_check { env key data } {
	global rep003_dbname

	set db [berkdb_open_noerr -rdonly -env $env $rep003_dbname]
	error_check_good rep3_check_open($key,$data) [is_valid_db $db] TRUE

	set dbt [$db get $key]
	error_check_good rep3_check($key,$data) \
	    [lindex [lindex $dbt 0] 1] $data

	error_check_good rep3_put_close($key,$data) [$db close] 0
}