Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / test / tcl / recd004.tcl
1 # See the file LICENSE for redistribution information.
2 #
3 # Copyright (c) 1996, 2012 Oracle and/or its affiliates.  All rights reserved.
4 #
5 # $Id$
6 #
7 # TEST  recd004
8 # TEST  Big key test where big key gets elevated to internal page.
9 proc recd004 { method {select 0} args } {
10         source ./include.tcl
11         global rand_init
12
13         set envargs ""
14         set zero_idx [lsearch -exact $args "-zero_log"]
15         if { $zero_idx != -1 } {
16                 set args [lreplace $args $zero_idx $zero_idx]
17                 set envargs "-zero_log"
18         }
19
20         set opts [convert_args $method $args]
21         set omethod [convert_method $method]
22
23         set pgindex [lsearch -exact $args "-pagesize"]
24         if { $pgindex != -1 } {
25                 puts "Recd004: skipping for specific pagesizes"
26                 return
27         }
28         if { [is_record_based $method] == 1 } {
29                 puts "Recd004 skipping for method $method"
30                 return
31         }
32         puts "Recd004: $method big-key on internal page recovery tests ($envargs)"
33
34         berkdb srand $rand_init
35
36         env_cleanup $testdir
37         set testfile recd004.db
38         set testfile2 recd004-2.db
39         set eflags "-create -txn wrnosync -home $testdir $envargs"
40         puts "\tRecd004.a: creating environment"
41         set env_cmd "berkdb_env $eflags"
42         set dbenv [eval $env_cmd]
43         error_check_bad dbenv $dbenv NULL
44
45         # Create the databases. We will use a small page size so that we
46         # elevate quickly
47         set oflags "-create -mode 0644 \
48             -auto_commit $omethod -env $dbenv $opts -pagesize 512 $testfile"
49         set db [eval {berkdb_open} $oflags]
50         error_check_bad db_open $db NULL
51         error_check_good db_open [is_substr $db db] 1
52         error_check_good db_close [$db close] 0
53         set oflags "-create -mode 0644 \
54             -auto_commit $omethod -env $dbenv $opts -pagesize 512 $testfile2"
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         reset_env $dbenv
60
61         # List of recovery tests: {CMD MSG} pairs
62         set slist {
63                 { {big_populate DB TXNID $n} "Recd004.b: big key elevation"}
64                 { {unpopulate DB TXNID 0} "Recd004.c: Remove keys"}
65         }
66
67         # If pages are 512 bytes, then adding 512 key/data pairs
68         # should be more than sufficient.
69         set n 512
70         foreach pair $slist {
71                 set cmd [subst [lindex $pair 0]]
72                 set msg [lindex $pair 1]
73                 if { $select != 0 } {
74                         set tag [lindex $msg 0]
75                         set tail [expr [string length $tag] - 2]
76                         set tag [string range $tag $tail $tail]
77                         if { [lsearch $select $tag] == -1 } {
78                                 continue
79                         }
80                 }
81                 op_recover abort \
82                     $testdir $env_cmd $testfile $cmd $msg $opts
83                 op_recover commit \
84                     $testdir $env_cmd $testfile $cmd $msg $opts
85                 #
86                 # Note that since prepare-discard ultimately aborts
87                 # the txn, it must come before prepare-commit.
88                 #
89                 op_recover prepare-abort $testdir $env_cmd $testfile2 \
90                         $cmd $msg $opts
91                 op_recover prepare-discard $testdir $env_cmd $testfile2 \
92                         $cmd $msg $opts
93                 op_recover prepare-commit $testdir $env_cmd $testfile2 \
94                         $cmd $msg $opts
95         }
96
97         puts "\tRecd004.d: Verify db_printlog can read logfile"
98         set tmpfile $testdir/printlog.out
99         set stat [catch {exec $util_path/db_printlog -h $testdir \
100             > $tmpfile} ret]
101         error_check_good db_printlog $stat 0
102         fileremove $tmpfile
103 }