~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/recd011.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 2000-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: recd011.tcl,v 11.14 2001/01/25 18:23:06 bostic Exp $
 
7
#
 
8
# Recovery Test 11.
 
9
# Test recovery to a specific timestamp.
 
10
proc recd011 { method {niter 200} {ckpt_freq 15} {sleep_time 1} args } {
 
11
        source ./include.tcl
 
12
 
 
13
        set args [convert_args $method $args]
 
14
        set omethod [convert_method $method]
 
15
        set tnum 11
 
16
 
 
17
        puts "Recd0$tnum ($args): Test recovery to a specific timestamp."
 
18
 
 
19
        set testfile recd0$tnum.db
 
20
        env_cleanup $testdir
 
21
 
 
22
        set i 0
 
23
        if { [is_record_based $method] == 1 } {
 
24
                set key 1
 
25
        } else {
 
26
                set key KEY
 
27
        }
 
28
 
 
29
        puts "\tRecd0$tnum.a: Create environment and database."
 
30
        set flags "-create -txn -home $testdir"
 
31
 
 
32
        set env_cmd "berkdb env $flags"
 
33
        set dbenv [eval $env_cmd]
 
34
        error_check_good dbenv [is_valid_env $dbenv] TRUE
 
35
 
 
36
        set oflags "-env $dbenv -create -mode 0644 $args $omethod"
 
37
        set db [eval {berkdb_open} $oflags $testfile]
 
38
        error_check_good dbopen [is_valid_db $db] TRUE
 
39
 
 
40
        # Main loop:  every second or so, increment the db in a txn.
 
41
        puts "\t\tInitial Checkpoint"
 
42
        error_check_good "Initial Checkpoint" [$dbenv txn_checkpoint] 0
 
43
 
 
44
        puts "\tRecd0$tnum.b ($niter iterations):\
 
45
            Transaction-protected increment loop."
 
46
        for { set i 0 } { $i <= $niter } { incr i } {
 
47
                set data $i
 
48
 
 
49
                # Put, in a txn.
 
50
                set txn [$dbenv txn]
 
51
                error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE
 
52
                error_check_good db_put \
 
53
                    [$db put -txn $txn $key [chop_data $method $data]] 0
 
54
                error_check_good txn_commit [$txn commit] 0
 
55
 
 
56
                set timeof($i) [timestamp -r]
 
57
 
 
58
                # If an appropriate period has elapsed, checkpoint.
 
59
                if { $i % $ckpt_freq == $ckpt_freq - 1 } {
 
60
                        puts "\t\tIteration $i: Checkpointing."
 
61
                        error_check_good ckpt($i) [$dbenv txn_checkpoint] 0
 
62
                }
 
63
 
 
64
                # sleep for N seconds.
 
65
                tclsleep $sleep_time
 
66
        }
 
67
        error_check_good db_close [$db close] 0
 
68
        error_check_good env_close [$dbenv close] 0
 
69
 
 
70
        # Now, loop through and recover to each timestamp, verifying the
 
71
        # expected increment.
 
72
        puts "\tRecd0$tnum.c: Recover to each timestamp and check."
 
73
        for { set i 0 } { $i <= $niter } { incr i } {
 
74
 
 
75
                # Run db_recover.
 
76
                berkdb debug_check
 
77
                set t [clock format $timeof($i) -format "%y%m%d%H%M.%S"]
 
78
                set ret [catch {exec $util_path/db_recover -h $testdir -t $t} r]
 
79
                error_check_good db_recover($i,$t) $ret 0
 
80
 
 
81
                # Now open the db and check the timestamp.
 
82
                set db [eval {berkdb_open} $testdir/$testfile]
 
83
                error_check_good db_open($i) [is_valid_db $db] TRUE
 
84
 
 
85
                set dbt [$db get $key]
 
86
                set datum [lindex [lindex $dbt 0] 1]
 
87
                error_check_good timestamp_recover $datum [pad_data $method $i]
 
88
 
 
89
                error_check_good db_close [$db close] 0
 
90
        }
 
91
 
 
92
        # Finally, recover to a time well before the first timestamp
 
93
        # and well after the last timestamp.  The latter should
 
94
        # be just like the last timestamp;  the former should fail.
 
95
        puts "\tRecd0$tnum.d: Recover to before the first timestamp."
 
96
        set t [clock format [expr $timeof(0) - 1000] -format "%y%m%d%H%M.%S"]
 
97
        set ret [catch {exec $util_path/db_recover -h $testdir -t $t} r]
 
98
        error_check_bad db_recover(before,$t) $ret 0
 
99
 
 
100
        puts "\tRecd0$tnum.e: Recover to after the last timestamp."
 
101
        set t [clock format \
 
102
            [expr $timeof($niter) + 1000] -format "%y%m%d%H%M.%S"]
 
103
        set ret [catch {exec $util_path/db_recover -h $testdir -t $t} r]
 
104
        error_check_good db_recover(after,$t) $ret 0
 
105
 
 
106
        # Now open the db and check the timestamp.
 
107
        set db [eval {berkdb_open} $testdir/$testfile]
 
108
        error_check_good db_open(after) [is_valid_db $db] TRUE
 
109
 
 
110
        set dbt [$db get $key]
 
111
        set datum [lindex [lindex $dbt 0] 1]
 
112
 
 
113
        error_check_good timestamp_recover $datum [pad_data $method $niter]
 
114
        error_check_good db_close [$db close] 0
 
115
}