1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: sdbtest002.tcl,v 11.20 2001/01/25 18:23:08 bostic Exp $
8
# Sub DB All-Method Test 2
9
# Make several subdb's of different access methods all in one DB.
10
# Fork of some child procs to each manipulate one subdb and when
11
# they are finished, verify the contents of the databases.
12
# Use the first 10,000 entries from the dictionary.
13
# Insert each with self as key and data; retrieve each.
14
# After all are entered, retrieve all; compare output to original.
15
# Close file, reopen, do retrieve and re-verify.
16
proc subdbtest002 { {nentries 10000} } {
19
puts "Subdbtest002: many different subdb access methods in one"
21
# Create the database and open the dictionary
22
set testfile $testdir/subdbtest002.db
31
# Set up various methods to rotate through
33
[list "-rbtree" "-recno" "-btree" "-btree" "-recno" "-rbtree"]
35
puts "\tSubdbtest002.a: create subdbs of different access methods:"
38
set nsubdbs [llength $methods]
40
for { set i 0 } { $i < $nsubdbs } { incr i } {
43
set newent [expr $nentries / $nsubdbs]
46
# XXX We need dict sorted to figure out what was deleted
47
# since things are stored sorted in the btree.
53
build_all_subdb $testfile $methods $psize $duplist $newent
55
# Now we will get each key from the DB and compare the results
58
puts "\tSubdbtest002.b: create $nsubdbs procs to delete some keys"
59
for { set subdb 0 } { $subdb < $nsubdbs } { incr subdb } {
61
$test_path/sdbscript.tcl $testfile \
62
$subdb $nsubdbs >& $testdir/subdb002.log.$subdb"
63
set p [exec $tclsh_path $test_path/wrap.tcl \
65
$testdir/subdb002.log.$subdb $testfile $subdb $nsubdbs &]
70
for { set subdb 0 } { $subdb < $nsubdbs } { incr subdb } {
71
set method [lindex $methods $subdb]
72
set method [convert_method $method]
73
if { [is_record_based $method] == 1 } {
74
set checkfunc subdbtest002_recno.check
76
set checkfunc subdbtest002.check
79
puts "\tSubdbtest002.b: dump file sub$subdb.db"
80
set db [berkdb_open -unknown $testfile sub$subdb.db]
81
error_check_good db_open [is_valid_db $db] TRUE
82
dump_file $db $txn $t1 $checkfunc
83
error_check_good db_close [$db close] 0
85
# This is just so that t2 is there and empty
86
# since we are only appending below.
90
# Now compare the keys to see if they match the dictionary (or ints)
91
if { [is_record_based $method] == 1 } {
93
for {set i 1} {$i <= $newent} {incr i} {
94
set x [expr $i - $subdb]
95
if { [expr $x % $nsubdbs] != 0 } {
96
puts $oid [expr $subdb * $newent + $i]
100
file rename -force $t1 $t3
103
for {set i 1} {[gets $oid line] >= 0} {incr i} {
109
for {set i 1} {$i <= $newent} {incr i} {
110
# Sed uses 1-based line numbers
111
set x [expr $i - $subdb]
112
if { [expr $x % $nsubdbs] != 0 } {
113
set beg [expr $subdb * $newent]
114
set beg [expr $beg + $i]
115
puts $oid $farr($beg)
122
error_check_good Subdbtest002:diff($t3,$t2) \
125
puts "\tSubdbtest002.c: sub$subdb.db: close, open, and dump file"
126
# Now, reopen the file and run the last test again.
127
open_and_dump_subfile $testfile NULL $txn $t1 $checkfunc \
128
dump_file_direction "-first" "-next" sub$subdb.db
129
if { [string compare $method "-recno"] != 0 } {
133
error_check_good Subdbtest002:diff($t2,$t3) \
136
# Now, reopen the file and run the last test again in the
138
puts "\tSubdbtest002.d: sub$subdb.db: close, open, and dump file in reverse direction"
139
open_and_dump_subfile $testfile NULL $txn $t1 $checkfunc \
140
dump_file_direction "-last" "-prev" sub$subdb.db
142
if { [string compare $method "-recno"] != 0 } {
146
error_check_good Subdbtest002:diff($t3,$t2) \
153
# Check function for Subdbtest002; keys and data are identical
154
proc subdbtest002.check { key data } {
155
error_check_good "key/data mismatch" $data $key
158
proc subdbtest002_recno.check { key data } {
161
error_check_good key"$key"_exists [info exists kvals($key)] 1
162
error_check_good "key/data mismatch, key $key" $data $kvals($key)