1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2001,2008 Oracle.  All rights reserved.
4#
5# $Id: rep077.tcl,v 12.3 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST  rep077
8# TEST
9# TEST	Replication, recovery and applying log records immediately.
10# TEST	Master and 1 client.  Start up both sites.
11# TEST	Close client and run rep_test on the master so that the
12# TEST	log record is the same LSN the client would be expecting.
13# TEST	Reopen client with recovery and verify the client does not
14# TEST	try to apply that "expected" record before it synchronizes
15# TEST	with the master.
16#
17proc rep077 { method { tnum "077"} args} {
18	source ./include.tcl
19
20	if { $is_windows9x_test == 1 } {
21		puts "Skipping replication test on Win9x 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 logsets [create_logsets 2]
32
33	foreach l $logsets {
34		puts "Rep$tnum ($method):\
35		    Recovered client getting immediate log records."
36		puts "Rep$tnum: Master logs are [lindex $l 0]"
37		puts "Rep$tnum: Client logs are [lindex $l 1]"
38		rep077_sub $method $tnum $l $args
39	}
40}
41
42proc rep077_sub { method tnum logset largs} {
43	global testdir
44	global rep_verbose
45	global verbose_type
46
47	set verbargs ""
48	if { $rep_verbose == 1 } {
49		set verbargs " -verbose {$verbose_type on} "
50	}
51
52	set niter 5
53	env_cleanup $testdir
54
55	replsetup $testdir/MSGQUEUEDIR
56
57	set masterdir $testdir/MASTERDIR
58	set clientdir $testdir/CLIENTDIR
59
60	file mkdir $masterdir
61	file mkdir $clientdir
62
63        set m_logtype [lindex $logset 0]
64	set c_logtype [lindex $logset 1]
65
66	# In-memory logs cannot be used with -txn nosync.
67	set m_logargs [adjust_logargs $m_logtype]
68	set c_logargs [adjust_logargs $c_logtype]
69	set m_txnargs [adjust_txnargs $m_logtype]
70	set c_txnargs [adjust_txnargs $c_logtype]
71
72	# Open a master.
73	repladd 1
74	set env_cmd(M) "berkdb_env_noerr -create \
75	    $verbargs \
76	    -home $masterdir -errpfx MASTER -txn nosync -rep_master \
77	    -rep_transport \[list 1 replsend\]"
78	set masterenv [eval $env_cmd(M)]
79
80	eval rep_test $method $masterenv NULL $niter 0 0 0 0 $largs
81
82	# Open a client
83	repladd 2
84	set env_cmd(C) "berkdb_env_noerr -create \
85	    $verbargs \
86	    -home $clientdir -errpfx CLIENT -txn nosync -rep_client \
87	    -rep_transport \[list 2 replsend\]"
88	set clientenv [eval $env_cmd(C)]
89
90	puts "\tRep$tnum.a: Start up master and client."
91	# Bring the client online by processing the startup messages.
92	set envlist "{$masterenv 1} {$clientenv 2}"
93	process_msgs $envlist
94
95	puts "\tRep$tnum.b: Close client."
96	$clientenv close
97
98	#
99	# We want to run rep_test now and DO NOT replclear the
100	# messages for the closed client.  We want to make sure
101	# that the first message the client sees upon restarting
102	# is a log record that exactly matches the current
103	# expected LSN.
104	#
105	puts "\tRep$tnum.c: Run rep_test on master with client closed."
106	#
107	# Move it forward by sending in niter as start and skip.
108	#
109	eval rep_test $method $masterenv NULL $niter $niter $niter 0 0 $largs
110
111	# We need to reopen with recovery to blow away our idea of
112	# who the master is, because this client will start up with
113	# the right generation number and the ready_lsn will be
114	# set to the right value for the first log record to apply.
115	#
116	# However, this client is running recovery and will have
117	# written its own recovery log records.  So, until this
118	# client finds and synchronizes with the master after
119	# restarting, its ready_lsn and lp->lsn will not be
120	# in sync and this client better not try to apply the records.
121	#
122	puts "\tRep$tnum.d: Restart client with recovery and process messages."
123	set clientenv [eval $env_cmd(C) -recover]
124	set envlist "{$masterenv 1} {$clientenv 2}"
125	process_msgs $envlist
126
127	#
128	# If we didn't crash at this point, we're okay.
129	#
130	$masterenv close
131	$clientenv close
132	replclose $testdir/MSGQUEUEDIR
133}
134