source ./include.tcl
source $test_path/test.tcl
source $test_path/testutils.tcl
set mypid [pid]
set usage "sysscript dir nfiles key_avg data_avg method"
if { $argc != 5 } {
puts stderr "FAIL:[timestamp] Usage: $usage"
exit
}
puts [concat "Argc: " $argc " Argv: " $argv]
set dir [lindex $argv 0]
set nfiles [ lindex $argv 1 ]
set key_avg [ lindex $argv 2 ]
set data_avg [ lindex $argv 3 ]
set method [ lindex $argv 4 ]
global rand_init
berkdb srand $rand_init
puts "Beginning execution for $mypid"
puts "$dir DB_HOME"
puts "$nfiles files"
puts "$key_avg average key length"
puts "$data_avg average data length"
flush stdout
set dbenv [berkdb_env -txn -home $dir]
set err [catch {error_check_good $mypid:dbenv [is_substr $dbenv env] 1} ret]
if {$err != 0} {
puts $ret
return
}
for { set i 0 } { $i < $nfiles } { incr i } {
set file test044.$i.db
set db($i) [berkdb open -auto_commit -env $dbenv $method $file]
set err [catch {error_check_bad $mypid:dbopen $db($i) NULL} ret]
if {$err != 0} {
puts $ret
return
}
set err [catch {error_check_bad $mypid:dbopen [is_substr $db($i) \
error] 1} ret]
if {$err != 0} {
puts $ret
return
}
}
set record_based [is_record_based $method]
while { 1 } {
if { [berkdb random_int 1 10] < 8 } {
set k [random_data 5 0 0 $record_based]
} else {
set k [random_data $key_avg 0 0 $record_based]
}
set data [chop_data $method [random_data $data_avg 0 0]]
set txn [$dbenv txn]
set err [catch {error_check_good $mypid:txn_begin [is_substr $txn \
$dbenv.txn] 1} ret]
if {$err != 0} {
puts $ret
return
}
for { set f 0 } {$f < $nfiles} {incr f} {
set cursors($f) [$db($f) cursor -txn $txn]
set err [catch {error_check_good $mypid:cursor_open \
[is_substr $cursors($f) $db($f)] 1} ret]
if {$err != 0} {
puts $ret
return
}
}
set aborted 0
set found 0
for { set i 0 } { $i < $nfiles } { incr i } {
set r [$db($i) get -txn $txn $k]
set r [$db($i) get -txn $txn $k]
if { $r == "-1" } {
for {set f 0 } {$f < $nfiles} {incr f} {
set err [catch {error_check_good \
$mypid:cursor_close \
[$cursors($f) close] 0} ret]
if {$err != 0} {
puts $ret
return
}
}
set err [catch {error_check_good $mypid:txn_abort \
[$txn abort] 0} ret]
if {$err != 0} {
puts $ret
return
}
set aborted 1
set found 2
break
} elseif { $r != "Key $k not found." } {
set found 1
break
}
}
switch $found {
2 {
}
0 {
set repl [berkdb random_int 1 $nfiles]
set fset ""
for { set i 0 } { $i < $repl } {incr i} {
set f [berkdb random_int 0 [expr $nfiles - 1]]
lappend fset $f
set data [chop_data $method $f:$data]
}
foreach i $fset {
set r [$db($i) put -txn $txn $k $data]
if {$r == "-1"} {
for {set f 0 } {$f < $nfiles} {incr f} {
set err [catch {error_check_good \
$mypid:cursor_close \
[$cursors($f) close] 0} ret]
if {$err != 0} {
puts $ret
return
}
}
set err [catch {error_check_good \
$mypid:txn_abort [$txn abort] 0} ret]
if {$err != 0} {
puts $ret
return
}
set aborted 1
break
}
}
}
1 {
set f [zero_list $nfiles]
set data $r
while { [set ndx [string first : $r]] != -1 } {
set fnum [string range $r 0 [expr $ndx - 1]]
if { [lindex $f $fnum] == 0 } {
set full [record $cursors($fnum) get -set $k]
} else {
set full [record $cursors($fnum) get -next]
}
if {[llength $full] == 0} {
for {set f 0 } {$f < $nfiles} {incr f} {
set err [catch {error_check_good \
$mypid:cursor_close \
[$cursors($f) close] 0} ret]
if {$err != 0} {
puts $ret
return
}
}
set err [catch {error_check_good \
$mypid:txn_abort [$txn abort] 0} ret]
if {$err != 0} {
puts $ret
return
}
set aborted 1
break
}
set err [catch {error_check_bad \
$mypid:curs_get($k,$data,$fnum,$flag) \
[string length $full] 0} ret]
if {$err != 0} {
puts $ret
return
}
set key [lindex [lindex $full 0] 0]
set rec [pad_data $method [lindex [lindex $full 0] 1]]
set err [catch {error_check_good \
$mypid:dbget_$fnum:key $key $k} ret]
if {$err != 0} {
puts $ret
return
}
set err [catch {error_check_good \
$mypid:dbget_$fnum:data($k) $rec $data} ret]
if {$err != 0} {
puts $ret
return
}
set f [lreplace $f $fnum $fnum 1]
incr ndx
set r [string range $r $ndx end]
}
}
}
if { $aborted == 0 } {
for {set f 0 } {$f < $nfiles} {incr f} {
set err [catch {error_check_good $mypid:cursor_close \
[$cursors($f) close] 0} ret]
if {$err != 0} {
puts $ret
return
}
}
set err [catch {error_check_good $mypid:commit [$txn commit] \
0} ret]
if {$err != 0} {
puts $ret
return
}
}
}
for { set i 0 } { $i < $nfiles} { incr i } {
set r [$db($i) close]
set err [catch {error_check_good $mypid:db_close:$i $r 0} ret]
if {$err != 0} {
puts $ret
return
}
}
$dbenv close
puts "[timestamp] [pid] Complete"
flush stdout
filecheck $file 0