1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Concurrent Data Store test (CDB)
11
# TEST Multiprocess DB test; verify that locking is working for the
12
# TEST concurrent access method product.
14
# TEST Use the first "nentries" words from the dictionary. Insert each with
15
# TEST self as key and a fixed, medium length data string. Then fire off
16
# TEST multiple processes that bang on the database. Each one should try to
17
# TEST read and write random keys. When they rewrite, they'll append their
18
# TEST pid to the data string (sometimes doing a rewrite sometimes doing a
19
# TEST partial put). Some will use cursors to traverse through a few keys
20
# TEST before finding one to write.
22
proc test042 { method {nentries 1000} args } {
26
# If we are using an env, then skip this test. It needs its own.
27
set eindex [lsearch -exact $args "-env"]
28
if { $eindex != -1 } {
30
set env [lindex $args $eindex]
31
puts "Test042 skipping for env $env"
35
set args [convert_args $method $args]
36
if { $encrypt != 0 } {
37
puts "Test042 skipping for security"
40
test042_body $method $nentries 0 $args
41
test042_body $method $nentries 1 $args
44
proc test042_body { method nentries alldb args } {
48
set eflag "-cdb -cdb_alldb"
52
puts "Test042: CDB Test ($eflag) $method $nentries"
54
# Set initial parameters
61
for { set i 0 } { $i < [llength $args] } {incr i} {
62
switch -regexp -- [lindex $args $i] {
63
-dir { incr i; set testdir [lindex $args $i] }
64
-iter { incr i; set iter [lindex $args $i] }
65
-procs { incr i; set procs [lindex $args $i] }
66
-exit { set do_exit 1 }
67
default { append oargs " " [lindex $args $i] }
71
# Create the database and open the dictionary
72
set testfile test042.db
79
set env [eval {berkdb_env -create} $eflag -home $testdir]
80
error_check_good dbenv [is_valid_env $env] TRUE
82
# Env is created, now set up database
83
test042_dbinit $env $nentries $method $oargs $testfile 0
85
for { set i 1 } {$i < $procs} {incr i} {
86
test042_dbinit $env $nentries $method $oargs \
91
# Remove old mpools and Open/create the lock and mpool regions
92
error_check_good env:close:$env [$env close] 0
93
set ret [berkdb envremove -home $testdir]
94
error_check_good env_remove $ret 0
96
set env [eval {berkdb_env -create} $eflag -home $testdir]
97
error_check_good dbenv [is_valid_widget $env env] TRUE
99
if { $do_exit == 1 } {
103
# Now spawn off processes
105
puts "\tTest042.b: forking off $procs children"
108
for { set i 0 } {$i < $procs} {incr i} {
114
puts "exec $tclsh_path $test_path/wrap.tcl \
115
mdbscript.tcl $testdir/test042.$i.log \
116
$method $testdir $tf $nentries $iter $i $procs &"
117
set p [exec $tclsh_path $test_path/wrap.tcl \
118
mdbscript.tcl $testdir/test042.$i.log $method \
119
$testdir $tf $nentries $iter $i $procs &]
122
puts "Test042: $procs independent processes now running"
125
# Check for test failure
126
set e [eval findfail [glob $testdir/test042.*.log]]
127
error_check_good "FAIL: error message(s) in log files" $e 0
129
# Test is done, blow away lock and mpool region
133
# If we are renumbering, then each time we delete an item, the number of
134
# items in the file is temporarily decreased, so the highest record numbers
135
# do not exist. To make sure this doesn't happen, we never generate the
136
# highest few record numbers as keys.
138
# For record-based methods, record numbers begin at 1, while for other keys,
139
# we begin at 0 to index into an array.
140
proc rand_key { method nkeys renum procs} {
142
return [berkdb random_int 1 [expr $nkeys - $procs]]
143
} elseif { [is_record_based $method] == 1 } {
144
return [berkdb random_int 1 $nkeys]
146
return [berkdb random_int 0 [expr $nkeys - 1]]
150
proc test042_dbinit { env nentries method oargs tf ext } {
154
set omethod [convert_method $method]
155
set db [eval {berkdb_open -env $env -create \
156
-mode 0644 $omethod} $oargs {$tf$ext}]
157
error_check_good dbopen [is_valid_db $db] TRUE
166
# Here is the loop where we put each key/data pair
167
puts "\tTest042.a: put loop $tf$ext"
168
while { [gets $did str] != -1 && $count < $nentries } {
169
if { [is_record_based $method] == 1 } {
170
set key [expr $count + 1]
174
set ret [eval {$db put} \
175
$txn $pflags {$key [chop_data $method $datastr]}]
176
error_check_good put:$db $ret 0
180
error_check_good close:$db [$db close] 0