proc txn010 { } {
source ./include.tcl
puts "Txn010: test DB_ENV->txn_checkpoint arguments/flags."
env_cleanup $testdir
puts "\tTxn010.a: open the environment and a database, checkpoint."
set env [berkdb_env -create -home $testdir -txn]
error_check_good envopen [is_valid_env $env] TRUE
set db [berkdb_open \
-env $env -create -mode 0644 -btree -auto_commit a.db]
error_check_good dbopen [is_valid_db $db] TRUE
for { set count 0 } { $count < 100 } { incr count } {
set t [$env txn]
error_check_good "init: put" \
[$db put -txn $t "key_a_$count" "data"] 0
error_check_good "init: commit" [$t commit] 0
}
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint] 0
puts "\tTxn010.b: test for checkpoints when system is quiescent"
set chkpt [txn010_stat $env "Time of last checkpoint"]
for { set count 0 } { $count < 5 } {incr count } {
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "quiescent: checkpoint time changed" \
[expr $test_chkpt == $chkpt] 1
}
set chkpt [txn010_stat $env "Time of last checkpoint"]
set t [$env txn]
error_check_good \
"quiescent: put" [$db put -txn $t "key_b_$count" "data"] 0
error_check_good "quiescent: commit" [$t commit] 0
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "quiescent: checkpoint time unchanged" \
[expr $test_chkpt > $chkpt] 1
puts "\tTxn010.c: test checkpoint -force"
set chkpt [txn010_stat $env "Time of last checkpoint"]
for { set count 0 } { $count < 5 } {incr count } {
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint -force] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "force: checkpoint time unchanged" \
[expr $test_chkpt > $chkpt] 1
set chkpt $test_chkpt
}
puts "\tTxn010.d: test checkpoint -kbyte"
for { set count 0 } { $count < 1000 } { incr count } {
set t [$env txn]
error_check_good "kbyte: put" \
[$db put -txn $t "key_c_$count" "data"] 0
error_check_good "kbyte: commit" [$t commit] 0
}
set chkpt [txn010_stat $env "Time of last checkpoint"]
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint -kbyte 2] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "kbytes: checkpoint time unchanged" \
[expr $test_chkpt > $chkpt] 1
set chkpt [txn010_stat $env "Time of last checkpoint"]
for { set count 0 } { $count < 20 } { incr count } {
set t [$env txn]
error_check_good "kbyte: put" \
[$db put -txn $t "key_d_$count" "data"] 0
error_check_good "kbyte: commit" [$t commit] 0
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint -kbyte 20] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "kbytes: checkpoint time changed" \
[expr $test_chkpt == $chkpt] 1
}
puts "\tTxn010.e: test checkpoint -min"
set t [$env txn]
error_check_good "min: put" [$db put -txn $t "key_e_$count" "data"] 0
error_check_good "min: commit" [$t commit] 0
set chkpt [txn010_stat $env "Time of last checkpoint"]
for { set count 0 } { $count < 5 } {incr count } {
tclsleep 1
error_check_good checkpoint [$env txn_checkpoint -min 2] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "min: checkpoint time changed" \
[expr $test_chkpt == $chkpt] 1
}
set chkpt [txn010_stat $env "Time of last checkpoint"]
tclsleep 120
error_check_good checkpoint [$env txn_checkpoint -min 2] 0
set test_chkpt [txn010_stat $env "Time of last checkpoint"]
error_check_good "min: checkpoint time unchanged" \
[expr $test_chkpt > $chkpt] 1
error_check_good db_close [$db close] 0
error_check_good env_close [$env close] 0
}
proc txn010_stat { env s } {
set stat [$env txn_stat]
foreach statpair $stat {
set statmsg [lindex $statpair 0]
set statval [lindex $statpair 1]
if {[is_substr $statmsg $s] != 0} {
return $statval
}
}
puts "FAIL: Txn010: stat string $s not found"
return 0
}