summaryrefslogtreecommitdiff
path: root/db/test/rep028.tcl
blob: c466856e5844805389efb7601747a5d2488dc568 (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
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2004,2007 Oracle.  All rights reserved.
#
# $Id: rep028.tcl,v 12.15 2007/05/17 18:17:21 bostic Exp $
#
# TEST  	rep028
# TEST	Replication and non-rep env handles. (Also see rep006.)
# TEST
# TEST	Open second non-rep env on client, and create a db
# TEST	through this handle.  Open the db on master and put
# TEST	some data.  Check whether the non-rep handle keeps
# TEST	working.  Also check if opening the client database
# TEST	in the non-rep env writes log records.
#
proc rep028 { method { niter 100 } { tnum "028" } args } {

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

	# Run for btree only.
	if { $checking_valid_methods } {
		set test_methods { btree }
		return $test_methods
	}
	if { [is_btree $method] == 0 } {
		puts "\tRep$tnum: Skipping for method $method."
		return
	}

	# Skip test for HP-UX because we can't open an env twice.
	if { $is_hp_test == 1 } {
		puts "\tRep$tnum: Skipping for HP-UX."
		return
	}

	set args [convert_args $method $args]
	set logsets [create_logsets 2]

	# Run the body of the test with and without recovery.
	set clopts { "create" "open" }
	foreach r $test_recopts {
		foreach l $logsets {
			set logindex [lsearch -exact $l "in-memory"]
			if { $r == "-recover" && $logindex != -1 } {
				puts "Rep$tnum: Skipping\
				    for in-memory logs with -recover."
				continue
			}
			foreach c $clopts {
				puts "Rep$tnum ($method $r $c):\
				    Replication and non-rep env handles"
				puts "Rep$tnum: Master logs are [lindex $l 0]"
				puts "Rep$tnum: Client logs are [lindex $l 1]"
				rep028_sub $method $niter $tnum $l $r $c $args
			}
		}
	}
}

proc rep028_sub { method niter tnum logset recargs clargs largs } {
	source ./include.tcl
	global is_hp_test
	global rep_verbose

	set verbargs ""
	if { $rep_verbose == 1 } {
		set verbargs " -verbose {rep on} "
	}

	set omethod [convert_method $method]
	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.
	set m_logargs [adjust_logargs $m_logtype]
	set c_logargs [adjust_logargs $c_logtype]
	set m_txnargs [adjust_txnargs $m_logtype]
	set c_txnargs [adjust_txnargs $c_logtype]

	# Open a master.
	puts "\tRep$tnum.a: Open replicated envs and non-replicated client env."
	repladd 1
	set env_cmd(M) "berkdb_env_noerr -create \
	    -log_max 1000000 -home $masterdir $verbargs \
	    $m_txnargs $m_logargs -rep_master \
	    -rep_transport \[list 1 replsend\]"
	set masterenv [eval $env_cmd(M) $recargs]

	# Open a client
	repladd 2
	set env_cmd(C) "berkdb_env_noerr -create $c_txnargs \
	    $c_logargs -home $clientdir $verbargs \
	    -rep_transport \[list 2 replsend\]"
	set clientenv [eval $env_cmd(C) $recargs]

	# Open 2nd non-replication handle on client env, and create
	# a db.  Note, by not specifying any subsystem args, we
	# do a DB_JOINENV, which is what we want.
	set nonrepenv [eval {berkdb_env_noerr -home $clientdir}]
	error_check_good nonrepenv [is_valid_env $nonrepenv] TRUE

	set dbname "test$tnum.db"
	#
	# If we're testing create, verify that if a non-rep client
	# creates a database before the master does, then when that
	# client goes to use it, it gets DB_DEAD_HANDLE.
	#

	if { $clargs == "create" } {
		puts "\tRep$tnum.b: Create database non-replicated."
		set let c
		set nextlet d
		set nonrepdb [eval berkdb_open_noerr -auto_commit \
		    -create $omethod -env $nonrepenv $dbname]
		error_check_good nonrepdb_open [is_valid_db $nonrepdb] TRUE
		tclsleep 2
	} else {
		set let b
		set nextlet c
	}

	#
	# Now declare the clientenv a client.
	#
	puts "\tRep$tnum.$let: Declare env as rep client"
	error_check_good client [$clientenv rep_start -client] 0

	# Bring the client online by processing the startup messages.
	set envlist "{$masterenv 1} {$clientenv 2}"
	process_msgs $envlist 0 NONE err
	#
	# In the create case, we'll detect the non-rep log records and
	# determine this client was never part of the replication group.
	#
	if { $clargs == "create" } {
		error_check_good dead [is_substr $err \
		    "was never part"] 1
		error_check_good close [$nonrepdb close] 0
	}

	# Open the same db through the master handle.  Put data
	# and process messages.
	set db [eval berkdb_open_noerr \
	    -create $omethod -env $masterenv -auto_commit $dbname]
	error_check_good db_open [is_valid_db $db] TRUE
	eval rep_test $method $masterenv $db $niter 0 0 0 0 $largs
	process_msgs $envlist

	#
	# If we're the open case, we want to just read the existing
	# database through a non-rep readonly handle.  Doing so
	# should not create log records on the client (but has
	# in the past).
	#
	if { $clargs == "open" } {
		puts "\tRep$tnum.$nextlet: Open and read database"
		set nonrepdb [eval berkdb_open \
		    -rdonly -env $nonrepenv $dbname]
		error_check_good nonrepdb_open [is_valid_db $nonrepdb] TRUE
		#
		# If opening wrote log records, we need to process
		# some more on the client to notice the end of log
		# is now in an unexpected place.
		#
		eval rep_test $method $masterenv $db $niter 0 0 0 0 $largs
		process_msgs $envlist
		error_check_good close [$nonrepdb close] 0

		#
		# Verify master and client logs are identical
		#
		set stat [catch {eval exec $util_path/db_printlog \
		    -h $masterdir > $masterdir/prlog} result]
		error_check_good stat_mprlog $stat 0
		set stat [catch {eval exec $util_path/db_printlog \
		    -h $clientdir > $clientdir/prlog} result]
		error_check_good stat_cprlog $stat 0
		error_check_good log_cmp \
		    [filecmp $masterdir/prlog $clientdir/prlog] 0
	}
	# Clean up.
	error_check_good db_close [$db close] 0

	error_check_good nonrepenv_close [$nonrepenv close] 0
	error_check_good masterenv_close [$masterenv close] 0
	error_check_good clientenv_close [$clientenv close] 0

	replclose $testdir/MSGQUEUEDIR
}