~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to bdb/test/sysscript.tcl

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 1996-2002
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: sysscript.tcl,v 11.17 2002/07/29 17:05:24 sue Exp $
 
7
#
 
8
# System integration test script.
 
9
# This script runs a single process that tests the full functionality of
 
10
# the system.  The database under test contains nfiles files.  Each process
 
11
# randomly generates a key and some data.  Both keys and data are bimodally
 
12
# distributed between small keys (1-10 characters) and large keys (the avg
 
13
# length is indicated via the command line parameter.
 
14
# The process then decides on a replication factor between 1 and nfiles.
 
15
# It writes the key and data to that many files and tacks on the file ids
 
16
# of the files it writes to the data string.  For example, let's say that
 
17
# I randomly generate the key dog and data cat.  Then I pick a replication
 
18
# factor of 3.  I pick 3 files from the set of n (say 1, 3, and 5).  I then
 
19
# rewrite the data as 1:3:5:cat.  I begin a transaction, add the key/data
 
20
# pair to each file and then commit.  Notice that I may generate replication
 
21
# of the form 1:3:3:cat in which case I simply add a duplicate to file 3.
 
22
#
 
23
# Usage: sysscript dir nfiles key_avg data_avg
 
24
#
 
25
# dir: DB_HOME directory
 
26
# nfiles: number of files in the set
 
27
# key_avg: average big key size
 
28
# data_avg: average big data size
 
29
 
 
30
source ./include.tcl
 
31
source $test_path/test.tcl
 
32
source $test_path/testutils.tcl
 
33
 
 
34
set mypid [pid]
 
35
 
 
36
set usage "sysscript dir nfiles key_avg data_avg method"
 
37
 
 
38
# Verify usage
 
39
if { $argc != 5 } {
 
40
        puts stderr "FAIL:[timestamp] Usage: $usage"
 
41
        exit
 
42
}
 
43
 
 
44
puts [concat "Argc: " $argc " Argv: " $argv]
 
45
 
 
46
# Initialize arguments
 
47
set dir [lindex $argv 0]
 
48
set nfiles [ lindex $argv 1 ]
 
49
set key_avg [ lindex $argv 2 ]
 
50
set data_avg [ lindex $argv 3 ]
 
51
set method [ lindex $argv 4 ]
 
52
 
 
53
# Initialize seed
 
54
global rand_init
 
55
berkdb srand $rand_init
 
56
 
 
57
puts "Beginning execution for $mypid"
 
58
puts "$dir DB_HOME"
 
59
puts "$nfiles files"
 
60
puts "$key_avg average key length"
 
61
puts "$data_avg average data length"
 
62
 
 
63
flush stdout
 
64
 
 
65
# Create local environment
 
66
set dbenv [berkdb_env -txn -home $dir]
 
67
set err [catch {error_check_good $mypid:dbenv [is_substr $dbenv env] 1} ret]
 
68
if {$err != 0} {
 
69
        puts $ret
 
70
        return
 
71
}
 
72
 
 
73
# Now open the files
 
74
for { set i 0 } { $i < $nfiles } { incr i } {
 
75
        set file test044.$i.db
 
76
        set db($i) [berkdb open -auto_commit -env $dbenv $method $file]
 
77
        set err [catch {error_check_bad $mypid:dbopen $db($i) NULL} ret]
 
78
        if {$err != 0} {
 
79
                puts $ret
 
80
                return
 
81
        }
 
82
        set err [catch {error_check_bad $mypid:dbopen [is_substr $db($i) \
 
83
            error] 1} ret]
 
84
        if {$err != 0} {
 
85
                puts $ret
 
86
                return
 
87
        }
 
88
}
 
89
 
 
90
set record_based [is_record_based $method]
 
