1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996-2002
# Sleepycat Software. All rights reserved.
#
# $Id: txn002.tcl,v 1.1.1.1 2003/11/20 22:14:02 toshok Exp $
#
# TEST txn002
# TEST Verify that read-only transactions do not write log records.
proc txn002 { {tnum "02" } { max 1024 } { ntxns 50 } } {
source ./include.tcl
global txn_curid
global txn_maxid
puts -nonewline "Txn0$tnum: Read-only transaction test ($max) ($ntxns)"
if { $tnum != "02" } {
puts " (with ID wrap)"
} else {
puts ""
}
env_cleanup $testdir
set env [berkdb \
env -create -mode 0644 -txn -txn_max $max -home $testdir]
error_check_good dbenv [is_valid_env $env] TRUE
error_check_good txn_id_set \
[$env txn_id_set $txn_curid $txn_maxid ] 0
# Save the current bytes in the log.
set off_start [txn002_logoff $env]
# We will create a bunch of transactions and commit them.
set txn_list {}
set tid_list {}
puts "\tTxn0$tnum.a: Beginning/Committing Transactions"
for { set i 0 } { $i < $ntxns } { incr i } {
set txn [$env txn]
error_check_good txn_begin [is_valid_txn $txn $env] TRUE
lappend txn_list $txn
set tid [$txn id]
error_check_good tid_check [lsearch $tid_list $tid] -1
lappend tid_list $tid
}
foreach t $txn_list {
error_check_good txn_commit:$t [$t commit] 0
}
# Make sure we haven't written any new log records except
# potentially some recycle records if we were wrapping txnids.
set off_stop [txn002_logoff $env]
if { $off_stop != $off_start } {
txn002_recycle_only $testdir
}
error_check_good env_close [$env close] 0
}
proc txn002_logoff { env } {
set stat [$env log_stat]
foreach i $stat {
foreach {txt val} $i {break}
if { [string compare \
$txt {Current log file offset}] == 0 } {
return $val
}
}
}
# Make sure that the only log records found are txn_recycle records
proc txn002_recycle_only { dir } {
global util_path
set tmpfile $dir/printlog.out
set stat [catch {exec $util_path/db_printlog -h $dir > $tmpfile} ret]
error_check_good db_printlog $stat 0
set f [open $tmpfile r]
while { [gets $f record] >= 0 } {
set r [regexp {\[[^\]]*\]\[[^\]]*\]([^\:]*)\:} $record whl name]
if { $r == 1 } {
error_check_good record_type __txn_recycle $name
}
}
close $f
fileremove $tmpfile
}
|