1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test the Btree and Record number renumbering.
10
proc test029 { method {nentries 10000} args} {
13
set do_renumber [is_rrecno $method]
14
set args [convert_args $method $args]
15
set omethod [convert_method $method]
17
puts "Test029: $method ($args)"
19
if { [string compare $omethod "-hash"] == 0 } {
20
puts "Test029 skipping for method HASH"
23
if { [is_record_based $method] == 1 && $do_renumber != 1 } {
24
puts "Test029 skipping for method RECNO (w/out renumbering)"
28
# Create the database and open the dictionary
30
set eindex [lsearch -exact $args "-env"]
32
# If we are using an env, then testfile should just be the db name.
33
# Otherwise it is the test directory and the name.
34
if { $eindex == -1 } {
35
set testfile $testdir/test029.db
38
set testfile test029.db
40
set env [lindex $args $eindex]
41
set txnenv [is_txnenv $env]
43
append args " -auto_commit "
45
# If we are using txns and running with the
46
# default, set the default down a bit.
48
if { $nentries == 10000 } {
49
# Do not set nentries down to 100 until we
54
set testdir [get_home $env]
58
# Read the first nentries dictionary elements and reverse them.
59
# Keep a list of these (these will be the keys).
60
puts "\tTest029.a: initialization"
64
while { [gets $did str] != -1 && $count < $nentries } {
65
lappend keys [reverse $str]
70
# Generate sorted order for the keys
71
set sorted_keys [lsort $keys]
73
# Save the first and last keys
74
set last_key [lindex $sorted_keys end]
75
set last_keynum [llength $sorted_keys]
77
set first_key [lindex $sorted_keys 0]
81
if { [string compare $omethod "-btree"] == 0 } {
82
set db [eval {berkdb_open -create \
83
-mode 0644 -recnum} $args {$omethod $testfile}]
84
error_check_good dbopen [is_valid_db $db] TRUE
86
set db [eval {berkdb_open -create \
87
-mode 0644} $args {$omethod $testfile}]
88
error_check_good dbopen [is_valid_db $db] TRUE
95
if { [is_record_based $method] == 1 } {
96
append gflags " -recno"
99
puts "\tTest029.b: put/get loop"
101
if { [is_record_based $method] == 1 } {
102
set key [lsearch $sorted_keys $k]
107
if { $txnenv == 1 } {
109
error_check_good txn [is_valid_txn $t $env] TRUE
112
set ret [eval {$db put} \
113
$txn $pflags {$key [chop_data $method $k]}]
114
error_check_good dbput $ret 0
116
set ret [eval {$db get} $txn $gflags {$key}]
117
error_check_good dbget [lindex [lindex $ret 0] 1] $k
118
if { $txnenv == 1 } {
119
error_check_good txn [$t commit] 0
123
# Now delete the first key in the database
124
puts "\tTest029.c: delete and verify renumber"
126
# Delete the first key in the file
127
if { [is_record_based $method] == 1 } {
128
set key $first_keynum
133
if { $txnenv == 1 } {
135
error_check_good txn [is_valid_txn $t $env] TRUE
138
set ret [eval {$db del} $txn {$key}]
139
error_check_good db_del $ret 0
140
if { $txnenv == 1 } {
141
error_check_good txn [$t commit] 0
144
# Now we are ready to retrieve records based on
146
if { [string compare $omethod "-btree"] == 0 } {
147
append gflags " -recno"
150
# First try to get the old last key (shouldn't exist)
151
if { $txnenv == 1 } {
153
error_check_good txn [is_valid_txn $t $env] TRUE
156
set ret [eval {$db get} $txn $gflags {$last_keynum}]
157
error_check_good get_after_del $ret [list]
158
if { $txnenv == 1 } {
159
error_check_good txn [$t commit] 0
162
# Now try to get what we think should be the last key
163
if { $txnenv == 1 } {
165
error_check_good txn [is_valid_txn $t $env] TRUE
168
set ret [eval {$db get} $txn $gflags {[expr $last_keynum - 1]}]
170
getn_last_after_del [lindex [lindex $ret 0] 1] $last_key
171
if { $txnenv == 1 } {
172
error_check_good txn [$t commit] 0
175
# Create a cursor; we need it for the next test and we
176
# need it for recno here.
177
if { $txnenv == 1 } {
179
error_check_good txn [is_valid_txn $t $env] TRUE
182
set dbc [eval {$db cursor} $txn]
183
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
185
# OK, now re-put the first key and make sure that we
186
# renumber the last key appropriately.
187
if { [string compare $omethod "-btree"] == 0 } {
188
set ret [eval {$db put} $txn \
189
{$key [chop_data $method $first_key]}]
190
error_check_good db_put $ret 0
193
set ret [$dbc get -first]
194
set ret [eval {$dbc put} $pflags {-before $first_key}]
195
error_check_bad dbc_put:DB_BEFORE $ret 0
198
# Now check that the last record matches the last record number
199
set ret [eval {$db get} $txn $gflags {$last_keynum}]
201
getn_last_after_put [lindex [lindex $ret 0] 1] $last_key
203
# Now delete the first key in the database using a cursor
204
puts "\tTest029.d: delete with cursor and verify renumber"
206
set ret [$dbc get -first]
207
error_check_good dbc_first $ret [list [list $key $first_key]]
209
# Now delete at the cursor
211
error_check_good dbc_del $ret 0
213
# Now check the record numbers of the last keys again.
214
# First try to get the old last key (shouldn't exist)
215
set ret [eval {$db get} $txn $gflags {$last_keynum}]
216
error_check_good get_last_after_cursor_del:$ret $ret [list]
218
# Now try to get what we think should be the last key
219
set ret [eval {$db get} $txn $gflags {[expr $last_keynum - 1]}]
221
getn_after_cursor_del [lindex [lindex $ret 0] 1] $last_key
223
# Re-put the first key and make sure that we renumber the last
225
puts "\tTest029.e: put with cursor and verify renumber"
226
if { [string compare $omethod "-btree"] == 0 } {
227
set ret [eval {$dbc put} \
228
$pflags {-current $first_key}]
229
error_check_good dbc_put:DB_CURRENT $ret 0
231
set ret [eval {$dbc put} $pflags {-before $first_key}]
232
error_check_bad dbc_put:DB_BEFORE $ret 0
235
# Now check that the last record matches the last record number
236
set ret [eval {$db get} $txn $gflags {$last_keynum}]
238
get_after_cursor_reput [lindex [lindex $ret 0] 1] $last_key
240
error_check_good dbc_close [$dbc close] 0
241
if { $txnenv == 1 } {
242
error_check_good txn [$t commit] 0
244
error_check_good db_close [$db close] 0