~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/sdbutils.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 1999-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
proc build_all_subdb { dbname methods psize dups {nentries 100} {dbargs ""}} {
9
 
        set nsubdbs [llength $dups]
10
 
        set mlen [llength $methods]
11
 
        set savearg $dbargs
12
 
        for {set i 0} {$i < $nsubdbs} { incr i } {
13
 
                set m [lindex $methods [expr $i % $mlen]]
14
 
                set dbargs $savearg
15
 
                subdb_build $dbname $nentries [lindex $dups $i] \
16
 
                    $i $m $psize sub$i.db $dbargs
17
 
        }
18
 
}
19
 
 
20
 
proc subdb_build { name nkeys ndups dup_interval method psize subdb dbargs} {
21
 
        source ./include.tcl
22
 
 
23
 
        set dbargs [convert_args $method $dbargs]
24
 
        set omethod [convert_method $method]
25
 
 
26
 
        puts "Method: $method"
27
 
 
28
 
        set txnenv 0
29
 
        set eindex [lsearch -exact $dbargs "-env"]
30
 
        if { $eindex != -1 } {
31
 
                incr eindex
32
 
                set env [lindex $dbargs $eindex]
33
 
                set txnenv [is_txnenv $env]
34
 
        }
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
40
 
        set did [open $dict]
41
 
        set count 0
42
 
        if { $ndups >= 0 } {
43
 
                puts "\tBuilding $method $name $subdb. \
44
 
        $nkeys keys with $ndups duplicates at interval of $dup_interval"
45
 
        }
46
 
        if { $ndups < 0 } {
47
 
                puts "\tBuilding $method $name $subdb. \
48
 
                    $nkeys unique keys of pagesize $psize"
49
 
                #
50
 
                # If ndups is < 0, we want unique keys in each subdb,
51
 
                # so skip ahead in the dict by nkeys * iteration
52
 
                #
53
 
                for { set count 0 } \
54
 
                    { $count < [expr $nkeys * $dup_interval] } {
55
 
                    incr count} {
56
 
                        set ret [gets $did str]
57
 
                        if { $ret == -1 } {
58
 
                                break
59
 
                        }
60
 
                }
61
 
        }
62
 
        set txn ""
63
 
        for { set count 0 } { [gets $did str] != -1 && $count < $nkeys } {
64
 
            incr count} {
65
 
                for { set i 0 } { $i < $ndups } { incr i } {
66
 
                        set data [format "%04d" [expr $i * $dup_interval]]
67
 
                        if { $txnenv == 1 } {
68
 
                                set t [$env txn]
69
 
                                error_check_good txn [is_valid_txn $t $env] TRUE
70
 
                                set txn "-txn $t"
71
 
                        }
72
 
                        set ret [eval {$db put} $txn {$str \
73
 
                            [chop_data $method $data]}]
74
 
                        error_check_good put $ret 0
75
 
                        if { $txnenv == 1 } {
76
 
                                error_check_good txn [$t commit] 0
77
 
                        }
78
 
                }
79
 
 
80
 
                if { $txnenv == 1 } {
81
 
                        set t [$env txn]
82
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
83
 
                        set txn "-txn $t"
84
 
                }
85
 
                if { $ndups == 0 } {
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 } {
91
 
                                global kvals
92
 
 
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
99
 
                        } else {
100
 
                                set ret [eval {$db put} $txn \
101
 
                                    {$str [chop_data $method $str]}]
102
 
                                error_check_good put $ret 0
103
 
                        }
104
 
                }
105
 
                if { $txnenv == 1 } {
106
 
                        error_check_good txn [$t commit] 0
107
 
                }
108
 
        }
109
 
        close $did
110
 
        error_check_good close:$name [$db close] 0
111
 
}
112
 
 
113
 
proc do_join_subdb { db primary subdbs key oargs } {
114
 
        source ./include.tcl
115
 
 
116
 
        puts "\tJoining: $subdbs on $key"
117
 
 
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
121
 
 
122
 
        set dblist ""
123
 
        set curslist ""
124
 
 
125
 
        foreach i $subdbs {
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
128
 
 
129
 
                lappend jlist [list $jdb $key]
130
 
                lappend dblist $jdb
131
 
 
132
 
        }
133
 
 
134
 
        set join_res [eval {$p get_join} $jlist]
135
 
        set ndups [llength $join_res]
136
 
 
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.
143
 
        set expected 50
144
 
        set last 1
145
 
        foreach n $subdbs {
146
 
                if { $n == 0 } {
147
 
                        set expected 0
148
 
                        break
149
 
                }
150
 
                if { $last == $n } {
151
 
                        continue
152
 
                }
153
 
 
154
 
                if { [expr $last % $n] == 0 || [expr $n % $last] == 0 } {
155
 
                        if { $n > $last } {
156
 
                                set last $n
157
 
                                set expected [expr 50 / $last]
158
 
                        }
159
 
                } else {
160
 
                        set last [expr $n * $last / [gcd $n $last]]
161
 
                        set expected [expr 50 / $last]
162
 
                }
163
 
        }
164
 
 
165
 
        error_check_good number_of_dups:$subdbs $ndups $expected
166
 
 
167
 
        #
168
 
        # If we get here, we have the number expected, now loop
169
 
        # through each and see if it is what we expected.
170
 
        #
171
 
        for { set i 0 } { $i < $ndups } { incr i } {
172
 
                set pair [lindex $join_res $i]
173
 
                set k [lindex $pair 0]
174
 
                foreach j $subdbs {
175
 
                        error_check_bad valid_dup:$j:$subdbs $j 0
176
 
                        set kval [string trimleft $k 0]
177
 
                        if { [string length $kval] == 0 } {
178
 
                                set kval 0
179
 
                        }
180
 
                        error_check_good \
181
 
                            valid_dup:$j:$subdbs [expr $kval % $j] 0
182
 
                }
183
 
        }
184
 
 
185
 
        error_check_good close_primary [$p close] 0
186
 
        foreach i $dblist {
187
 
                error_check_good close_index:$i [$i close] 0
188
 
        }
189
 
}
190
 
 
191
 
proc n_to_subname { n } {
192
 
        if { $n == 0 } {
193
 
                return null.db;
194
 
        } else {
195
 
                return sub$n.db;
196
 
        }
197
 
}