proc log006 { } {
source ./include.tcl
puts "Log006: Check auto-remove of log files."
env_cleanup $testdir
puts "\tLog006.a: open environment, populate database."
set env [berkdb_env_noerr -log_remove \
-create -home $testdir -log_buffer 10000 -log_max 100000 -txn]
error_check_good envopen [is_valid_env $env] TRUE
log006_put $testdir $env
set log_expect 12
puts "\tLog006.b: Check log files removed."
set lfiles [glob -nocomplain $testdir/log.*]
set remlen [llength $lfiles]
error_check_good lfiles_len [expr $remlen < $log_expect] 1
error_check_good lfiles [lsearch $lfiles $testdir/log.0000000001] -1
set oldfile [lindex [lsort -ascii $lfiles] end]
puts "\tLog006.c: Rerun put loop with long-lived transaction."
set txn [$env txn]
error_check_good txn [is_valid_txn $txn $env] TRUE
log006_put $testdir $env
puts "\tLog006.d: Check log files not removed."
set lfiles [glob -nocomplain $testdir/log.*]
error_check_good lfiles2_len [expr [llength $lfiles] > $remlen] 1
set lfiles [lsort -ascii $lfiles]
error_check_good lfiles_chk [lsearch $lfiles $oldfile] 0
error_check_good txn_commit [$txn commit] 0
error_check_good ckp1 [$env txn_checkpoint] 0
error_check_good ckp2 [$env txn_checkpoint] 0
puts "\tLog006.e: Run log_archive with -auto_remove flag."
set lfiles [glob -nocomplain $testdir/log.*]
set oldfile [lindex [lsort -ascii $lfiles] end]
foreach f {-arch_abs -arch_data -arch_log} {
set stat [catch {eval $env log_archive -arch_remove $f} ret]
error_check_good stat $stat 1
error_check_good la:$f:fail [is_substr $ret "illegal flag"] 1
}
set stat [catch {$env log_archive -arch_remove} ret]
error_check_good stat $stat 0
puts "\tLog006.f: Check only $oldfile remains."
set lfiles [glob -nocomplain $testdir/log.*]
error_check_good 1log [llength $lfiles] 1
error_check_good lfiles_chk [lsearch $lfiles $oldfile] 0
puts "\tLog006.g: Rerun put loop with long-lived transaction."
set txn [$env txn]
error_check_good txn [is_valid_txn $txn $env] TRUE
log006_put $testdir $env
error_check_good txn_commit [$txn commit] 0
error_check_good ckp1 [$env txn_checkpoint] 0
error_check_good ckp2 [$env txn_checkpoint] 0
error_check_good env_close [$env close] 0
puts "\tLog006.h: Run db_archive with delete flag."
set lfiles [glob -nocomplain $testdir/log.*]
set oldfile [lindex [lsort -ascii $lfiles] end]
foreach f {-a -l -s} {
set stat [catch {exec $util_path/db_archive $f -d -h $testdir} \
ret]
error_check_good stat $stat 1
error_check_good la:fail [is_substr $ret "illegal flag"] 1
}
set stat [catch {exec $util_path/db_archive -d -h $testdir} ret]
error_check_good stat $stat 0
puts "\tLog006.i: Check only $oldfile remains."
set lfiles [glob -nocomplain $testdir/log.*]
error_check_good 1log [llength $lfiles] 1
error_check_good lfiles_chk [lsearch $lfiles $oldfile] 0
env_cleanup $testdir
puts "\tLog006.j: open environment w/o auto remove, populate database."
set env [berkdb_env -recover \
-create -home $testdir -log_buffer 10000 -log_max 100000 -txn]
error_check_good envopen [is_valid_env $env] TRUE
log006_put $testdir $env
puts "\tLog006.k: Check log files not removed."
set lfiles [glob -nocomplain $testdir/log.*]
error_check_good lfiles2_len [expr [llength $lfiles] > $remlen] 1
set lfiles [lsort -ascii $lfiles]
error_check_good lfiles [lsearch $lfiles $testdir/log.0000000001] 0
puts "\tLog006.l: turn on auto remove and repopulate database."
error_check_good sf [$env set_flags -log_remove on] 0
log006_put $testdir $env
puts "\tLog006.m: Check log files removed."
set lfiles [glob -nocomplain $testdir/log.*]
error_check_good lfiles_len [expr [llength $lfiles] < $log_expect] 1
error_check_good lfiles [lsearch $lfiles $testdir/log.0000000001] -1
error_check_good env_close [$env close] 0
env_cleanup $testdir
puts "\tLog006.n: Test setting via DB_CONFIG."
set cid [open $testdir/DB_CONFIG w]
puts $cid "set_flags db_log_autoremove"
close $cid
set env [berkdb_env -recover \
-create -home $testdir -log_buffer 10000 -log_max 100000 -txn]
error_check_good envopen [is_valid_env $env] TRUE
log006_put $testdir $env
puts "\tLog006.o: Check log files removed."
set lfiles [glob -nocomplain $testdir/log.*]
error_check_good lfiles_len [expr [llength $lfiles] < $log_expect] 1
error_check_good lfiles [lsearch $lfiles $testdir/log.0000000001] -1
error_check_good env_close [$env close] 0
}
proc log006_put { testdir env } {
set testfile log006.db
set limit 100
cleanup $testdir $env
set db [eval {berkdb_open_noerr -create -mode 0644} \
-env $env -auto_commit -pagesize 8192 -btree $testfile]
error_check_good dbopen [is_valid_db $db] TRUE
set file_list [get_file_list]
if { [llength $file_list] > $limit } {
set file_list [lrange $file_list 1 $limit]
}
set len [llength $file_list]
set count 0
foreach f $file_list {
if { [string compare [file type $f] "file"] != 0 } {
continue
}
set key $f
set fid [open $f r]
fconfigure $fid -translation binary
set data [read $fid]
close $fid
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
set ret [eval {$db put} $txn {$key $data}]
error_check_good put $ret 0
error_check_good txn [$t commit] 0
if { $count % 10 == 0 } {
error_check_good ckp($count) [$env txn_checkpoint] 0
}
incr count
}
error_check_good db_close [$db close] 0
}