1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test of DB->stat(DB_FASTSTAT)
10
proc test065 { method args } {
16
set args [convert_args $method $args]
17
set omethod [convert_method $method]
21
set eindex [lsearch -exact $args "-env"]
23
# If we are using an env, then testfile should just be the db name.
24
# Otherwise it is the test directory and the name.
25
if { $eindex == -1 } {
26
set testfile $testdir/test0$tnum.db
29
set testfile test0$tnum.db
31
set env [lindex $args $eindex]
32
set txnenv [is_txnenv $env]
34
append args " -auto_commit "
36
# If we are using txns and running with the
37
# default, set the default down a bit.
39
if { $nentries == 10000 } {
43
set testdir [get_home $env]
47
puts "Test0$tnum: $method ($args) DB->stat(DB_FAST_STAT) test."
49
puts "\tTest0$tnum.a: Create database and check it while empty."
51
set db [eval {berkdb_open_noerr -create -mode 0644} \
52
$omethod $args $testfile]
53
error_check_good db_open [is_valid_db $db] TRUE
55
set ret [catch {eval $db stat -faststat} res]
57
error_check_good db_close [$db close] 0
59
if { ([is_record_based $method] && ![is_queue $method]) \
60
|| [is_rbtree $method] } {
61
error_check_good recordcount_ok [is_substr $res \
62
"{{Number of keys} 0}"] 1
64
puts "\tTest0$tnum: Test complete for method $method."
68
# If we've got this far, we're on an access method for
69
# which record counts makes sense. Thus, we no longer
70
# catch EINVALs, and no longer care about __db_errs.
71
set db [eval {berkdb_open -create -mode 0644} $omethod $args $testfile]
73
puts "\tTest0$tnum.b: put $nentries keys."
75
if { [is_record_based $method] } {
84
set data [pad_data $method $alphabet]
86
for { set ndx 1 } { $ndx <= $nentries } { incr ndx } {
89
error_check_good txn [is_valid_txn $t $env] TRUE
92
set ret [eval {$db put} $txn {$keypfx$ndx $data}]
93
error_check_good db_put $ret 0
95
error_check_good txn [$t commit] 0
99
set ret [$db stat -faststat]
100
error_check_good recordcount_after_puts \
101
[is_substr $ret "{{Number of keys} $nentries}"] 1
103
puts "\tTest0$tnum.c: delete 90% of keys."
104
set end [expr {$nentries / 10 * 9}]
105
for { set ndx 1 } { $ndx <= $end } { incr ndx } {
106
if { $txnenv == 1 } {
108
error_check_good txn [is_valid_txn $t $env] TRUE
111
if { [is_rrecno $method] == 1 } {
112
# if we're renumbering, when we hit key 5001 we'll
113
# have deleted 5000 and we'll croak! So delete key
115
set ret [eval {$db del} $txn {[concat $keypfx 1]}]
117
set ret [eval {$db del} $txn {$keypfx$ndx}]
119
error_check_good db_del $ret 0
120
if { $txnenv == 1 } {
121
error_check_good txn [$t commit] 0
125
set ret [$db stat -faststat]
126
if { [is_rrecno $method] == 1 || [is_rbtree $method] == 1 } {
127
# We allow renumbering--thus the stat should return 10%
129
error_check_good recordcount_after_dels [is_substr $ret \
130
"{{Number of keys} [expr {$nentries / 10}]}"] 1
132
# No renumbering--no change in RECORDCOUNT!
133
error_check_good recordcount_after_dels \
134
[is_substr $ret "{{Number of keys} $nentries}"] 1
137
puts "\tTest0$tnum.d: put new keys at the beginning."
138
set end [expr {$nentries / 10 * 8}]
139
for { set ndx 1 } { $ndx <= $end } {incr ndx } {
140
if { $txnenv == 1 } {
142
error_check_good txn [is_valid_txn $t $env] TRUE
145
set ret [eval {$db put} $txn {$keypfx$ndx $data}]
146
error_check_good db_put_beginning $ret 0
147
if { $txnenv == 1 } {
148
error_check_good txn [$t commit] 0
152
set ret [$db stat -faststat]
153
if { [is_rrecno $method] == 1 } {
154
# With renumbering we're back up to 80% of $nentries
155
error_check_good recordcount_after_dels [is_substr $ret \
156
"{{Number of keys} [expr {$nentries / 10 * 8}]}"] 1
157
} elseif { [is_rbtree $method] == 1 } {
158
# Total records in a btree is now 90% of $nentries
159
error_check_good recordcount_after_dels [is_substr $ret \
160
"{{Number of keys} [expr {$nentries / 10 * 9}]}"] 1
162
# No renumbering--still no change in RECORDCOUNT.
163
error_check_good recordcount_after_dels [is_substr $ret \
164
"{{Number of keys} $nentries}"] 1
167
puts "\tTest0$tnum.e: put new keys at the end."
168
set start [expr {1 + $nentries / 10 * 9}]
169
set end [expr {($nentries / 10 * 9) + ($nentries / 10 * 8)}]
170
for { set ndx $start } { $ndx <= $end } { incr ndx } {
171
if { $txnenv == 1 } {
173
error_check_good txn [is_valid_txn $t $env] TRUE
176
set ret [eval {$db put} $txn {$keypfx$ndx $data}]
177
error_check_good db_put_end $ret 0
178
if { $txnenv == 1 } {
179
error_check_good txn [$t commit] 0
183
set ret [$db stat -faststat]
184
if { [is_rbtree $method] != 1 } {
185
# If this is a recno database, the record count should be up
186
# to (1.7 x nentries), the largest number we've seen, with
187
# or without renumbering.
188
error_check_good recordcount_after_puts2 [is_substr $ret \
189
"{{Number of keys} [expr {$start - 1 + $nentries / 10 * 8}]}"] 1
191
# In an rbtree, 1000 of those keys were overwrites, so there
192
# are (.7 x nentries) new keys and (.9 x nentries) old keys
193
# for a total of (1.6 x nentries).
194
error_check_good recordcount_after_puts2 [is_substr $ret \
195
"{{Number of keys} [expr {$start -1 + $nentries / 10 * 7}]}"] 1
198
error_check_good db_close [$db close] 0