1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test053.tcl,v 11.13 2001/01/25 18:23:12 bostic Exp $
8
# Test53: test of the DB_REVSPLITOFF flag in the btree and
9
# Btree-w-recnum methods
10
proc test053 { method args } {
15
set args [convert_args $method $args]
16
set omethod [convert_method $method]
18
puts "\tTest053: Test of cursor stability across btree splits."
19
if { [is_btree $method] != 1 && [is_rbtree $method] != 1 } {
20
puts "Test053: skipping for method $method."
24
set pgindex [lsearch -exact $args "-pagesize"]
25
if { $pgindex != -1 } {
26
puts "Test053: skipping for specific pagesizes"
33
puts "\tTest053.a: Create $omethod $args database."
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/test053.db
42
set testfile test053.db
44
set env [lindex $args $eindex]
50
"-create -truncate -revsplitoff -pagesize 1024 $args $omethod"
51
set db [eval {berkdb_open} $oflags $testfile]
52
error_check_good dbopen [is_valid_db $db] TRUE
57
# We want to create a db with npages leaf pages, and have each page
58
# be near full with keys that we can predict. We set pagesize above
59
# to 1024 bytes, it should breakdown as follows (per page):
62
# key: ~4 bytes overhead, XXX0N where X is a letter, N is 0-9
63
# data: ~4 bytes overhead, + 100 bytes
65
# then, with 8 keys/page we should be just under 1024 bytes
66
puts "\tTest053.b: Create $npages pages with $nkeys pairs on each."
67
set keystring [string range $alphabet 0 [expr $npages -1]]
68
set data [repeat DATA 22]
69
for { set i 0 } { $i < $npages } {incr i } {
72
[repeat [string toupper [string range $keystring $i $i]] 3]
73
set key_set($i) $keyroot
74
for {set j 0} { $j < $nkeys} {incr j} {
76
set key [set keyroot]0$j
80
set ret [$db put $key $data]
81
error_check_good dbput $ret 0
85
puts "\tTest053.c: Check page count."
86
error_check_good page_count:check \
87
[is_substr [$db stat] "{Leaf pages} $npages"] 1
89
puts "\tTest053.d: Delete all but one key per page."
90
for {set i 0} { $i < $npages } {incr i } {
91
for {set j 1} { $j < $nkeys } {incr j } {
92
set ret [$db del $key_set($i)0$j]
93
error_check_good dbdel $ret 0
96
puts "\tTest053.e: Check to make sure all pages are still there."
97
error_check_good page_count:check \
98
[is_substr [$db stat] "{Leaf pages} $npages"] 1
101
error_check_good db:cursor [is_substr $dbc $db] 1
103
# walk cursor through tree forward, backward.
104
# delete one key, repeat
105
for {set i 0} { $i < $npages} {incr i} {
107
"\tTest053.f.$i: Walk curs through tree: forward..."
108
for { set j $i; set curr [$dbc get -first]} { $j < $npages} { \
109
incr j; set curr [$dbc get -next]} {
110
error_check_bad dbc:get:next [llength $curr] 0
111
error_check_good dbc:get:keys \
112
[lindex [lindex $curr 0] 0] $key_set($j)00
114
puts -nonewline "backward..."
115
for { set j [expr $npages - 1]; set curr [$dbc get -last]} { \
117
set j [incr j -1]; set curr [$dbc get -prev]} {
118
error_check_bad dbc:get:prev [llength $curr] 0
119
error_check_good dbc:get:keys \
120
[lindex [lindex $curr 0] 0] $key_set($j)00
124
if { [is_rbtree $method] == 1} {
125
puts "\t\tTest053.f.$i:\
126
Walk through tree with record numbers."
127
for {set j 1} {$j <= [expr $npages - $i]} {incr j} {
128
set curr [$db get -recno $j]
130
db_get:recno:$j [llength $curr] 0
131
error_check_good db_get:recno:keys:$j \
132
[lindex [lindex $curr 0] 0] \
133
$key_set([expr $j + $i - 1])00
136
puts "\tTest053.g.$i:\
137
Delete single key ([expr $npages - $i] keys left)."
138
set ret [$db del $key_set($i)00]
139
error_check_good dbdel $ret 0
140
error_check_good del:check \
141
[llength [$db get $key_set($i)00]] 0
144
# end for loop, verify db_notfound
145
set ret [$dbc get -first]
146
error_check_good dbc:get:verify [llength $ret] 0
148
# loop: until single key restored on each page
149
for {set i 0} { $i < $npages} {incr i} {
150
puts "\tTest053.i.$i:\
151
Restore single key ([expr $i + 1] keys in tree)."
152
set ret [$db put $key_set($i)00 $data]
153
error_check_good dbput $ret 0
156
"\tTest053.j: Walk cursor through tree: forward..."
157
for { set j 0; set curr [$dbc get -first]} { $j <= $i} {\
158
incr j; set curr [$dbc get -next]} {
159
error_check_bad dbc:get:next [llength $curr] 0
160
error_check_good dbc:get:keys \
161
[lindex [lindex $curr 0] 0] $key_set($j)00
163
error_check_good dbc:get:next [llength $curr] 0
165
puts -nonewline "backward..."
166
for { set j $i; set curr [$dbc get -last]} { \
168
set j [incr j -1]; set curr [$dbc get -prev]} {
169
error_check_bad dbc:get:prev [llength $curr] 0
170
error_check_good dbc:get:keys \
171
[lindex [lindex $curr 0] 0] $key_set($j)00
174
error_check_good dbc:get:prev [llength $curr] 0
176
if { [is_rbtree $method] == 1} {
177
puts "\t\tTest053.k.$i:\
178
Walk through tree with record numbers."
179
for {set j 1} {$j <= [expr $i + 1]} {incr j} {
180
set curr [$db get -recno $j]
182
db_get:recno:$j [llength $curr] 0
183
error_check_good db_get:recno:keys:$j \
184
[lindex [lindex $curr 0] 0] \
185
$key_set([expr $j - 1])00
190
error_check_good dbc_close [$dbc close] 0
191
error_check_good db_close [$db close] 0
193
puts "Test053 complete."