1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996,2008 Oracle.  All rights reserved.
4#
5# $Id: recd002.tcl,v 12.10 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	recd002
8# TEST	Split recovery tests.  For every known split log message, makes sure
9# TEST	that we exercise redo, undo, and do-nothing condition.
10proc recd002 { method {select 0} args} {
11	source ./include.tcl
12	global rand_init
13
14	set envargs ""
15	set zero_idx [lsearch -exact $args "-zero_log"]
16	if { $zero_idx != -1 } {
17		set args [lreplace $args $zero_idx $zero_idx]
18		set envargs "-zero_log"
19	}
20
21	set args [convert_args $method $args]
22	set omethod [convert_method $method]
23
24	set pgindex [lsearch -exact $args "-pagesize"]
25	if { $pgindex != -1 } {
26		puts "Recd002: skipping for specific pagesizes"
27		return
28	}
29	berkdb srand $rand_init
30
31	# Queues don't do splits, so we don't really need the small page
32	# size and the small page size is smaller than the record, so it's
33	# a problem.
34	if { [string compare $omethod "-queue"] == 0 } {
35		set pagesize 4096
36	} else {
37		set pagesize 512
38	}
39	puts "Recd002: $method split recovery tests ($envargs)"
40
41	env_cleanup $testdir
42	set testfile recd002.db
43	set testfile2 recd002-2.db
44	set eflags "-create -txn -lock_max_locks 2000 -home $testdir $envargs"
45
46	puts "\tRecd002.a: creating environment"
47	set env_cmd "berkdb_env $eflags"
48	set dbenv [eval $env_cmd]
49	error_check_bad dbenv $dbenv NULL
50
51	# Create the databases. We will use a small page size so that splits
52	# happen fairly quickly.
53	set oflags "-create $args $omethod -mode 0644 -env $dbenv\
54	    -pagesize $pagesize $testfile"
55	set db [eval {berkdb_open} $oflags]
56	error_check_bad db_open $db NULL
57	error_check_good db_open [is_substr $db db] 1
58	error_check_good db_close [$db close] 0
59	set oflags "-create $args $omethod -mode 0644 -env $dbenv\
60	    -pagesize $pagesize $testfile2"
61	set db [eval {berkdb_open} $oflags]
62	error_check_bad db_open $db NULL
63	error_check_good db_open [is_substr $db db] 1
64	error_check_good db_close [$db close] 0
65	reset_env $dbenv
66
67	# List of recovery tests: {CMD MSG} pairs
68	set slist {
69		{ {populate DB $omethod TXNID $n 0 0} "Recd002.b: splits"}
70		{ {unpopulate DB TXNID $r} "Recd002.c: Remove keys"}
71	}
72
73	# If pages are 512 bytes, then adding 512 key/data pairs
74	# should be more than sufficient.
75	set n 512
76	set r [expr $n / 2 ]
77	foreach pair $slist {
78		set cmd [subst [lindex $pair 0]]
79		set msg [lindex $pair 1]
80		if { $select != 0 } {
81			set tag [lindex $msg 0]
82			set tail [expr [string length $tag] - 2]
83			set tag [string range $tag $tail $tail]
84			if { [lsearch $select $tag] == -1 } {
85				continue
86			}
87		}
88		op_recover abort $testdir $env_cmd $testfile $cmd $msg
89		op_recover commit $testdir $env_cmd $testfile $cmd $msg
90		#
91		# Note that since prepare-discard ultimately aborts
92		# the txn, it must come before prepare-commit.
93		#
94		op_recover prepare-abort $testdir $env_cmd $testfile2 \
95			$cmd $msg
96		op_recover prepare-discard $testdir $env_cmd $testfile2 \
97			$cmd $msg
98		op_recover prepare-commit $testdir $env_cmd $testfile2 \
99			$cmd $msg
100	}
101
102	puts "\tRecd002.d: Verify db_printlog can read logfile"
103	set tmpfile $testdir/printlog.out
104	set stat [catch {exec $util_path/db_printlog -h $testdir \
105	    > $tmpfile} ret]
106	error_check_good db_printlog $stat 0
107	fileremove $tmpfile
108}
109