1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2003-2009 Oracle.  All rights reserved.
4#
5# $Id$
6#
7# TEST  rep006
8# TEST	Replication and non-rep env handles.
9# TEST
10# TEST	Run a modified version of test001 in a replicated master
11# TEST	environment; verify that the database on the client is correct.
12# TEST	Next, create a non-rep env handle to the master env.
13# TEST	Attempt to open the database r/w to force error.
14
15proc rep006 { method { niter 1000 } { tnum "006" } args } {
16
17	source ./include.tcl
18	global databases_in_memory
19	global repfiles_in_memory
20
21	if { $is_windows9x_test == 1 } {
22		puts "Skipping replication test on Win 9x platform."
23		return
24	}
25	set logsets [create_logsets 2]
26
27	# All access methods are allowed.
28	if { $checking_valid_methods } {
29		return "ALL"
30	}
31
32	set msg "using on-disk databases"
33	if { $databases_in_memory } {
34		set msg "using named in-memory databases"
35		if { [is_queueext $method] } {
36			puts -nonewline "Skipping rep$tnum for method "
37			puts "$method with named in-memory databases."
38			return
39		}
40	}
41
42	set msg2 "and on-disk replication files"
43	if { $repfiles_in_memory } {
44		set msg2 "and in-memory replication files"
45	}
46
47	# Run the body of the test with and without recovery.
48	foreach r $test_recopts {
49		foreach l $logsets {
50			set logindex [lsearch -exact $l "in-memory"]
51			if { $r == "-recover" && $logindex != -1 } {
52				puts "Rep$tnum: Skipping for in-memory logs\
53				    with -recover."
54				continue
55			}
56			puts "Rep$tnum ($method $r): Replication and\
57			    non-rep env handles $msg $msg2."
58			puts "Rep$tnum: Master logs are [lindex $l 0]"
59			puts "Rep$tnum: Client logs are [lindex $l 1]"
60			rep006_sub $method $niter $tnum $l $r $args
61		}
62	}
63}
64
65proc rep006_sub { method niter tnum logset recargs largs } {
66	source ./include.tcl
67	global testdir
68	global is_hp_test
69	global databases_in_memory
70	global repfiles_in_memory
71	global rep_verbose
72	global verbose_type
73
74	set verbargs ""
75	if { $rep_verbose == 1 } {
76		set verbargs " -verbose {$verbose_type on} "
77	}
78
79	set repmemargs ""
80	if { $repfiles_in_memory } {
81		set repmemargs "-rep_inmem_files "
82	}
83
84	env_cleanup $testdir
85
86	replsetup $testdir/MSGQUEUEDIR
87
88	set masterdir $testdir/MASTERDIR
89	set clientdir $testdir/CLIENTDIR
90
91	file mkdir $masterdir
92	file mkdir $clientdir
93
94	set m_logtype [lindex $logset 0]
95	set c_logtype [lindex $logset 1]
96
97	# In-memory logs require a large log buffer, and cannot
98	# be used with -txn nosync.
99	set m_logargs [adjust_logargs $m_logtype]
100	set c_logargs [adjust_logargs $c_logtype]
101	set m_txnargs [adjust_txnargs $m_logtype]
102	set c_txnargs [adjust_txnargs $c_logtype]
103
104	if { [is_record_based $method] == 1 } {
105		set checkfunc test001_recno.check
106	} else {
107		set checkfunc test001.check
108	}
109
110	# Open a master.
111	repladd 1
112	set max_locks 2500
113	set env_cmd(M) "berkdb_env_noerr -create -log_max 1000000 \
114	    -lock_max_objects $max_locks -lock_max_locks $max_locks \
115	    -home $masterdir -errpfx MASTER $verbargs $repmemargs \
116	    $m_txnargs $m_logargs -rep_master -rep_transport \
117	    \[list 1 replsend\]"
118	set masterenv [eval $env_cmd(M) $recargs]
119
120	# Open a client
121	repladd 2
122	set env_cmd(C) "berkdb_env_noerr -create $c_txnargs $c_logargs \
123	    -lock_max_objects $max_locks -lock_max_locks $max_locks \
124	    -home $clientdir -errpfx CLIENT $verbargs $repmemargs \
125	    -rep_client -rep_transport \[list 2 replsend\]"
126	set clientenv [eval $env_cmd(C) $recargs]
127
128	# Bring the client online by processing the startup messages.
129	set envlist "{$masterenv 1} {$clientenv 2}"
130	process_msgs $envlist
131
132	# Run a modified test001 in the master (and update client).
133	puts "\tRep$tnum.a: Running test001 in replicated env."
134	eval rep_test $method $masterenv NULL $niter 0 0 0 $largs
135	process_msgs $envlist
136
137	# Check that databases are in-memory or on-disk as expected.
138	if { $databases_in_memory } {
139		set dbname { "" "test.db" }
140	} else {
141		set dbname "test.db"
142	}
143	check_db_location $masterenv
144	check_db_location $clientenv
145
146	# Verify the database in the client dir.
147	puts "\tRep$tnum.b: Verifying client database contents."
148	set testdir [get_home $masterenv]
149	set t1 $testdir/t1
150	set t2 $testdir/t2
151	set t3 $testdir/t3
152	open_and_dump_file $dbname $clientenv $t1 \
153	    $checkfunc dump_file_direction "-first" "-next"
154
155	# Determine whether this build is configured with --enable-debug_rop
156	# or --enable-debug_wop; we'll need to skip portions of the test if so.
157	# Also check for *not* configuring with diagnostic.  That similarly
158	# forces a different code path and we need to skip portions.
159	set conf [berkdb getconfig]
160	set skip_for_config 0
161	if { [is_substr $conf "debug_rop"] == 1 \
162	    || [is_substr $conf "debug_wop"] == 1 \
163	    || [is_substr $conf "diagnostic"] == 0 } {
164		set skip_for_config 1
165	}
166
167	# Skip if configured with --enable-debug_rop or --enable-debug_wop
168	# or without --enable-diagnostic,
169	# because the checkpoint won't fail in those cases.
170	if { $skip_for_config == 1 } {
171		puts "\tRep$tnum.c: Skipping based on configuration."
172	} else {
173		puts "\tRep$tnum.c: Verifying non-master db_checkpoint."
174		set stat \
175		    [catch {exec $util_path/db_checkpoint -h $masterdir -1} ret]
176		error_check_good open_err $stat 1
177		error_check_good \
178		    open_err1 [is_substr $ret "attempting to modify"] 1
179	}
180
181	# We have to skip this bit for HP-UX because we can't open an env
182	# twice, and for debug_rop/debug_wop because the open won't fail.
183	if { $is_hp_test == 1 } {
184		puts "\tRep$tnum.d: Skipping for HP-UX."
185	} elseif { $skip_for_config == 1 } {
186		puts "\tRep$tnum.d: Skipping based on configuration."
187	} else {
188		puts "\tRep$tnum.d: Verifying non-master access."
189
190		set rdenv [eval {berkdb_env_noerr} \
191		    -home $masterdir $verbargs]
192		error_check_good rdenv [is_valid_env $rdenv] TRUE
193		#
194		# Open the db read/write which will cause it to try to
195		# write out a log record, which should fail.
196		#
197		set stat \
198		    [catch {berkdb_open_noerr -env $rdenv $dbname} ret]
199		error_check_good open_err $stat 1
200		error_check_good \
201		    open_err1 [is_substr $ret "attempting to modify"] 1
202		error_check_good rdenv_close [$rdenv close] 0
203	}
204
205	process_msgs $envlist
206
207	error_check_good masterenv_close [$masterenv close] 0
208	error_check_good clientenv_close [$clientenv close] 0
209
210	error_check_good verify \
211	    [verify_dir $clientdir "\tRep$tnum.e: " 0 0 1] 0
212	replclose $testdir/MSGQUEUEDIR
213}
214