1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Basic offpage duplicate test.
11
# TEST Run duplicates with small page size so that we test off page duplicates.
12
# TEST Then after we have an off-page database, test with overflow pages too.
13
proc test017 { method {contents 0} {ndups 19} {tnum 17} args } {
16
set args [convert_args $method $args]
17
set omethod [convert_method $method]
19
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
20
puts "Test0$tnum skipping for method $method"
23
set pgindex [lsearch -exact $args "-pagesize"]
24
if { $pgindex != -1 } {
26
if { [lindex $args $pgindex] > 8192 } {
27
puts "Test0$tnum: Skipping for large pagesizes"
32
# Create the database and open the dictionary
34
set eindex [lsearch -exact $args "-env"]
36
# If we are using an env, then testfile should just be the db name.
37
# Otherwise it is the test directory and the name.
38
if { $eindex == -1 } {
39
set testfile $testdir/test0$tnum.db
42
set testfile test0$tnum.db
44
set env [lindex $args $eindex]
45
set txnenv [is_txnenv $env]
47
append args " -auto_commit "
49
set testdir [get_home $env]
58
set db [eval {berkdb_open \
59
-create -mode 0644 -dup} $args {$omethod $testfile}]
60
error_check_good dbopen [is_valid_db $db] TRUE
67
set file_list [get_file_list 1]
69
set flen [llength $file_list]
70
reduce_dups flen ndups
71
set file_list [lrange $file_list 0 $flen]
73
puts "Test0$tnum: $method ($args) Off page duplicate tests with $ndups duplicates"
76
# Here is the loop where we put and get each key/data pair
77
puts -nonewline "\tTest0$tnum.a: Creating duplicates with "
78
if { $contents != 0 } {
79
puts "file contents as key/data"
81
puts "file name as key/data"
83
foreach f $file_list {
84
if { $contents != 0 } {
86
fconfigure $fid -translation binary
88
# Prepend file name to guarantee uniqueness
89
set filecont [read $fid]
95
for { set i 1 } { $i <= $ndups } { incr i } {
99
error_check_good txn [is_valid_txn $t $env] TRUE
102
set ret [eval {$db put} \
103
$txn $pflags {$str [chop_data $method $datastr]}]
104
error_check_good put $ret 0
105
if { $txnenv == 1 } {
106
error_check_good txn [$t commit] 0
111
# Save 10% files for overflow test
113
if { $contents == 0 && [expr $count % 10] == 0 } {
116
# Now retrieve all the keys matching this key
117
set ret [$db get $str]
118
error_check_bad $f:dbget_dups [llength $ret] 0
119
error_check_good $f:dbget_dups1 [llength $ret] $ndups
121
if { $txnenv == 1 } {
123
error_check_good txn [is_valid_txn $t $env] TRUE
126
set dbc [eval {$db cursor} $txn]
127
for {set ret [$dbc get "-set" $str]} \
128
{[llength $ret] != 0} \
129
{set ret [$dbc get "-next"] } {
130
set k [lindex [lindex $ret 0] 0]
131
if { [string compare $k $str] != 0 } {
134
set datastr [lindex [lindex $ret 0] 1]
135
set d [data_of $datastr]
136
if {[string length $d] == 0} {
139
error_check_good "Test0$tnum:get" $d $str
140
set id [ id_of $datastr ]
141
error_check_good "Test0$tnum:$f:dup#" $id $x
144
error_check_good "Test0$tnum:ndups:$str" [expr $x - 1] $ndups
145
error_check_good cursor_close [$dbc close] 0
146
if { $txnenv == 1 } {
147
error_check_good txn [$t commit] 0
152
# Now we will get each key from the DB and compare the results
154
puts "\tTest0$tnum.b: Checking file for correct duplicates"
156
for { set i 1 } { $i <= $ndups } {incr i} {
159
set oid [open $t2.tmp w]
160
set o1id [open $t4.tmp w]
161
foreach f $file_list {
162
for {set i 1} {$i <= $ndups} {incr i} {
174
if { $txnenv == 1 } {
176
error_check_good txn [is_valid_txn $t $env] TRUE
179
dup_check $db $txn $t1 $dlist
180
if { $txnenv == 1 } {
181
error_check_good txn [$t commit] 0
183
if {$contents == 0} {
186
error_check_good Test0$tnum:diff($t3,$t2) [filecmp $t3 $t2] 0
188
# Now compare the keys to see if they match the file names
189
if { $txnenv == 1 } {
191
error_check_good txn [is_valid_txn $t $env] TRUE
194
dump_file $db $txn $t1 test017.check
195
if { $txnenv == 1 } {
196
error_check_good txn [$t commit] 0
200
error_check_good Test0$tnum:diff($t3,$t4) [filecmp $t3 $t4] 0
203
error_check_good db_close [$db close] 0
204
set db [eval {berkdb_open} $args $testfile]
205
error_check_good dbopen [is_valid_db $db] TRUE
207
puts "\tTest0$tnum.c: Checking file for correct duplicates after close"
208
if { $txnenv == 1 } {
210
error_check_good txn [is_valid_txn $t $env] TRUE
213
dup_check $db $txn $t1 $dlist
214
if { $txnenv == 1 } {
215
error_check_good txn [$t commit] 0
218
if {$contents == 0} {
219
# Now compare the keys to see if they match the filenames
221
error_check_good Test0$tnum:diff($t3,$t2) [filecmp $t3 $t2] 0
223
error_check_good db_close [$db close] 0
225
puts "\tTest0$tnum.d: Verify off page duplicates and overflow status"
226
set db [eval {berkdb_open} $args $testfile]
227
error_check_good dbopen [is_valid_db $db] TRUE
229
if { [is_btree $method] } {
230
error_check_bad stat:offpage \
231
[is_substr $stat "{{Internal pages} 0}"] 1
233
if {$contents == 0} {
234
# This check doesn't work in hash, since overflow
235
# pages count extra pages in buckets as well as true
237
if { [is_hash $method] == 0 } {
238
error_check_good overflow \
239
[is_substr $stat "{{Overflow pages} 0}"] 1
242
error_check_bad overflow \
243
[is_substr $stat "{{Overflow pages} 0}"] 1
247
# If doing overflow test, do that now. Else we are done.
248
# Add overflow pages by adding a large entry to a duplicate.
250
if { [llength $ovfl] == 0} {
251
error_check_good db_close [$db close] 0
255
puts "\tTest0$tnum.e: Add overflow duplicate entries"
256
set ovfldup [expr $ndups + 1]
259
# This is just like put_file, but prepends the dup number
262
fconfigure $fid -translation binary
263
set fdata [read $fid]
265
set data $ovfldup:$fdata:$fdata:$fdata:$fdata
267
if { $txnenv == 1 } {
269
error_check_good txn [is_valid_txn $t $env] TRUE
272
set ret [eval {$db put} $txn $pflags {$f $data}]
273
error_check_good ovfl_put $ret 0
274
if { $txnenv == 1 } {
275
error_check_good txn [$t commit] 0
279
puts "\tTest0$tnum.f: Verify overflow duplicate entries"
280
if { $txnenv == 1 } {
282
error_check_good txn [is_valid_txn $t $env] TRUE
285
dup_check $db $txn $t1 $dlist $ovfldup
286
if { $txnenv == 1 } {
287
error_check_good txn [$t commit] 0
290
error_check_good Test0$tnum:diff($t3,$t2) [filecmp $t3 $t2] 0
293
if { [is_hash [$db get_type]] } {
294
error_check_bad overflow1_hash [is_substr $stat \
295
"{{Number of big pages} 0}"] 1
298
overflow1 [is_substr $stat "{{Overflow pages} 0}"] 1
300
error_check_good db_close [$db close] 0
303
# Check function; verify data contains key
304
proc test017.check { key data } {
305
error_check_good "data mismatch for key $key" $key [data_of $data]