1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test of DB_CURRENT partial puts onto almost empty duplicate
10
# TEST pages, with and without DB_DUP_SORT.
12
# TEST Test of DB_CURRENT partial puts on almost-empty duplicate pages.
13
# TEST This test was written to address the following issue, #2 in the
14
# TEST list of issues relating to bug #0820:
16
# TEST 2. DBcursor->put, DB_CURRENT flag, off-page duplicates, hash and btree:
17
# TEST In Btree, the DB_CURRENT overwrite of off-page duplicate records
18
# TEST first deletes the record and then puts the new one -- this could
19
# TEST be a problem if the removal of the record causes a reverse split.
20
# TEST Suggested solution is to acquire a cursor to lock down the current
21
# TEST record, put a new record after that record, and then delete using
22
# TEST the held cursor.
24
# TEST It also tests the following, #5 in the same list of issues:
25
# TEST 5. DBcursor->put, DB_AFTER/DB_BEFORE/DB_CURRENT flags, DB_DBT_PARTIAL
26
# TEST set, duplicate comparison routine specified.
27
# TEST The partial change does not change how data items sort, but the
28
# TEST record to be put isn't built yet, and that record supplied is the
29
# TEST one that's checked for ordering compatibility.
30
proc test067 { method {ndups 1000} {tnum 67} args } {
35
set args [convert_args $method $args]
36
set omethod [convert_method $method]
38
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
39
puts "\tTest0$tnum: skipping for method $method."
44
set eindex [lsearch -exact $args "-env"]
46
# If we are using an env, then testfile should just be the db name.
47
# Otherwise it is the test directory and the name.
48
if { $eindex == -1 } {
49
set testfile $testdir/test0$tnum.db
52
set testfile test0$tnum.db
54
set env [lindex $args $eindex]
55
set txnenv [is_txnenv $env]
57
append args " -auto_commit "
58
if { $ndups == 1000 } {
62
set testdir [get_home $env]
66
$method ($args) Partial puts on near-empty duplicate pages."
68
foreach dupopt { "-dup" "-dup -dupsort" } {
70
# Testdir might get reset from the env's home dir back
71
# to the default if this calls something that sources
72
# include.tcl, since testdir is a global. Set it correctly
73
# here each time through the loop.
75
if { $env != "NULL" } {
76
set testdir [get_home $env]
79
set db [eval {berkdb_open -create -mode 0644 \
80
$omethod} $args $dupopt {$testfile}]
81
error_check_good db_open [is_valid_db $db] TRUE
83
puts "\tTest0$tnum.a ($dupopt): Put $ndups duplicates."
85
set key "key_test$tnum"
87
for { set ndx 0 } { $ndx < $ndups } { incr ndx } {
88
set data $alphabet$ndx
92
error_check_good txn [is_valid_txn $t $env] TRUE
95
# No need for pad_data since we're skipping recno.
96
set ret [eval {$db put} $txn {$key $data}]
97
error_check_good put($key,$data) $ret 0
99
error_check_good txn [$t commit] 0
103
# Sync so we can inspect database if the next section bombs.
104
error_check_good db_sync [$db sync] 0
105
puts "\tTest0$tnum.b ($dupopt):\
106
Deleting dups (last first), overwriting each."
108
if { $txnenv == 1 } {
110
error_check_good txn [is_valid_txn $t $env] TRUE
113
set dbc [eval {$db cursor} $txn]
114
error_check_good cursor_create [is_valid_cursor $dbc $db] TRUE
117
while { $count < $ndups - 1 } {
118
# set cursor to last item in db
119
set ret [$dbc get -last]
121
verify_key [lindex [lindex $ret 0] 0] $key
123
# for error reporting
124
set currdatum [lindex [lindex $ret 0] 1]
126
# partial-overwrite it
127
# (overwrite offsets 1-4 with "bcde"--which they
130
# Even though we expect success, we catch this
131
# since it might return EINVAL, and we want that
134
set ret [catch {eval $dbc put -current \
135
{-partial [list 1 4]} "bcde"} \
138
partial_put_valid($currdatum) $errorCode NONE
139
error_check_good partial_put($currdatum) $res 0
142
error_check_good dbc_del [$dbc del] 0
149
error_check_good dbc_close [$dbc close] 0
150
if { $txnenv == 1 } {
151
error_check_good txn [$t commit] 0
153
error_check_good db_close [$db close] 0