~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/recd020.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 1996-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  recd020
9
 
# TEST  Test recovery after checksum error.
10
 
proc recd020 { method args} {
11
 
        global fixed_len
12
 
        global log_log_record_types
13
 
        global datastr
14
 
        source ./include.tcl
15
 
 
16
 
        set pgindex [lsearch -exact $args "-pagesize"]
17
 
        if { $pgindex != -1 } {
18
 
                puts "Recd020: skipping for specific pagesizes"
19
 
                return
20
 
        }
21
 
        if { [is_queueext $method] == 1 } {
22
 
                puts "Recd020: skipping for method $method"
23
 
                return
24
 
        }
25
 
 
26
 
        puts "Recd020: $method recovery after checksum error"
27
 
 
28
 
        # Create the database and environment.
29
 
        env_cleanup $testdir
30
 
 
31
 
        set testfile recd020.db
32
 
        set flags "-create -txn -home $testdir"
33
 
 
34
 
        puts "\tRecd020.a: creating environment"
35
 
        set env_cmd "berkdb_env $flags"
36
 
        set dbenv [eval $env_cmd]
37
 
        error_check_good dbenv [is_valid_env $dbenv] TRUE
38
 
 
39
 
        set pgsize 512
40
 
        set orig_fixed_len $fixed_len
41
 
        set fixed_len [expr $pgsize / 4]
42
 
        set opts [convert_args $method $args]
43
 
        set omethod [convert_method $method]
44
 
        set oflags "-create $omethod -mode 0644 \
45
 
            -auto_commit -chksum -pagesize $pgsize $opts $testfile"
46
 
        set db [eval {berkdb_open} -env $dbenv $oflags]
47
 
 
48
 
        #
49
 
        # Put some data.
50
 
        #
51
 
        set nument 50
52
 
        puts "\tRecd020.b: Put some data"
53
 
        for { set i 1 } { $i <= $nument } { incr i } {
54
 
                # Use 'i' as key so method doesn't matter
55
 
                set key $i
56
 
                set data $i$datastr
57
 
 
58
 
                # Put, in a txn.
59
 
                set txn [$dbenv txn]
60
 
                error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE
61
 
                error_check_good db_put \
62
 
                    [$db put -txn $txn $key [chop_data $method $data]] 0
63
 
                error_check_good txn_commit [$txn commit] 0
64
 
        }
65
 
        error_check_good db_close [$db close] 0
66
 
        error_check_good env_close [$dbenv close] 0
67
 
        #
68
 
        # We need to remove the env so that we don't get cached
69
 
        # pages.
70
 
        #
71
 
        error_check_good env_remove [berkdb envremove -home $testdir] 0
72
 
 
73
 
        puts "\tRecd020.c: Overwrite part of database"
74
 
        #
75
 
        # First just touch some bits in the file.  We want to go
76
 
        # through the paging system, so touch some data pages,
77
 
        # like the middle of page 2.
78
 
        # We should get a checksum error for the checksummed file.
79
 
        #
80
 
        set pg 2
81
 
        set fid [open $testdir/$testfile r+]
82
 
        fconfigure $fid -translation binary
83
 
        set seeklen [expr $pgsize * $pg + 200]
84
 
        seek $fid $seeklen start
85
 
        set byte [read $fid 1]
86
 
        binary scan $byte c val
87
 
        set newval [expr ~$val]
88
 
        set newbyte [binary format c $newval]
89
 
        seek $fid $seeklen start
90
 
        puts -nonewline $fid $newbyte
91
 
        close $fid
92
 
 
93
 
        #
94
 
        # Verify we get the checksum error.  When we get it, it should
95
 
        # log the error as well, so when we run recovery we'll need to
96
 
        # do catastrophic recovery.  We do this in a sub-process so that
97
 
        # the files are closed after the panic.
98
 
        #
99
 
        set f1 [open |$tclsh_path r+]
100
 
        puts $f1 "source $test_path/test.tcl"
101
 
 
102
 
        set env_cmd "berkdb_env_noerr $flags"
103
 
        set dbenv [send_cmd $f1 $env_cmd]
104
 
        error_check_good dbenv [is_valid_env $dbenv] TRUE
105
 
 
106
 
        set db [send_cmd $f1  "{berkdb_open_noerr} -env $dbenv $oflags"]
107
 
        error_check_good db [is_valid_db $db] TRUE
108
 
 
109
 
        # We need to set non-blocking mode so that after each command
110
 
        # we can read all the remaining output from that command and
111
 
        # we can know what the output from one command is.
112
 
        fconfigure $f1 -blocking 0
113
 
        set ret [read $f1]
114
 
        set got_err 0
115
 
        for { set i 1 } { $i <= $nument } { incr i } {
116
 
                set stat [send_cmd $f1  "catch {$db get $i} r"]
117
 
                set getret [send_cmd $f1  "puts \$r"]
118
 
                set ret [read $f1]
119
 
                if { $stat == 1 } {
120
 
                        error_check_good dbget:fail [is_substr $getret \
121
 
                            "checksum error: catastrophic recovery required"] 1
122
 
                        set got_err 1
123
 
                        # Now verify that it was an error on the page we set.
124
 
                        error_check_good dbget:pg$pg [is_substr $ret \
125
 
                            "failed for page $pg"] 1
126
 
                        break
127
 
                } else {
128
 
                        set key [lindex [lindex $getret 0] 0]
129
 
                        set data [lindex [lindex $getret 0] 1]
130
 
                        error_check_good keychk $key $i
131
 
                        error_check_good datachk $data \
132
 
                            [pad_data $method $i$datastr]
133
 
                }
134
 
        }
135
 
        error_check_good got_chksum $got_err 1
136
 
        set ret [send_cmd $f1  "$db close"]
137
 
        set extra [read $f1]
138
 
        error_check_good db:fail [is_substr $ret "run recovery"] 1
139
 
 
140
 
        set ret [send_cmd $f1  "$dbenv close"]
141
 
        error_check_good env_close:fail [is_substr $ret "run recovery"] 1
142
 
        close $f1
143
 
 
144
 
        # Keep track of the log types we've seen
145
 
        if { $log_log_record_types == 1} {
146
 
                logtrack_read $testdir
147
 
        }
148
 
 
149
 
        puts "\tRecd020.d: Run normal recovery"
150
 
        set ret [catch {exec $util_path/db_recover -h $testdir} r]
151
 
        error_check_good db_recover $ret 1
152
 
        error_check_good dbrec:fail \
153
 
            [is_substr $r "checksum error: catastrophic recovery required"] 1
154
 
 
155
 
        catch {fileremove $testdir/$testfile} ret
156
 
        puts "\tRecd020.e: Run catastrophic recovery"
157
 
        set ret [catch {exec $util_path/db_recover -c -h $testdir} r]
158
 
        error_check_good db_recover $ret 0
159
 
 
160
 
        #
161
 
        # Now verify the data was reconstructed correctly.
162
 
        #
163
 
        set env_cmd "berkdb_env_noerr $flags"
164
 
        set dbenv [eval $env_cmd]
165
 
        error_check_good dbenv [is_valid_env $dbenv] TRUE
166
 
 
167
 
        set db [eval {berkdb_open} -env $dbenv $oflags]
168
 
        error_check_good db [is_valid_db $db] TRUE
169
 
 
170
 
        for { set i 1 } { $i <= $nument } { incr i } {
171
 
                set stat [catch {$db get $i} ret]
172
 
                error_check_good stat $stat 0
173
 
                set key [lindex [lindex $ret 0] 0]
174
 
                set data [lindex [lindex $ret 0] 1]
175
 
                error_check_good keychk $key $i
176
 
                error_check_good datachk $data [pad_data $method $i$datastr]
177
 
        }
178
 
        error_check_good db_close [$db close] 0
179
 
        error_check_good env_close [$dbenv close] 0
180
 
}