proc txn011 { {ntxns 100} } {
source ./include.tcl
global util_path
foreach envtype { "" "-private" } {
puts "Txn011: Non-durable txns ($envtype)."
env_cleanup $testdir
puts "\tTxn011.a: Persistent env recovery with -log_inmemory"
set lbuf [expr 8 * [expr 1024 * 1024]]
set env_cmd "berkdb_env -create \
-home $testdir -txn -log_inmemory -log_buffer $lbuf"
set ndenv [eval $env_cmd $envtype]
set db [berkdb_open -create -auto_commit \
-btree -env $ndenv -notdurable test.db]
check_log_records $testdir
error_check_good db_close [$db close] 0
error_check_good ndenv_close [$ndenv close] 0
set stat [catch {exec $util_path/db_recover -e -h $testdir} ret]
error_check_good db_printlog $stat 0
set ndenv [berkdb_env -home $testdir]
set db [berkdb_open -auto_commit -env $ndenv test.db]
error_check_good db_close [$db close] 0
error_check_good ndenv_close [$ndenv close] 0
env_cleanup $testdir
set ndenv [eval $env_cmd]
error_check_good env_open [is_valid_env $ndenv] TRUE
set testfile notdurable.db
set db [eval berkdb_open -create \
-auto_commit -env $ndenv -notdurable -btree $testfile]
error_check_good dbopen [is_valid_db $db] TRUE
puts "\tTxn011.b: Abort txns in in-memory logging env."
txn011_runtxns $ntxns $db $ndenv abort
txn011_check_empty $db $ndenv
puts "\tTxn011.c: Commit txns in in-memory logging env."
txn011_runtxns $ntxns $db $ndenv commit
check_log_records $testdir
error_check_good db_close [$db close] 0
error_check_good ndenv_close [$ndenv close] 0
env_cleanup $testdir
puts "\tTxn011.d: Set up mixed durable/non-durable test."
set mixed_env_cmd "berkdb_env_noerr -create \
-home $testdir -txn -log_inmemory -log_buffer $lbuf"
set env [eval $mixed_env_cmd]
error_check_good env_open [is_valid_env $env] TRUE
check_log_records $testdir
set nondurfile nondurable.db
set ndb [berkdb_open_noerr -create\
-auto_commit -env $env -btree -notdurable $nondurfile]
error_check_good dbopen [is_valid_db $ndb] TRUE
check_log_records $testdir
puts "\tTxn011.e: Abort txns in non-durable db."
txn011_runtxns $ntxns $ndb $env abort
txn011_check_empty $ndb $env
check_log_records $testdir
puts "\tTxn011.f: Commit txns in non-durable db."
txn011_runtxns $ntxns $ndb $env commit
check_log_records $testdir
set durfile durable.db
set ddb [eval berkdb_open_noerr \
-create -auto_commit -env $env -btree $durfile]
error_check_good dbopen [is_valid_db $ddb] TRUE
puts "\tTxn011.g: Try to get a not-durable handle on\
a durable db."
set errormsg "Cannot open DURABLE and NOT DURABLE handles"
catch {berkdb_open_noerr \
-auto_commit -env $env -notdurable $durfile} res
error_check_good handle_error1 [is_substr $res $errormsg] 1
error_check_good ddb_close [$ddb close] 0
catch {berkdb_open_noerr \
-auto_commit -env $env -notdurable $durfile} res
error_check_good handle_error2 [is_substr $res $errormsg] 1
set ddb [berkdb_open_noerr \
-auto_commit -env $env -btree $durfile]
error_check_good dbopen [is_valid_db $ddb] TRUE
puts "\tTxn011.h: Abort txns in durable db."
txn011_runtxns $ntxns $ddb $env abort
txn011_check_empty $ddb $env
puts "\tTxn011.i: Commit txns in durable db."
txn011_runtxns $ntxns $ddb $env commit
puts "\tTxn011.j: Subdbs must all be durable or all not durable."
set sdb1 [eval berkdb_open_noerr -create -auto_commit \
-env $env -btree testfile1.db subdb1]
catch {set sdb2 [eval berkdb_open_noerr -create -auto_commit \
-env $env -btree -notdurable testfile1.db subdb2]} res
error_check_good same_type_subdb1 [is_substr $res $errormsg] 1
error_check_good sdb1_close [$sdb1 close] 0
set sdb3 [eval berkdb_open_noerr -create -auto_commit \
-env $env -btree -notdurable testfile2.db subdb3]
catch {set sdb4 [eval berkdb_open_noerr -create -auto_commit \
-env $env -btree testfile2.db subdb4]} res
error_check_good same_type_subdb2 [is_substr $res $errormsg] 1
error_check_good sdb3_close [$sdb3 close] 0
puts "\tTxn011.k: Try to get a durable handle on a\
not-durable db."
catch {berkdb_open_noerr -auto_commit -env $env $nondurfile} res
error_check_good handle_error [is_substr $res $errormsg] 1
error_check_good ndb_close [$ndb close] 0
catch {berkdb_open_noerr -auto_commit -env $env $nondurfile} res
error_check_good handle_error [is_substr $res $errormsg] 1
error_check_good ddb_close [$ddb close] 0
error_check_good env_close [$env close] 0
}
}
proc txn011_runtxns { ntxns db env end } {
source ./include.tcl
set did [open $dict]
set i 0
while { [gets $did str] != -1 && $i < $ntxns } {
set txn [$env txn]
error_check_good txn_begin [is_valid_txn $txn $env] TRUE
error_check_good db_put_txn [$db put -txn $txn $i $str] 0
error_check_good txn_$end [$txn $end] 0
incr i
}
close $did
}
proc txn011_check_empty { db env } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
set dbc [eval {$db cursor} $txn]
error_check_good db_cursor [is_substr $dbc $db] 1
set ret [$dbc get -first]
error_check_good get_on_empty [string length $ret] 0
error_check_good dbc_close [$dbc close] 0
error_check_good txn [$t commit] 0
}
proc check_log_records { 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 && [string match *_debug $name] != 1 && \
[string match __txn_regop $name] != 1 && \
[string match __txn_child $name] != 1 } {
puts "FAIL: unexpected log record $name found"
}
}
close $f
fileremove $tmpfile
}