1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996,2008 Oracle.  All rights reserved.
4#
5# $Id: recd003.tcl,v 12.8 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	recd003
8# TEST	Duplicate recovery tests.  For every known duplicate log message,
9# TEST	makes sure that we exercise redo, undo, and do-nothing condition.
10# TEST
11# TEST	Test all the duplicate log messages and recovery operations.  We make
12# TEST	sure that we exercise all possible recovery actions: redo, undo, undo
13# TEST	but no fix necessary and redo but no fix necessary.
14proc recd003 { method {select 0} args } {
15	source ./include.tcl
16	global rand_init
17
18	set envargs ""
19	set zero_idx [lsearch -exact $args "-zero_log"]
20	if { $zero_idx != -1 } {
21		set args [lreplace $args $zero_idx $zero_idx]
22		set envargs "-zero_log"
23	}
24
25	set largs [convert_args $method $args]
26	set omethod [convert_method $method]
27
28	if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
29		puts "Recd003 skipping for method $method"
30		return
31	}
32	puts "Recd003: $method duplicate recovery tests ($envargs)"
33
34	berkdb srand $rand_init
35
36	env_cleanup $testdir
37	# See comment in recd001.tcl for why there are two database files...
38	set testfile recd003.db
39	set testfile2 recd003-2.db
40	set eflags "-create -txn -home $testdir $envargs"
41
42	puts "\tRecd003.a: creating environment"
43	set env_cmd "berkdb_env $eflags"
44	set dbenv [eval $env_cmd]
45	error_check_bad dbenv $dbenv NULL
46
47	# Create the databases.
48	set oflags \
49	    "-create $largs -mode 0644 $omethod -dup -env $dbenv $testfile"
50	set db [eval {berkdb_open} $oflags]
51	error_check_bad db_open $db NULL
52	error_check_good db_open [is_substr $db db] 1
53	error_check_good db_close [$db close] 0
54	set oflags \
55	    "-create $largs -mode 0644 $omethod -dup -env $dbenv $testfile2"
56	set db [eval {berkdb_open} $oflags]
57	error_check_bad db_open $db NULL
58	error_check_good db_open [is_substr $db db] 1
59	error_check_good db_close [$db close] 0
60	reset_env $dbenv
61
62	# These are all the data values that we're going to need to read
63	# through the operation table and run the recovery tests.
64	set n 10
65	set dupn 2000
66	set bign 500
67
68	# List of recovery tests: {CMD MSG} pairs
69	set dlist {
70	{ {populate DB $omethod TXNID $n 1 0}
71	    "Recd003.b: add dups"}
72	{ {DB del -txn TXNID duplicate_key}
73	    "Recd003.c: remove dups all at once"}
74	{ {populate DB $omethod TXNID $n 1 0}
75	    "Recd003.d: add dups (change state)"}
76	{ {unpopulate DB TXNID 0}
77	    "Recd003.e: remove dups 1 at a time"}
78	{ {populate DB $omethod TXNID $dupn 1 0}
79	    "Recd003.f: dup split"}
80	{ {DB del -txn TXNID duplicate_key}
81	    "Recd003.g: remove dups (change state)"}
82	{ {populate DB $omethod TXNID $n 1 1}
83	    "Recd003.h: add big dup"}
84	{ {DB del -txn TXNID duplicate_key}
85	    "Recd003.i: remove big dup all at once"}
86	{ {populate DB $omethod TXNID $n 1 1}
87	    "Recd003.j: add big dup (change state)"}
88	{ {unpopulate DB TXNID 0}
89	    "Recd003.k: remove big dup 1 at a time"}
90	{ {populate DB $omethod TXNID $bign 1 1}
91	    "Recd003.l: split big dup"}
92	}
93
94	foreach pair $dlist {
95		set cmd [subst [lindex $pair 0]]
96		set msg [lindex $pair 1]
97		if { $select != 0 } {
98			set tag [lindex $msg 0]
99			set tail [expr [string length $tag] - 2]
100			set tag [string range $tag $tail $tail]
101			if { [lsearch $select $tag] == -1 } {
102				continue
103			}
104		}
105		op_recover abort $testdir $env_cmd $testfile $cmd $msg
106		op_recover commit $testdir $env_cmd $testfile $cmd $msg
107		#
108		# Note that since prepare-discard ultimately aborts
109		# the txn, it must come before prepare-commit.
110		#
111		op_recover prepare-abort $testdir $env_cmd $testfile2 \
112			$cmd $msg
113		op_recover prepare-discard $testdir $env_cmd $testfile2 \
114			$cmd $msg
115		op_recover prepare-commit $testdir $env_cmd $testfile2 \
116			$cmd $msg
117	}
118
119	puts "\tRecd003.m: Verify db_printlog can read logfile"
120	set tmpfile $testdir/printlog.out
121	set stat [catch {exec $util_path/db_printlog -h $testdir \
122	    > $tmpfile} ret]
123	error_check_good db_printlog $stat 0
124	fileremove $tmpfile
125}
126