1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST This is a recovery test for testing lots of prepared txns.
10
# TEST This test is to force the use of txn_recover to call with the
11
# TEST DB_FIRST flag and then DB_NEXT.
12
proc recd015 { method args } {
15
set args [convert_args $method $args]
16
set omethod [convert_method $method]
18
puts "Recd015: $method ($args) prepared txns test"
20
# Create the database and environment.
25
set env_cmd "berkdb_env -create -txn -home $testdir"
27
puts "$msg Simple test to prepare $numtxns txn "
28
foreach op { abort commit discard } {
30
recd015_body $env_cmd $testfile $numtxns $msg $op
34
# Now test large numbers of prepared txns to test DB_NEXT
38
set testfile recd015.db
39
set txnmax [expr $numtxns + 5]
41
# For this test we create our database ahead of time so that we
42
# don't need to send methods and args to the script.
45
set env_cmd "berkdb_env -create -txn_max $txnmax -txn -home $testdir"
46
set env [eval $env_cmd]
47
error_check_good dbenv [is_valid_env $env] TRUE
48
set db [eval {berkdb_open -create} $omethod -env $env $args $testfile]
49
error_check_good dbopen [is_valid_db $db] TRUE
50
error_check_good dbclose [$db close] 0
51
error_check_good envclose [$env close] 0
54
puts "$msg Large test to prepare $numtxns txn "
55
foreach op { abort commit discard } {
56
recd015_body $env_cmd $testfile $numtxns $msg $op
59
set stat [catch {exec $util_path/db_printlog -h $testdir \
61
error_check_good db_printlog $stat 0
62
fileremove $testdir/LOG
65
proc recd015_body { env_cmd testfile numtxns msg op } {
69
set gidf $testdir/gidfile
72
puts "$msg.0: Executing child script to prepare txns"
74
set p [exec $tclsh_path $test_path/wrap.tcl recd15scr.tcl \
75
$testdir/recdout $env_cmd $testfile $gidf $numtxns &]
78
watch_procs $pidlist 5
79
set f1 [open $testdir/recdout r]
83
fileremove -f $testdir/recdout
86
puts -nonewline "$msg.1: Running recovery ... "
89
set env [eval $env_cmd -recover]
90
error_check_good dbenv-recover [is_valid_env $env] TRUE
93
puts "$msg.2: getting txns from txn_recover"
94
set txnlist [$env txn_recover]
95
error_check_good txnlist_len [llength $txnlist] $numtxns
97
set gfd [open $gidf r]
99
while { [gets $gfd gid] != -1 } {
105
# Make sure we have as many as we expect
106
error_check_good num_gids $i $numtxns
109
puts "$msg.3: comparing GIDs and $op txns"
110
foreach tpair $txnlist {
111
set txn [lindex $tpair 0]
112
set gid [lindex $tpair 1]
113
error_check_good gidcompare $gid $gids($i)
114
error_check_good txn:$op [$txn $op] 0
117
if { $op != "discard" } {
118
error_check_good envclose [$env close] 0
122
# If we discarded, now do it again and randomly resolve some
123
# until all txns are resolved.
125
puts "$msg.4: resolving/discarding txns"
126
set txnlist [$env txn_recover]
127
set len [llength $txnlist]
130
set opval(2) "commit"
132
set opval(3) "discard"
134
while { $len != 0 } {
139
# Abort/commit or discard them randomly until
142
for { set i 0 } { $i < $len } { incr i } {
143
set t [lindex $txnlist $i]
144
set txn [lindex $t 0]
145
set newop [berkdb random_int 1 3]
146
set ret [$txn $opval($newop)]
147
error_check_good txn_$opval($newop):$i $ret 0
151
# puts "$opval(1): $opicnt(1) Total: $opcnt(1)"
152
# puts "$opval(2): $opicnt(2) Total: $opcnt(2)"
153
# puts "$opval(3): $opicnt(3) Total: $opcnt(3)"
155
set txnlist [$env txn_recover]
156
set len [llength $txnlist]
159
error_check_good envclose [$env close] 0