1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
10
# TEST Test reader-only/writer process combinations; we use the access methods
14
# Multiple processes not supported by private memory so don't
15
# run memp003_body with -private.
18
memp003_body "-system_mem -shm_key 1"
21
proc memp003_body { flags } {
25
puts "Memp003: {$flags} Reader/Writer tests"
27
if { [mem_chk $flags] == 1 } {
37
# Create an environment that the two processes can share, with
39
set c [list 0 [expr $psize * 20 * 3] 3]
40
set dbenv [eval {berkdb_env \
41
-create -lock -home $testdir -cachesize $c} $flags]
42
error_check_good dbenv [is_valid_env $dbenv] TRUE
44
# First open and create the file.
45
set db [berkdb_open -env $dbenv -create -truncate \
46
-mode 0644 -pagesize $psize -btree $testfile]
47
error_check_good dbopen/RW [is_valid_db $db] TRUE
53
puts "\tMemp003.a: create database"
55
# Here is the loop where we put and get each key/data pair
56
while { [gets $did str] != -1 && $count < $nentries } {
59
set ret [eval {$db put} $txn {$str $str}]
60
error_check_good put $ret 0
62
set ret [eval {$db get} $txn {$str}]
63
error_check_good get $ret [list [list $str $str]]
68
error_check_good close [$db close] 0
70
# Now open the file for read-only
71
set db [berkdb_open -env $dbenv -rdonly $testfile]
72
error_check_good dbopen/RO [is_substr $db db] 1
74
puts "\tMemp003.b: verify a few keys"
75
# Read and verify a couple of keys; saving them to check later
77
for { set i 0 } { $i < 10 } { incr i } {
78
set ndx [berkdb random_int 0 [expr $nentries - 1]]
79
set key [lindex $keys $ndx]
80
if { [lsearch $testset $key] != -1 } {
85
# The remote process stuff is unhappy with
86
# zero-length keys; make sure we don't pick one.
87
if { [llength $key] == 0 } {
94
set ret [eval {$db get} $txn {$key}]
95
error_check_good get/RO $ret [list [list $key $key]]
98
puts "\tMemp003.c: retrieve and modify keys in remote process"
99
# Now open remote process where we will open the file RW
100
set f1 [open |$tclsh_path r+]
101
puts $f1 "source $test_path/test.tcl"
102
puts $f1 "flush stdout"
105
set c [concat "{" [list 0 [expr $psize * 20 * 3] 3] "}" ]
106
set remote_env [send_cmd $f1 \
107
"berkdb_env -create -lock -home $testdir -cachesize $c $flags"]
108
error_check_good remote_dbenv [is_valid_env $remote_env] TRUE
110
set remote_db [send_cmd $f1 "berkdb_open -env $remote_env $testfile"]
111
error_check_good remote_dbopen [is_valid_db $remote_db] TRUE
115
set ret [send_cmd $f1 "$remote_db get $k"]
116
error_check_good remote_get $ret [list [list $k $k]]
118
# Now replace the key
119
set ret [send_cmd $f1 "$remote_db put $k $k$k"]
120
error_check_good remote_put $ret 0
123
puts "\tMemp003.d: verify changes in local process"
125
set ret [eval {$db get} $txn {$key}]
126
error_check_good get_verify/RO $ret [list [list $key $key$key]]
129
puts "\tMemp003.e: Fill up the cache with dirty buffers"
131
# Now rewrite the keys with BIG data
132
set data [replicate $alphabet 32]
133
set ret [send_cmd $f1 "$remote_db put $k $data"]
134
error_check_good remote_put $ret 0
137
puts "\tMemp003.f: Get more pages for the read-only file"
138
dump_file $db $txn $t1 nop
140
puts "\tMemp003.g: Sync from the read-only file"
141
error_check_good db_sync [$db sync] 0
142
error_check_good db_close [$db close] 0
144
set ret [send_cmd $f1 "$remote_db close"]
145
error_check_good remote_get $ret 0
147
# Close the environment both remotely and locally.
148
set ret [send_cmd $f1 "$remote_env close"]
149
error_check_good remote:env_close $ret 0