1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2000-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: recd011.tcl,v 11.14 2001/01/25 18:23:06 bostic Exp $
9
# Test recovery to a specific timestamp.
10
proc recd011 { method {niter 200} {ckpt_freq 15} {sleep_time 1} args } {
13
set args [convert_args $method $args]
14
set omethod [convert_method $method]
17
puts "Recd0$tnum ($args): Test recovery to a specific timestamp."
19
set testfile recd0$tnum.db
23
if { [is_record_based $method] == 1 } {
29
puts "\tRecd0$tnum.a: Create environment and database."
30
set flags "-create -txn -home $testdir"
32
set env_cmd "berkdb env $flags"
33
set dbenv [eval $env_cmd]
34
error_check_good dbenv [is_valid_env $dbenv] TRUE
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
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
44
puts "\tRecd0$tnum.b ($niter iterations):\
45
Transaction-protected increment loop."
46
for { set i 0 } { $i <= $niter } { incr i } {
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
56
set timeof($i) [timestamp -r]
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
64
# sleep for N seconds.
67
error_check_good db_close [$db close] 0
68
error_check_good env_close [$dbenv close] 0
70
# Now, loop through and recover to each timestamp, verifying the
72
puts "\tRecd0$tnum.c: Recover to each timestamp and check."
73
for { set i 0 } { $i <= $niter } { incr i } {
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
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
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]
89
error_check_good db_close [$db close] 0
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
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
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
110
set dbt [$db get $key]
111
set datum [lindex [lindex $dbt 0] 1]
113
error_check_good timestamp_recover $datum [pad_data $method $niter]
114
error_check_good db_close [$db close] 0