1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
6
# $Id: sysscript.tcl,v 11.17 2002/07/29 17:05:24 sue Exp $
8
# System integration test script.
9
# This script runs a single process that tests the full functionality of
10
# the system. The database under test contains nfiles files. Each process
11
# randomly generates a key and some data. Both keys and data are bimodally
12
# distributed between small keys (1-10 characters) and large keys (the avg
13
# length is indicated via the command line parameter.
14
# The process then decides on a replication factor between 1 and nfiles.
15
# It writes the key and data to that many files and tacks on the file ids
16
# of the files it writes to the data string. For example, let's say that
17
# I randomly generate the key dog and data cat. Then I pick a replication
18
# factor of 3. I pick 3 files from the set of n (say 1, 3, and 5). I then
19
# rewrite the data as 1:3:5:cat. I begin a transaction, add the key/data
20
# pair to each file and then commit. Notice that I may generate replication
21
# of the form 1:3:3:cat in which case I simply add a duplicate to file 3.
23
# Usage: sysscript dir nfiles key_avg data_avg
25
# dir: DB_HOME directory
26
# nfiles: number of files in the set
27
# key_avg: average big key size
28
# data_avg: average big data size
31
source $test_path/test.tcl
32
source $test_path/testutils.tcl
36
set usage "sysscript dir nfiles key_avg data_avg method"
40
puts stderr "FAIL:[timestamp] Usage: $usage"
44
puts [concat "Argc: " $argc " Argv: " $argv]
46
# Initialize arguments
47
set dir [lindex $argv 0]
48
set nfiles [ lindex $argv 1 ]
49
set key_avg [ lindex $argv 2 ]
50
set data_avg [ lindex $argv 3 ]
51
set method [ lindex $argv 4 ]
55
berkdb srand $rand_init
57
puts "Beginning execution for $mypid"
60
puts "$key_avg average key length"
61
puts "$data_avg average data length"
65
# Create local environment
66
set dbenv [berkdb_env -txn -home $dir]
67
set err [catch {error_check_good $mypid:dbenv [is_substr $dbenv env] 1} ret]
74
for { set i 0 } { $i < $nfiles } { incr i } {
75
set file test044.$i.db
76
set db($i) [berkdb open -auto_commit -env $dbenv $method $file]
77
set err [catch {error_check_bad $mypid:dbopen $db($i) NULL} ret]
82
set err [catch {error_check_bad $mypid:dbopen [is_substr $db($i) \
90
set record_based [is_record_based $method]
92
# Decide if we're going to create a big key or a small key
93
# We give small keys a 70% chance.
94
if { [berkdb random_int 1 10] < 8 } {
95
set k [random_data 5 0 0 $record_based]
97
set k [random_data $key_avg 0 0 $record_based]
99
set data [chop_data $method [random_data $data_avg 0 0]]
102
set err [catch {error_check_good $mypid:txn_begin [is_substr $txn \
110
for { set f 0 } {$f < $nfiles} {incr f} {
111
set cursors($f) [$db($f) cursor -txn $txn]
112
set err [catch {error_check_good $mypid:cursor_open \
113
[is_substr $cursors($f) $db($f)] 1} ret]
121
# Check to see if key is already in database
123
for { set i 0 } { $i < $nfiles } { incr i } {
124
set r [$db($i) get -txn $txn $k]
125
set r [$db($i) get -txn $txn $k]
127
for {set f 0 } {$f < $nfiles} {incr f} {
128
set err [catch {error_check_good \
129
$mypid:cursor_close \
130
[$cursors($f) close] 0} ret]
136
set err [catch {error_check_good $mypid:txn_abort \
145
} elseif { $r != "Key $k not found." } {
152
# Transaction aborted, no need to do anything.
155
# Key was not found, decide how much to replicate
156
# and then create a list of that many file IDs.
157
set repl [berkdb random_int 1 $nfiles]
159
for { set i 0 } { $i < $repl } {incr i} {
160
set f [berkdb random_int 0 [expr $nfiles - 1]]
162
set data [chop_data $method $f:$data]
166
set r [$db($i) put -txn $txn $k $data]
168
for {set f 0 } {$f < $nfiles} {incr f} {
169
set err [catch {error_check_good \
170
$mypid:cursor_close \
171
[$cursors($f) close] 0} ret]
177
set err [catch {error_check_good \
178
$mypid:txn_abort [$txn abort] 0} ret]
189
# Key was found. Make sure that all the data values
191
set f [zero_list $nfiles]
193
while { [set ndx [string first : $r]] != -1 } {
194
set fnum [string range $r 0 [expr $ndx - 1]]
195
if { [lindex $f $fnum] == 0 } {
197
set full [record $cursors($fnum) get -set $k]
200
set full [record $cursors($fnum) get -next]
202
if {[llength $full] == 0} {
203
for {set f 0 } {$f < $nfiles} {incr f} {
204
set err [catch {error_check_good \
205
$mypid:cursor_close \
206
[$cursors($f) close] 0} ret]
212
set err [catch {error_check_good \
213
$mypid:txn_abort [$txn abort] 0} ret]
221
set err [catch {error_check_bad \
222
$mypid:curs_get($k,$data,$fnum,$flag) \
223
[string length $full] 0} ret]
228
set key [lindex [lindex $full 0] 0]
229
set rec [pad_data $method [lindex [lindex $full 0] 1]]
230
set err [catch {error_check_good \
231
$mypid:dbget_$fnum:key $key $k} ret]
236
set err [catch {error_check_good \
237
$mypid:dbget_$fnum:data($k) $rec $data} ret]
242
set f [lreplace $f $fnum $fnum 1]
244
set r [string range $r $ndx end]
248
if { $aborted == 0 } {
249
for {set f 0 } {$f < $nfiles} {incr f} {
250
set err [catch {error_check_good $mypid:cursor_close \
251
[$cursors($f) close] 0} ret]
257
set err [catch {error_check_good $mypid:commit [$txn commit] \
267
for { set i 0 } { $i < $nfiles} { incr i } {
268
set r [$db($i) close]
269
set err [catch {error_check_good $mypid:db_close:$i $r 0} ret]
276
# Close tm and environment
279
puts "[timestamp] [pid] Complete"