91
while { 1 } {
 
92
        # Decide if we're going to create a big key or a small key
 
93
        # We give small keys a 70% chance.
 
94
        if { [berkdb random_int 1 10] < 8 } {
 
95
                set k [random_data 5 0 0 $record_based]
 
96
        } else {
 
97
                set k [random_data $key_avg 0 0 $record_based]
 
98
        }
 
99
        set data [chop_data $method [random_data $data_avg 0 0]]
 
100
 
 
101
        set txn [$dbenv txn]
 
102
        set err [catch {error_check_good $mypid:txn_begin [is_substr $txn \
 
103
            $dbenv.txn] 1} ret]
 
104
        if {$err != 0} {
 
105
                puts $ret
 
106
                return
 
107
        }
 
108
 
 
109
        # Open cursors
 
110
        for { set f 0 } {$f < $nfiles} {incr f} {
 
111
                set cursors($f) [$db($f) cursor -txn $txn]
 
112
                set err [catch {error_check_good $mypid:cursor_open \
 
113
                    [is_substr $cursors($f) $db($f)] 1} ret]
 
114
                if {$err != 0} {
 
115
                        puts $ret
 
116
                        return
 
117
                }
 
118
        }
 
119
        set aborted 0
 
120
 
 
121
        # Check to see if key is already in database
 
122
        set found 0
 
123
        for { set i 0 } { $i < $nfiles } { incr i } {
 
124
                set r [$db($i) get -txn $txn $k]
 
125
                set r [$db($i) get -txn $txn $k]
 
126
                if { $r == "-1" } {
 
127
                        for {set f 0 } {$f < $nfiles} {incr f} {
 
128
                                set err [catch {error_check_good \
 
129
                                    $mypid:cursor_close \
 
130
                                    [$cursors($f) close] 0} ret]
 
131
                                if {$err != 0} {
 
132
                                        puts $ret
 
133
                                        return
 
134
                                }
 
135
                        }
 
136
                        set err [catch {error_check_good $mypid:txn_abort \
 
137
                            [$txn abort] 0} ret]
 
138
                        if {$err != 0} {
 
139
                                puts $ret
 
140
                                return
 
141
                        }
 
142
                        set aborted 1
 
143
                        set found 2
 
144
                        break
 
145
                } elseif { $r != "Key $k not found." } {
 
146
                        set found 1
 
147
                        break
 
148
                }
 
149
        }
 
150
        switch $found {
 
151
        2 {
 
152
                # Transaction aborted, no need to do anything.
 
153
        }
 
154
        0 {
 
155
                # Key was not found, decide how much to replicate
 
156
                # and then create a list of that many file IDs.
 
157
                set repl [berkdb random_int 1 $nfiles]
 
158
                set fset ""
 
159
                for { set i 0 } { $i < $repl } {incr i} {
 
160
                        set f [berkdb random_int 0 [expr $nfiles - 1]]
 
161
                        lappend fset $f
 
162
                        set data [chop_data $method $f:$data]
 
163
                }
 
164
 
 
165
                foreach i $fset {
 
166
                        set r [$db($i) put -txn $txn $k $data]
 
167
                        if {$r == "-1"} {
 
168
                                for {set f 0 } {$f < $nfiles} {incr f} {
 
169
                                        set err [catch {error_check_good \
 
170
                                            $mypid:cursor_close \
 
171
                                            [$cursors($f) close] 0} ret]
 
172
                                        if {$err != 0} {
 
173
                                                puts $ret
 
174
                                                return
 
175
                                        }
 
176
                                }
 
177
                                set err [catch {error_check_good \
 
178
                                    $mypid:txn_abort [$txn abort] 0} ret]
 
179
                                if {$err != 0} {
 
180
                                        puts $ret
 
181
                                        return
 
182
                                }
 
183
                                set aborted 1
 
184
                                break
 
185
                        }
 
186
                }
 
187
        }
 
188
        1 {
 
189
                # Key was found.  Make sure that all the data values
 
190
                # look good.
 
191
                set f [zero_list $nfiles]
 
192
                set data $r
 
193
                while { [set ndx [string first : $r]] != -1 } {
 
194
                        set fnum [string range $r 0 [expr $ndx - 1]]
 
195
                        if { [lindex $f $fnum] == 0 } {
 
196
                                #set flag -set
 
197
                                set full [record $cursors($fnum) get -set $k]
 
198
                        } else {
 
199
                                #set flag -next
 
200
                                set full [record $cursors($fnum) get -next]
 
201
                        }
 
202
                        if {[llength $full] == 0} {
 
203
                                for {set f 0 } {$f < $nfiles} {incr f} {
 
204
                                        set err [catch {error_check_good \
 
205
                                            $mypid:cursor_close \
 
206
                                            [$cursors($f) close] 0} ret]
 
207
                                        if {$err != 0} {
 
208
                                                puts $ret
 
209
                                                return
 
210
                                        }
 
211
                                }
 
212
                                set err [catch {error_check_good \
 
213
                                    $mypid:txn_abort [$txn abort] 0} ret]
 
214
                                if {$err != 0} {
 
215
                                        puts $ret
 
216
                                        return
 
217
                                }
 
218
                                set aborted 1
 
219
                                break
 
220
                        }
 
221
                        set err [catch {error_check_bad \
 
222
                            $mypid:curs_get($k,$data,$fnum,$flag) \
 
223
                            [string length $full] 0} ret]
 
224
                        if {$err != 0} {
 
225
                                puts $ret
 
226
                                return
 
227
                        }
 
228
                        set key [lindex [lindex $full 0] 0]
 
229
                        set rec [pad_data $method [lindex [lindex $full 0] 1]]
 
230
                        set err [catch {error_check_good \
 
231
                            $mypid:dbget_$fnum:key $key $k} ret]
 
232
                        if {$err != 0} {
 
233
                                puts $ret
 
234
                                return
 
235
                        }
 
236
                        set err [catch {error_check_good \
 
237
                            $mypid:dbget_$fnum:data($k) $rec $data} ret]
 
238
                        if {$err != 0} {
 
239
                                puts $ret
 
240
                                return
 
241
                        }
 
242
                        set f [lreplace $f $fnum $fnum 1]
 
243
                        incr ndx
 
244
                        set r [string range $r $ndx end]
 
245
                }
 
246
        }
 
247
        }
 
248
        if { $aborted == 0 } {
 
249
                for {set f 0 } {$f < $nfiles} {incr f} {
 
250
                        set err [catch {error_check_good $mypid:cursor_close \
 
251
                            [$cursors($f) close] 0} ret]
 
252
                        if {$err != 0} {
 
253
                                puts $ret
 
254
                                return
 
255
                        }
 
256
                }
 
257
                set err [catch {error_check_good $mypid:commit [$txn commit] \
 
258
                    0} ret]
 
259
                if {$err != 0} {
 
260
                        puts $ret
 
261
                        return
 
262
                }
 
263
        }
 
264
}
 
265
 
 
266
# Close files
 
267
for { set i 0 } { $i < $nfiles} { incr i } {
 
268
        set r [$db($i) close]
 
269
        set err [catch {error_check_good $mypid:db_close:$i $r 0} ret]
 
270
        if {$err != 0} {
 
271
                puts $ret
 
272
                return
 
273
        }
 
274
}
 
275
 
 
276
# Close tm and environment
 
277
$dbenv close
 
278
 
 
279
puts "[timestamp] [pid] Complete"
 
280
flush stdout
 
281
 
 
282
filecheck $file 0