~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/sindex.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: sindex.tcl,v 1.3 2001/05/19 01:04:00 krinsky Exp $
 
7
#
 
8
# Secondary index test driver and maintenance routines.
 
9
#
 
10
# Breaking from the usual convention, we put the driver function
 
11
# for the secondary index tests here, in its own file.  The reason
 
12
# for this is that it's something which compartmentalizes nicely,
 
13
# has little in common with other driver functions, and
 
14
# is likely to be run on its own from time to time.
 
15
#
 
16
# The secondary index tests themselves live in si0*.tcl.
 
17
 
 
18
# Standard number of secondary indices to create if a single-element
 
19
# list of methods is passed into the secondary index tests.
 
20
global nsecondaries
 
21
set nsecondaries 2
 
22
 
 
23
# Run the secondary index tests.
 
24
proc sindex { {verbose 1} args } {
 
25
        global verbose_check_secondaries
 
26
        set verbose_check_secondaries $verbose
 
27
 
 
28
        # Run basic tests with a single secondary index and a small number
 
29
        # of keys, then again with a larger number of keys.  (Note that
 
30
        # we can't go above 5000, since we use two items from our
 
31
        # 10K-word list for each key/data pair.)
 
32
        foreach n { 200 5000 } {
 
33
                foreach pm { btree hash recno frecno queue queueext } {
 
34
                        foreach sm { dbtree dhash ddbtree ddhash btree hash } {
 
35
                                sindex001 [list $pm $sm $sm] $n
 
36
                                sindex002 [list $pm $sm $sm] $n
 
37
                                # Skip tests 3 & 4 for large lists;
 
38
                                # they're not that interesting.
 
39
                                if { $n < 1000 } {
 
40
                                        sindex003 [list $pm $sm $sm] $n
 
41
                                        sindex004 [list $pm $sm $sm] $n
 
42
                                }
 
43
                        }
 
44
                }
 
45
        }
 
46
 
 
47
        # Run secondary index join test.  (There's no point in running
 
48
        # this with both lengths, the primary is unhappy for now with fixed-
 
49
        # length records (XXX), and we need unsorted dups in the secondaries.)
 
50
        foreach pm { btree hash recno } {
 
51
                foreach sm { btree hash } {
 
52
                        sindex005 [list $pm $sm $sm] 1000
 
53
                }
 
54
                sindex005 [list $pm btree hash] 1000
 
55
                sindex005 [list $pm hash btree] 1000
 
56
        }
 
57
 
 
58
 
 
59
        # Run test with 50 secondaries.
 
60
        foreach pm { btree hash } {
 
61
                set methlist [list $pm]
 
62
                for { set i 0 } { $i < 50 } { incr i } {
 
63
                        # XXX this should incorporate hash after #3726
 
64
                        if { $i % 2 == 0 } {
 
65
                                lappend methlist "dbtree"
 
66
                        } else {
 
67
                                lappend methlist "ddbtree"
 
68
                        }
 
69
                }
 
70
                sindex001 $methlist 500
 
71
                sindex002 $methlist 500
 
72
                sindex003 $methlist 500
 
73
                sindex004 $methlist 500
 
74
        }
 
75
}
 
76
 
 
77
# The callback function we use for each given secondary in most tests
 
78
# is a simple function of its place in the list of secondaries (0-based)
 
79
# and the access method (since recnos may need different callbacks).
 
80
#
 
81
# !!!
 
82
# Note that callbacks 0-3 return unique secondary keys if the input data
 
83
# are unique;  callbacks 4 and higher may not, so don't use them with
 
84
# the normal wordlist and secondaries that don't support dups.
 
85
# The callbacks that incorporate a key don't work properly with recno
 
86
# access methods, at least not in the current test framework (the
 
87
# error_check_good lines test for e.g. 1foo, when the database has
 
88
# e.g. 0x010x000x000x00foo).
 
89
proc callback_n { n } {
 
90
        switch $n {
 
91
                0 { return _s_reversedata }
 
92
                1 { return _s_noop }
 
93
                2 { return _s_concatkeydata }
 
94
                3 { return _s_concatdatakey }
 
95
                4 { return _s_reverseconcat }
 
96
                5 { return _s_truncdata }
 
97
                6 { return _s_alwayscocacola }
 
98
        }
 
99
        return _s_noop
 
100
}
 
