1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: sdbutils.tcl,v 11.10 2001/01/25 18:23:08 bostic Exp $
8
proc build_all_subdb { dbname methods psize dups {nentries 100} {dbargs ""}} {
9
set nsubdbs [llength $dups]
10
set plen [llength $psize]
11
set mlen [llength $methods]
13
for {set i 0} {$i < $nsubdbs} { incr i } {
14
set m [lindex $methods [expr $i % $mlen]]
16
set p [lindex $psize [expr $i % $plen]]
17
subdb_build $dbname $nentries [lindex $dups $i] \
18
$i $m $p sub$i.db $dbargs
22
proc subdb_build { name nkeys ndups dup_interval method psize subdb dbargs} {
25
set dbargs [convert_args $method $dbargs]
26
set omethod [convert_method $method]
28
puts "Method: $method"
30
# Create the database and open the dictionary
31
set oflags "-create -mode 0644 $omethod \
32
-pagesize $psize $dbargs $name $subdb"
33
set db [eval {berkdb_open} $oflags]
34
error_check_good dbopen [is_valid_db $db] TRUE
38
puts "\tBuilding $method $name $subdb. \
39
$nkeys keys with $ndups duplicates at interval of $dup_interval"
42
puts "\tBuilding $method $name $subdb. \
43
$nkeys unique keys of pagesize $psize"
45
# If ndups is < 0, we want unique keys in each subdb,
46
# so skip ahead in the dict by nkeys * iteration
49
{ $count < [expr $nkeys * $dup_interval] } {
51
set ret [gets $did str]
57
for { set count 0 } { [gets $did str] != -1 && $count < $nkeys } {
59
for { set i 0 } { $i < $ndups } { incr i } {
60
set data [format "%04d" [expr $i * $dup_interval]]
61
set ret [$db put $str [chop_data $method $data]]
62
error_check_good put $ret 0
66
set ret [$db put $str [chop_data $method NODUP]]
67
error_check_good put $ret 0
68
} elseif { $ndups < 0 } {
69
if { [is_record_based $method] == 1 } {
72
set num [expr $nkeys * $dup_interval]
73
set num [expr $num + $count + 1]
74
set ret [$db put $num [chop_data $method $str]]
75
set kvals($num) [pad_data $method $str]
76
error_check_good put $ret 0
78
set ret [$db put $str [chop_data $method $str]]
79
error_check_good put $ret 0
84
error_check_good close:$name [$db close] 0
87
proc do_join_subdb { db primary subdbs key } {
90
puts "\tJoining: $subdbs on $key"
92
# Open all the databases
93
set p [berkdb_open -unknown $db $primary]
94
error_check_good "primary open" [is_valid_db $p] TRUE
100
set jdb [berkdb_open -unknown $db sub$i.db]
101
error_check_good "sub$i.db open" [is_valid_db $jdb] TRUE
103
lappend jlist [list $jdb $key]
108
set join_res [eval {$p get_join} $jlist]
109
set ndups [llength $join_res]
111
# Calculate how many dups we expect.
112
# We go through the list of indices. If we find a 0, then we
113
# expect 0 dups. For everything else, we look at pairs of numbers,
114
# if the are relatively prime, multiply them and figure out how
115
# many times that goes into 50. If they aren't relatively prime,
116
# take the number of times the larger goes into 50.
128
if { [expr $last % $n] == 0 || [expr $n % $last] == 0 } {
131
set expected [expr 50 / $last]
134
set last [expr $n * $last / [gcd $n $last]]
135
set expected [expr 50 / $last]
139
error_check_good number_of_dups:$subdbs $ndups $expected
142
# If we get here, we have the number expected, now loop
143
# through each and see if it is what we expected.
145
for { set i 0 } { $i < $ndups } { incr i } {
146
set pair [lindex $join_res $i]
147
set k [lindex $pair 0]
149
error_check_bad valid_dup:$j:$subdbs $j 0
150
set kval [string trimleft $k 0]
151
if { [string length $kval] == 0 } {
155
valid_dup:$j:$subdbs [expr $kval % $j] 0
159
error_check_good close_primary [$p close] 0
161
error_check_good close_index:$i [$i close] 0
165
proc n_to_subname { n } {