1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
8
proc build_all_subdb { dbname methods psize dups {nentries 100} {dbargs ""}} {
9
set nsubdbs [llength $dups]
10
set mlen [llength $methods]
12
for {set i 0} {$i < $nsubdbs} { incr i } {
13
set m [lindex $methods [expr $i % $mlen]]
15
subdb_build $dbname $nentries [lindex $dups $i] \
16
$i $m $psize sub$i.db $dbargs
20
proc subdb_build { name nkeys ndups dup_interval method psize subdb dbargs} {
23
set dbargs [convert_args $method $dbargs]
24
set omethod [convert_method $method]
26
puts "Method: $method"
29
set eindex [lsearch -exact $dbargs "-env"]
30
if { $eindex != -1 } {
32
set env [lindex $dbargs $eindex]
33
set txnenv [is_txnenv $env]
35
# Create the database and open the dictionary
36
set oflags "-create -mode 0644 $omethod \
37
-pagesize $psize $dbargs $name $subdb"
38
set db [eval {berkdb_open} $oflags]
39
error_check_good dbopen [is_valid_db $db] TRUE
43
puts "\tBuilding $method $name $subdb. \
44
$nkeys keys with $ndups duplicates at interval of $dup_interval"
47
puts "\tBuilding $method $name $subdb. \
48
$nkeys unique keys of pagesize $psize"
50
# If ndups is < 0, we want unique keys in each subdb,
51
# so skip ahead in the dict by nkeys * iteration
54
{ $count < [expr $nkeys * $dup_interval] } {
56
set ret [gets $did str]
63
for { set count 0 } { [gets $did str] != -1 && $count < $nkeys } {
65
for { set i 0 } { $i < $ndups } { incr i } {
66
set data [format "%04d" [expr $i * $dup_interval]]
69
error_check_good txn [is_valid_txn $t $env] TRUE
72
set ret [eval {$db put} $txn {$str \
73
[chop_data $method $data]}]
74
error_check_good put $ret 0
76
error_check_good txn [$t commit] 0
82
error_check_good txn [is_valid_txn $t $env] TRUE
86
set ret [eval {$db put} $txn {$str \
87
[chop_data $method NODUP]}]
88
error_check_good put $ret 0
89
} elseif { $ndups < 0 } {
90
if { [is_record_based $method] == 1 } {
93
set num [expr $nkeys * $dup_interval]
94
set num [expr $num + $count + 1]
95
set ret [eval {$db put} $txn {$num \
96
[chop_data $method $str]}]
97
set kvals($num) [pad_data $method $str]
98
error_check_good put $ret 0
100
set ret [eval {$db put} $txn \
101
{$str [chop_data $method $str]}]
102
error_check_good put $ret 0
105
if { $txnenv == 1 } {
106
error_check_good txn [$t commit] 0
110
error_check_good close:$name [$db close] 0
113
proc do_join_subdb { db primary subdbs key oargs } {
116
puts "\tJoining: $subdbs on $key"
118
# Open all the databases
119
set p [eval {berkdb_open -unknown} $oargs $db $primary]
120
error_check_good "primary open" [is_valid_db $p] TRUE
126
set jdb [eval {berkdb_open -unknown} $oargs $db sub$i.db]
127
error_check_good "sub$i.db open" [is_valid_db $jdb] TRUE
129
lappend jlist [list $jdb $key]
134
set join_res [eval {$p get_join} $jlist]
135
set ndups [llength $join_res]
137
# Calculate how many dups we expect.
138
# We go through the list of indices. If we find a 0, then we
139
# expect 0 dups. For everything else, we look at pairs of numbers,
140
# if the are relatively prime, multiply them and figure out how
141
# many times that goes into 50. If they aren't relatively prime,
142
# take the number of times the larger goes into 50.
154
if { [expr $last % $n] == 0 || [expr $n % $last] == 0 } {
157
set expected [expr 50 / $last]
160
set last [expr $n * $last / [gcd $n $last]]
161
set expected [expr 50 / $last]
165
error_check_good number_of_dups:$subdbs $ndups $expected
168
# If we get here, we have the number expected, now loop
169
# through each and see if it is what we expected.
171
for { set i 0 } { $i < $ndups } { incr i } {
172
set pair [lindex $join_res $i]
173
set k [lindex $pair 0]
175
error_check_bad valid_dup:$j:$subdbs $j 0
176
set kval [string trimleft $k 0]
177
if { [string length $kval] == 0 } {
181
valid_dup:$j:$subdbs [expr $kval % $j] 0
185
error_check_good close_primary [$p close] 0
187
error_check_good close_index:$i [$i close] 0
191
proc n_to_subname { n } {