101
 
 
102
proc _s_reversedata { a b } { return [reverse $b] }
 
103
proc _s_truncdata { a b } { return [string range $b 1 end] }
 
104
proc _s_concatkeydata { a b } { return $a$b }
 
105
proc _s_concatdatakey { a b } { return $b$a }
 
106
proc _s_reverseconcat { a b } { return [reverse $a$b] }
 
107
proc _s_alwayscocacola { a b } { return "Coca-Cola" }
 
108
proc _s_noop { a b } { return $b }
 
109
 
 
110
# Should the check_secondary routines print lots of output?
 
111
set verbose_check_secondaries 0
 
112
 
 
113
# Given a primary database handle, a list of secondary handles, a
 
114
# number of entries, and arrays of keys and data, verify that all
 
115
# databases have what they ought to.
 
116
proc check_secondaries { pdb sdbs nentries keyarr dataarr {pref "Check"} } {
 
117
        upvar $keyarr keys
 
118
        upvar $dataarr data
 
119
        global verbose_check_secondaries
 
120
 
 
121
        # Make sure each key/data pair is in the primary.
 
122
        if { $verbose_check_secondaries } {
 
123
                puts "\t\t$pref.1: Each key/data pair is in the primary"
 
124
        }
 
125
        for { set i 0 } { $i < $nentries } { incr i } {
 
126
                error_check_good pdb_get($i) [$pdb get $keys($i)] \
 
127
                    [list [list $keys($i) $data($i)]]
 
128
        }
 
129
 
 
130
        for { set j 0 } { $j < [llength $sdbs] } { incr j } {
 
131
                # Make sure each key/data pair is in this secondary.
 
132
                if { $verbose_check_secondaries } {
 
133
                        puts "\t\t$pref.2:\
 
134
                            Each skey/key/data tuple is in secondary #$j"
 
135
                }
 
136
                for { set i 0 } { $i < $nentries } { incr i } {
 
137
                        set sdb [lindex $sdbs $j]
 
138
                        set skey [[callback_n $j] $keys($i) $data($i)]
 
139
                        error_check_good sdb($j)_pget($i) \
 
140
                            [$sdb pget -get_both $skey $keys($i)] \
 
141
                            [list [list $skey $keys($i) $data($i)]]
 
142
                }
 
143
 
 
144
                # Make sure this secondary contains only $nentries
 
145
                # items.
 
146
                if { $verbose_check_secondaries } {
 
147
                        puts "\t\t$pref.3: Secondary #$j has $nentries items"
 
148
                }
 
149
                set dbc [$sdb cursor]
 
150
                error_check_good dbc($i) \
 
151
                    [is_valid_cursor $dbc $sdb] TRUE
 
152
                for { set k 0 } { [llength [$dbc get -next]] > 0 } \
 
153
                    { incr k } { }
 
154
                error_check_good numitems($i) $k $nentries
 
155
                error_check_good dbc($i)_close [$dbc close] 0
 
156
        }
 
157
 
 
158
        if { $verbose_check_secondaries } {
 
159
                puts "\t\t$pref.4: Primary has $nentries items"
 
160
        }
 
161
        set dbc [$pdb cursor]
 
162
        error_check_good pdbc [is_valid_cursor $dbc $pdb] TRUE
 
163
        for { set k 0 } { [llength [$dbc get -next]] > 0 } { incr k } { }
 
164
        error_check_good numitems $k $nentries
 
165
        error_check_good pdbc_close [$dbc close] 0
 
166
}
 
167
 
 
168
# Given a primary database handle and a list of secondary handles, walk
 
169
# through the primary and make sure all the secondaries are correct,
 
170
# then walk through the secondaries and make sure the primary is correct.
 
171
#
 
172
# This is slightly less rigorous than the normal check_secondaries--we
 
173
# use it whenever we don't have up-to-date "keys" and "data" arrays.
 
