1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996, 1997, 1998, 1999, 2000
# Sleepycat Software. All rights reserved.
#
# $Id: log.tcl,v 11.17 2000/11/30 20:09:19 dda Exp $
#
# Options are:
# -dir <directory in which to store memp>
# -maxfilesize <maxsize of log file>
# -iterations <iterations>
# -stat
proc log_usage {} {
puts "log -dir <directory> -iterations <number of ops> \
-maxfilesize <max size of log files> -stat"
}
proc logtest { args } {
source ./include.tcl
global rand_init
# Set defaults
set iterations 1000
set maxfile [expr 1024 * 128]
set dostat 0
for { set i 0 } { $i < [llength $args] } {incr i} {
switch -regexp -- [lindex $args $i] {
-d.* { incr i; set testdir [lindex $args $i] }
-i.* { incr i; set iterations [lindex $args $i] }
-m.* { incr i; set maxfile [lindex $args $i] }
-s.* { set dostat 1 }
default {
puts -nonewline "FAIL:[timestamp] Usage: "
log_usage
return
}
}
}
set multi_log [expr 3 * $iterations]
# Clean out old log if it existed
puts "Unlinking log: error message OK"
env_cleanup $testdir
# Now run the various functionality tests
berkdb srand $rand_init
log001 $testdir $maxfile $iterations
log001 $testdir $maxfile $multi_log
log002 $testdir $maxfile
log003 $testdir $maxfile
log004 $testdir
}
proc log001 { dir max nrecs } {
source ./include.tcl
puts "Log001: Basic put/get test"
env_cleanup $dir
set env [berkdb env -log -create -home $dir \
-mode 0644 -log_max $max]
error_check_bad log_env:$dir $env NULL
error_check_good log:$dir [is_substr $env "env"] 1
# We will write records to the log and make sure we can
# read them back correctly. We'll use a standard pattern
# repeated some number of times for each record.
set lsn_list {}
set rec_list {}
puts "Log001.a: Writing $nrecs log records"
for { set i 0 } { $i < $nrecs } { incr i } {
set rec ""
for { set j 0 } { $j < [expr $i % 10 + 1] } {incr j} {
set rec $rec$i:logrec:$i
}
set lsn [$env log_put $rec]
error_check_bad log_put [is_substr $lsn log_cmd] 1
lappend lsn_list $lsn
lappend rec_list $rec
}
puts "Log001.b: Retrieving log records sequentially (forward)"
set i 0
for { set grec [$env log_get -first] } { [llength $grec] != 0 } {
set grec [$env log_get -next]} {
error_check_good log_get:seq [lindex $grec 1] \
[lindex $rec_list $i]
incr i
}
puts "Log001.c: Retrieving log records sequentially (backward)"
set i [llength $rec_list]
for { set grec [$env log_get -last] } { [llength $grec] != 0 } {
set grec [$env log_get -prev] } {
incr i -1
error_check_good \
log_get:seq [lindex $grec 1] [lindex $rec_list $i]
}
puts "Log001.d: Retrieving log records sequentially by LSN"
set i 0
foreach lsn $lsn_list {
set grec [$env log_get -set $lsn]
error_check_good \
log_get:seq [lindex $grec 1] [lindex $rec_list $i]
incr i
}
puts "Log001.e: Retrieving log records randomly by LSN"
set m [expr [llength $lsn_list] - 1]
for { set i 0 } { $i < $nrecs } { incr i } {
set recno [berkdb random_int 0 $m ]
set lsn [lindex $lsn_list $recno]
set grec [$env log_get -set $lsn]
error_check_good \
log_get:seq [lindex $grec 1] [lindex $rec_list $recno]
}
# Close and unlink the file
error_check_good env:close:$env [$env close] 0
error_check_good envremove:$dir [berkdb envremove -home $dir] 0
puts "Log001 Complete"
}
proc log002 { dir {max 32768} } {
source ./include.tcl
puts "Log002: Multiple log test w/trunc, file, compare functionality"
env_cleanup $dir
set env [berkdb env -create -home $dir -mode 0644 -log -log_max $max]
error_check_bad log_env:$dir $env NULL
error_check_good log:$dir [is_substr $env "env"] 1
# We'll record every hundred'th record for later use
set info_list {}
set i 0
puts "Log002.a: Writing log records"
for {set s 0} { $s < [expr 3 * $max] } { incr s $len } {
set rec [random_data 120 0 0]
set len [string length $rec]
set lsn [$env log_put $rec]
if { [expr $i % 100 ] == 0 } {
lappend info_list [list $lsn $rec]
}
incr i
}
puts "Log002.b: Checking log_compare"
set last {0 0}
foreach p $info_list {
set l [lindex $p 0]
if { [llength $last] != 0 } {
error_check_good \
log_compare [$env log_compare $l $last] 1
error_check_good \
log_compare [$env log_compare $last $l] -1
error_check_good \
log_compare [$env log_compare $l $l] 0
}
set last $l
}
puts "Log002.c: Checking log_file"
set flist [glob $dir/log*]
foreach p $info_list {
set lsn [lindex $p 0]
set f [$env log_file $lsn]
# Change all backslash separators on Windows to forward slash
# separators, which is what the rest of the test suite expects.
regsub -all {\\} $f {/} f
error_check_bad log_file:$f [lsearch $flist $f] -1
}
puts "Log002.d: Verifying records"
for {set i [expr [llength $info_list] - 1] } { $i >= 0 } { incr i -1} {
set p [lindex $info_list $i]
set grec [$env log_get -set [lindex $p 0]]
error_check_good log_get:$env [lindex $grec 1] [lindex $p 1]
}
# Close and unlink the file
error_check_good env:close:$env [$env close] 0
error_check_good envremove:$dir [berkdb envremove -home $dir] 0
puts "Log002 Complete"
}
proc log003 { dir {max 32768} } {
source ./include.tcl
puts "Log003: Verify log_flush behavior"
env_cleanup $dir
set short_rec "abcdefghijklmnopqrstuvwxyz"
set long_rec [repeat $short_rec 200]
set very_long_rec [repeat $long_rec 4]
foreach rec "$short_rec $long_rec $very_long_rec" {
puts "Log003.a: Verify flush on [string length $rec] byte rec"
set env [berkdb env -log -home $dir \
-create -mode 0644 -log_max $max]
error_check_bad log_env:$dir $env NULL
error_check_good log:$dir [is_substr $env "env"] 1
set lsn [$env log_put $rec]
error_check_bad log_put [lindex $lsn 0] "ERROR:"
set ret [$env log_flush $lsn]
error_check_good log_flush $ret 0
# Now, we want to crash the region and recheck. Closing the
# log does not flush any records, so we'll use a close to
# do the "crash"
set ret [$env close]
error_check_good log_env:close $ret 0
# Now, remove the log region
#set ret [berkdb envremove -home $dir]
#error_check_good env:remove $ret 0
# Re-open the log and try to read the record.
set env [berkdb env -create -home $dir \
-log -mode 0644 -log_max $max]
error_check_bad log_env:$dir $env NULL
error_check_good log:$dir [is_substr $env "env"] 1
set gotrec [$env log_get -first]
error_check_good lp_get [lindex $gotrec 1] $rec
# Close and unlink the file
error_check_good env:close:$env [$env close] 0
error_check_good envremove:$dir [berkdb envremove -home $dir] 0
log_cleanup $dir
}
foreach rec "$short_rec $long_rec $very_long_rec" {
puts "Log003.b: \
Verify flush on non-last record [string length $rec]"
set env [berkdb env \
-create -log -home $dir -mode 0644 -log_max $max]
error_check_bad log_env:$dir $env NULL
error_check_good log:$dir [is_substr $env "env"] 1
# Put 10 random records
for { set i 0 } { $i < 10 } { incr i} {
set r [random_data 450 0 0]
set lsn [$env log_put $r]
error_check_bad log_put [lindex $lsn 0] "ERROR:"
}
# Put the record we are interested in
set save_lsn [$env log_put $rec]
error_check_bad log_put [lindex $save_lsn 0] "ERROR:"
# Put 10 more random records
for { set i 0 } { $i < 10 } { incr i} {
set r [random_data 450 0 0]
set lsn [$env log_put $r]
error_check_bad log_put [lindex $lsn 0] "ERROR:"
}
# Now check the flush
set ret [$env log_flush $save_lsn]
error_check_good log_flush $ret 0
# Now, we want to crash the region and recheck. Closing the
# log does not flush any records, so we'll use a close to
# do the "crash"
#
# Now, close and remove the log region
error_check_good env:close:$env [$env close] 0
set ret [berkdb envremove -home $dir]
error_check_good env:remove $ret 0
# Re-open the log and try to read the record.
set env [berkdb env \
-home $dir -create -log -mode 0644 -log_max $max]
error_check_bad log_env:$dir $env NULL
error_check_good log:$dir [is_substr $env "env"] 1
set gotrec [$env log_get -set $save_lsn]
error_check_good lp_get [lindex $gotrec 1] $rec
# Close and unlink the file
error_check_good env:close:$env [$env close] 0
error_check_good envremove:$dir [berkdb envremove -home $dir] 0
log_cleanup $dir
}
puts "Log003 Complete"
}
# Make sure that if we do PREVs on a log, but the beginning of the
# log has been truncated, we do the right thing.
proc log004 { dir } {
source ./include.tcl
puts "Log004: Prev on log when beginning of log has been truncated."
# Use archive test to populate log
env_cleanup $dir
puts "Log004.a: Call archive to populate log."
archive
# Delete all log files under 100
puts "Log004.b: Delete all log files under 100."
set ret [catch { glob $dir/log.00000000* } result]
if { $ret == 0 } {
eval fileremove -f $result
}
# Now open the log and get the first record and try a prev
puts "Log004.c: Open truncated log, attempt to access missing portion."
set myenv [berkdb env -create -log -home $dir]
error_check_good log_open [is_substr $myenv "env"] 1
set ret [$myenv log_get -first]
error_check_bad log_get [llength $ret] 0
# This should give DB_NOTFOUND which is a ret of length 0
catch {$myenv log_get -prev} ret
error_check_good log_get_prev [string length $ret] 0
puts "Log004.d: Close log and environment."
error_check_good log_close [$myenv close] 0
puts "Log004 complete."
}
|