proc env012 { } {
source ./include.tcl
set tnum "012"
puts "Env$tnum: Test of DB_REGISTER."
puts "\tEnv$tnum.a: Platforms without fcntl fail with DB_OPNOTSUP."
env_cleanup $testdir
if {[catch {eval {berkdb_env} \
-create -home $testdir -txn -register -recover} env]} {
error_check_good fail_OPNOTSUP [is_substr $env DB_OPNOTSUP] 1
puts "Skipping env$tnum; DB_REGISTER is not supported."
}
error_check_good env_close [$env close] 0
puts "\tEnv$tnum.b: Second process can join with -register."
env_cleanup $testdir
set testfile TESTFILE
set key KEY
set data DATA1
puts "\t\tEnv$tnum.b1: Start process 1."
set p1 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p1 \
$testdir $testfile PUT $key $data RECOVER 10 &]
tclsleep 2
puts "\t\tEnv$tnum.b2: Start process 2."
set p2 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p2 \
$testdir $testfile GET $key $data 0 0 &]
watch_procs $p1 1 120
watch_procs $p2 1 120
logcheck $testdir/env$tnum.log.p1
logcheck $testdir/env$tnum.log.p2
puts "\tEnv$tnum.c: Second process can join with -register\
-recover after first process is killed."
env_cleanup $testdir
puts "\t\tEnv$tnum.c1: Start process 1."
set pids {}
set p1 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p1 \
$testdir $testfile PUT $key $data RECOVER 10 &]
lappend pids $p1
tclsleep 2
puts "\t\tEnv$tnum.c2: Kill process 1."
set pids [findprocessids $testdir $pids]
foreach pid $pids {
tclkill $pid
}
puts "\t\tEnv$tnum.c3: Start process 2."
set p2 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p2 \
$testdir $testfile GET $key $data RECOVER 0 &]
watch_procs $p2 1 120
logcheck $testdir/env$tnum.log.p1
logcheck $testdir/env$tnum.log.p2
if { $is_windows_test == 1 } {
puts "Skipping sections .d and .e on Windows platform."
} else {
puts "\tEnv$tnum.d: Second process cannot join without -recover\
after first process is killed."
env_cleanup $testdir
puts "\t\tEnv$tnum.d1: Start process 1."
set pids {}
set p1 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p1 \
$testdir $testfile PUT $key $data RECOVER 10 &]
lappend pids $p1
tclsleep 2
puts "\t\tEnv$tnum.d2: Kill process 1."
set pids [findprocessids $testdir $pids]
foreach pid $pids {
tclkill $pid
}
puts "\t\tEnv$tnum.d3: Start process 2."
set p2 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p2 \
$testdir $testfile GET $key $data 0 0 &]
tclsleep 2
watch_procs $p2 1 120
logcheck $testdir/env$tnum.log.p1
logcheckfails $testdir/env$tnum.log.p2 DB_RUNRECOVERY
puts "\tEnv$tnum.e: Running registered process detects failure."
env_cleanup $testdir
puts "\t\tEnv$tnum.e1: Start process 1."
set pids {}
set p1 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p1 \
$testdir $testfile PUT $key $data RECOVER 10 &]
lappend pids $p1
tclsleep 2
set pids [findprocessids $testdir $pids]
puts "\t\tEnv$tnum.e2: Start process 2."
set p2 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p2 \
$testdir $testfile LOOP $key $data 0 10 &]
puts "\t\tEnv$tnum.e3: Kill process 1."
foreach pid $pids {
tclkill $pid
}
puts "\t\tEnv$tnum.e4: Start process 3."
set p3 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p3 \
$testdir $testfile GET $key $data RECOVER 0 &]
tclsleep 2
watch_procs $p2 1 120
watch_procs $p3 1 120
logcheck $testdir/env$tnum.log.p1
logcheckfails $testdir/env$tnum.log.p2 DB_RUNRECOVERY
logcheck $testdir/env$tnum.log.p3
}
puts "\tEnv$tnum.f: Empty slot shouldn't cause automatic recovery."
puts "\t\tEnv$tnum.f1: Start process 1."
set p1 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p1 \
$testdir $testfile PUT $key $data RECOVER 1 &]
puts "\t\tEnv$tnum.f2: Start process 2."
set p2 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p2 \
$testdir $testfile GET $key $data 0 1 &]
watch_procs $p1 1 60
watch_procs $p2 1 60
logcheck $testdir/env$tnum.log.p1
logcheck $testdir/env$tnum.log.p2
puts "\t\tEnv$tnum.f3: Start process 3."
set p3 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p3 \
$testdir $testfile GET $key $data RECOVER 10 &]
tclsleep 2
puts "\t\tEnv$tnum.f4: Start process 4."
set p4 [exec $tclsh_path $test_path/wrap.tcl envscript.tcl \
$testdir/env$tnum.log.p4 \
$testdir $testfile PUT $key $data 0 10 &]
watch_procs $p3 1 120
watch_procs $p4 1 120
logcheck $testdir/env$tnum.log.p3
logcheck $testdir/env$tnum.log.p4
}
proc logcheck { logname } {
set errstrings [eval findfail $logname]
foreach errstring $errstrings {
puts "FAIL: error in $logname : $errstring"
}
}
proc logcheckfails { logname message } {
set f [open $logname r]
while { [gets $f line] >= 0 } {
if { [is_substr $line $message] == 1 } {
close $f
return 0
}
}
close $f
puts "FAIL: Did not find expected error $message."
}
proc findprocessids { testdir plist } {
set beginfiles [glob $testdir/begin.*]
foreach b $beginfiles {
regsub $testdir/begin. $b {} pid
if { [lsearch -exact $plist $pid] == -1 } {
lappend plist $pid
}
}
return $plist
}