1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2000,2008 Oracle.  All rights reserved.
4#
5# $Id: recd018.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	recd018
8# TEST	Test recover of closely interspersed checkpoints and commits.
9#
10# This test is from the error case from #4230.
11#
12proc recd018 { method {ndbs 10} args } {
13	source ./include.tcl
14
15	set args [convert_args $method $args]
16	set omethod [convert_method $method]
17	set tnum "018"
18
19	puts "Recd$tnum ($args): $method recovery of checkpoints and commits."
20
21	set tname recd$tnum.db
22	env_cleanup $testdir
23
24	set i 0
25	if { [is_record_based $method] == 1 } {
26		set key 1
27		set key2 2
28	} else {
29		set key KEY
30		set key2 KEY2
31	}
32
33	puts "\tRecd$tnum.a: Create environment and database."
34	set flags "-create -txn -home $testdir"
35
36	set env_cmd "berkdb_env $flags"
37	set dbenv [eval $env_cmd]
38	error_check_good dbenv [is_valid_env $dbenv] TRUE
39
40	set oflags "-auto_commit -env $dbenv -create -mode 0644 $args $omethod"
41	for { set i 0 } { $i < $ndbs } { incr i } {
42		set testfile $tname.$i
43		set db($i) [eval {berkdb_open} $oflags $testfile]
44		error_check_good dbopen [is_valid_db $db($i)] TRUE
45		set file $testdir/$testfile.init
46		catch { file copy -force $testdir/$testfile $file} res
47		copy_extent_file $testdir $testfile init
48	}
49
50	# Main loop:  Write a record or two to each database.
51	# Do a commit immediately followed by a checkpoint after each one.
52	error_check_good "Initial Checkpoint" [$dbenv txn_checkpoint] 0
53
54	puts "\tRecd$tnum.b Put/Commit/Checkpoint to $ndbs databases"
55	for { set i 0 } { $i < $ndbs } { incr i } {
56		set testfile $tname.$i
57		set data $i
58
59		# Put, in a txn.
60		set txn [$dbenv txn]
61		error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE
62		error_check_good db_put \
63		    [$db($i) put -txn $txn $key [chop_data $method $data]] 0
64		error_check_good txn_commit [$txn commit] 0
65		error_check_good txn_checkpt [$dbenv txn_checkpoint] 0
66		if { [expr $i % 2] == 0 } {
67			set txn [$dbenv txn]
68			error_check_good txn2 [is_valid_txn $txn $dbenv] TRUE
69			error_check_good db_put [$db($i) put \
70			    -txn $txn $key2 [chop_data $method $data]] 0
71			error_check_good txn_commit [$txn commit] 0
72			error_check_good txn_checkpt [$dbenv txn_checkpoint] 0
73		}
74		error_check_good db_close [$db($i) close] 0
75		set file $testdir/$testfile.afterop
76		catch { file copy -force $testdir/$testfile $file} res
77		copy_extent_file $testdir $testfile afterop
78	}
79	error_check_good env_close [$dbenv close] 0
80
81	# Now, loop through and recover to each timestamp, verifying the
82	# expected increment.
83	puts "\tRecd$tnum.c: Run recovery (no-op)"
84	set ret [catch {exec $util_path/db_recover -h $testdir} r]
85	error_check_good db_recover $ret 0
86
87	puts "\tRecd$tnum.d: Run recovery (initial file)"
88	for { set i 0 } {$i < $ndbs } { incr i } {
89		set testfile $tname.$i
90		set file $testdir/$testfile.init
91		catch { file copy -force $file $testdir/$testfile } res
92		move_file_extent $testdir $testfile init copy
93	}
94
95	set ret [catch {exec $util_path/db_recover -h $testdir} r]
96	error_check_good db_recover $ret 0
97
98	puts "\tRecd$tnum.e: Run recovery (after file)"
99	for { set i 0 } {$i < $ndbs } { incr i } {
100		set testfile $tname.$i
101		set file $testdir/$testfile.afterop
102		catch { file copy -force $file $testdir/$testfile } res
103		move_file_extent $testdir $testfile afterop copy
104	}
105
106	set ret [catch {exec $util_path/db_recover -h $testdir} r]
107	error_check_good db_recover $ret 0
108
109}
110