1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test of cursor stability across btree splits with very
10
# TEST deep trees (a variant of test048). [#2514]
11
proc test088 { method args } {
12
global errorCode alphabet
16
set args [convert_args $method $args]
18
if { [is_btree $method] != 1 } {
19
puts "Test$tstn skipping for method $method."
22
set pgindex [lsearch -exact $args "-pagesize"]
23
if { $pgindex != -1 } {
24
puts "Test088: skipping for specific pagesizes"
30
puts "\tTest$tstn: Test of cursor stability across btree splits."
32
set key "key$alphabet$alphabet$alphabet"
33
set data "data$alphabet$alphabet$alphabet"
37
puts "\tTest$tstn.a: Create $method database."
39
set eindex [lsearch -exact $args "-env"]
41
# If we are using an env, then testfile should just be the db name.
42
# Otherwise it is the test directory and the name.
43
if { $eindex == -1 } {
44
set testfile $testdir/test$tstn.db
47
set testfile test$tstn.db
49
set env [lindex $args $eindex]
50
set txnenv [is_txnenv $env]
52
append args " -auto_commit "
54
set testdir [get_home $env]
61
set oflags "-create -pagesize $ps -mode 0644 $args $method"
62
set db [eval {berkdb_open} $oflags $testfile]
63
error_check_good dbopen [is_valid_db $db] TRUE
66
# Fill page w/ key/data pairs.
68
puts "\tTest$tstn.b: Fill page with $nkeys small key/data pairs."
69
for { set i 0 } { $i < $nkeys } { incr i } {
72
error_check_good txn [is_valid_txn $t $env] TRUE
75
set ret [eval {$db put} $txn {${key}00000$i $data$i}]
76
error_check_good dbput $ret 0
78
error_check_good txn [$t commit] 0
82
# get db ordering, set cursors
83
puts "\tTest$tstn.c: Set cursors on each of $nkeys pairs."
84
# if mkeys is above 1000, need to adjust below for lexical order
88
error_check_good txn [is_valid_txn $t $env] TRUE
92
for {set i 0; set ret [$db get ${key}00000$i]} {\
93
$i < $nkeys && [llength $ret] != 0} {\
94
incr i; set ret [$db get ${key}00000$i]} {
95
set key_set($i) [lindex [lindex $ret 0] 0]
96
set data_set($i) [lindex [lindex $ret 0] 1]
97
set dbc [eval {$db cursor} $txn]
99
error_check_good db_cursor:$i [is_substr $dbc_set($i) $db] 1
100
set ret [$dbc_set($i) get -set $key_set($i)]
101
error_check_bad dbc_set($i)_get:set [llength $ret] 0
104
puts "\tTest$tstn.d: Add $mkeys pairs to force splits."
105
for {set i $nkeys} { $i < $mkeys } { incr i } {
107
set ret [eval {$db put} $txn {${key}0$i $data$i}]
108
} elseif { $i >= 1000 } {
109
set ret [eval {$db put} $txn {${key}00$i $data$i}]
110
} elseif { $i >= 100 } {
111
set ret [eval {$db put} $txn {${key}000$i $data$i}]
112
} elseif { $i >= 10 } {
113
set ret [eval {$db put} $txn {${key}0000$i $data$i}]
115
set ret [eval {$db put} $txn {${key}00000$i $data$i}]
117
error_check_good dbput:more $ret 0
120
puts "\tTest$tstn.e: Make sure splits happened."
121
# XXX cannot execute stat in presence of txns and cursors.
122
if { $txnenv == 0 } {
123
error_check_bad stat:check-split [is_substr [$db stat] \
124
"{{Internal pages} 0}"] 1
127
puts "\tTest$tstn.f: Check to see that cursors maintained reference."
128
for {set i 0} { $i < $nkeys } {incr i} {
129
set ret [$dbc_set($i) get -current]
130
error_check_bad dbc$i:get:current [llength $ret] 0
131
set ret2 [$dbc_set($i) get -set $key_set($i)]
132
error_check_bad dbc$i:get:set [llength $ret2] 0
133
error_check_good dbc$i:get(match) $ret $ret2
136
puts "\tTest$tstn.g: Delete added keys to force reverse splits."
137
for {set i $nkeys} { $i < $mkeys } { incr i } {
139
set ret [eval {$db del} $txn {${key}0$i}]
140
} elseif { $i >= 1000 } {
141
set ret [eval {$db del} $txn {${key}00$i}]
142
} elseif { $i >= 100 } {
143
set ret [eval {$db del} $txn {${key}000$i}]
144
} elseif { $i >= 10 } {
145
set ret [eval {$db del} $txn {${key}0000$i}]
147
set ret [eval {$db del} $txn {${key}00000$i}]
149
error_check_good dbput:more $ret 0
152
puts "\tTest$tstn.h: Verify cursor reference."
153
for {set i 0} { $i < $nkeys } {incr i} {
154
set ret [$dbc_set($i) get -current]
155
error_check_bad dbc$i:get:current [llength $ret] 0
156
set ret2 [$dbc_set($i) get -set $key_set($i)]
157
error_check_bad dbc$i:get:set [llength $ret2] 0
158
error_check_good dbc$i:get(match) $ret $ret2
161
puts "\tTest$tstn.i: Cleanup."
163
for {set i 0} { $i < $nkeys } {incr i} {
164
error_check_good dbc_close:$i [$dbc_set($i) close] 0
166
if { $txnenv == 1 } {
167
error_check_good txn [$t commit] 0
169
error_check_good dbclose [$db close] 0
171
puts "\tTest$tstn complete."