174
proc cursor_check_secondaries { pdb sdbs nentries { pref "Check" } } {
 
175
        global verbose_check_secondaries
 
176
 
 
177
        # Make sure each key/data pair in the primary is in each secondary.
 
178
        set pdbc [$pdb cursor]
 
179
        error_check_good ccs_pdbc [is_valid_cursor $pdbc $pdb] TRUE
 
180
        set i 0
 
181
        if { $verbose_check_secondaries } {
 
182
                puts "\t\t$pref.1:\
 
183
                    Key/data in primary => key/data in secondaries"
 
184
        }
 
185
 
 
186
        for { set dbt [$pdbc get -first] } { [llength $dbt] > 0 } \
 
187
            { set dbt [$pdbc get -next] } {
 
188
                incr i
 
189
                set pkey [lindex [lindex $dbt 0] 0]
 
190
                set pdata [lindex [lindex $dbt 0] 1]
 
191
                for { set j 0 } { $j < [llength $sdbs] } { incr j } {
 
192
                        set sdb [lindex $sdbs $j]
 
193
                        set sdbt [$sdb pget -get_both \
 
194
                            [[callback_n $j] $pkey $pdata] $pkey]
 
195
                        error_check_good pkey($pkey,$j) \
 
196
                            [lindex [lindex $sdbt 0] 1] $pkey
 
197
                        error_check_good pdata($pdata,$j) \
 
198
                            [lindex [lindex $sdbt 0] 2] $pdata
 
199
                }
 
200
        }
 
201
        error_check_good ccs_pdbc_close [$pdbc close] 0
 
202
        error_check_good primary_has_nentries $i $nentries
 
203
 
 
204
        for { set j 0 } { $j < [llength $sdbs] } { incr j } {
 
205
                if { $verbose_check_secondaries } {
 
206
                        puts "\t\t$pref.2:\
 
207
                            Key/data in secondary #$j => key/data in primary"
 
208
                }
 
209
                set sdb [lindex $sdbs $j]
 
210
                set sdbc [$sdb cursor]
 
211
                error_check_good ccs_sdbc($j) [is_valid_cursor $sdbc $sdb] TRUE
 
212
                set i 0
 
213
                for { set dbt [$sdbc pget -first] } { [llength $dbt] > 0 } \
 
214
                    { set dbt [$sdbc pget -next] } {
 
215
                        incr i
 
216
                        set pkey [lindex [lindex $dbt 0] 1]
 
217
                        set pdata [lindex [lindex $dbt 0] 2]
 
218
                        error_check_good pdb_get($pkey/$pdata,$j) \
 
219
                            [$pdb get -get_both $pkey $pdata] \
 
220
                            [list [list $pkey $pdata]]
 
221
                }
 
222
                error_check_good secondary($j)_has_nentries $i $nentries
 
223
 
 
224
                # To exercise pget -last/pget -prev, we do it backwards too.
 
225
                set i 0
 
226
                for { set dbt [$sdbc pget -last] } { [llength $dbt] > 0 } \
 
227
                    { set dbt [$sdbc pget -prev] } {
 
228
                        incr i
 
229
                        set pkey [lindex [lindex $dbt 0] 1]
 
230
                        set pdata [lindex [lindex $dbt 0] 2]
 
231
                        error_check_good pdb_get_bkwds($pkey/$pdata,$j) \
 
232
                            [$pdb get -get_both $pkey $pdata] \
 
233
                            [list [list $pkey $pdata]]
 
234
                }
 
235
                error_check_good secondary($j)_has_nentries_bkwds $i $nentries
 
236
 
 
237
                error_check_good ccs_sdbc_close($j) [$sdbc close] 0
 
238
        }
 
239
}
 
240
 
 
241
# The secondary index tests take a list of the access methods that
 
242
# each array ought to use.  Convert at one blow into a list of converted
 
243
# argses and omethods for each method in the list.
 
244
proc convert_argses { methods largs } {
 
245
        set ret {}
 
246
        foreach m $methods {
 
247
                lappend ret [convert_args $m $largs]
 
248
        }
 
249
        return $ret
 
250
}
 
251
proc convert_methods { methods } {
 
252
        set ret {}
 
253
        foreach m $methods {
 
254
                lappend ret [convert_method $m]
 
255
        }
 
256
        return $ret
 
257
}