1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test086.tcl,v 11.4 2001/05/17 20:37:09 bostic Exp $
8
# Test086: Cursor stability across btree splits w/ subtransaction abort [#2373].
9
proc test086 { method args } {
15
if { [is_btree $method] != 1 } {
16
puts "Test$tstn skipping for method $method."
22
puts "\tTest$tstn: Test of cursor stability across aborted\
30
set eindex [lsearch -exact $args "-env"]
32
# If we are using an env, then this test won't work.
33
if { $eindex == -1 } {
34
# But we will be using our own env...
35
set testfile test0$tstn.db
37
puts "\tTest$tstn: Environment provided; skipping test."
43
set env [berkdb env -create -home $testdir -txn]
44
error_check_good berkdb_env [is_valid_env $env] TRUE
46
puts "\tTest$tstn.a: Create $method database."
47
set oflags "-create -env $env -mode 0644 $args $method"
48
set db [eval {berkdb_open} $oflags $testfile]
49
error_check_good dbopen [is_valid_db $db] TRUE
52
# Fill page w/ small key/data pairs, keep at leaf
54
puts "\tTest$tstn.b: Fill page with $nkeys small key/data pairs."
56
error_check_good txn [is_valid_txn $txn $env] TRUE
57
for { set i 0 } { $i < $nkeys } { incr i } {
58
set ret [$db put -txn $txn key000$i $data$i]
59
error_check_good dbput $ret 0
61
error_check_good commit [$txn commit] 0
63
# get db ordering, set cursors
64
puts "\tTest$tstn.c: Set cursors on each of $nkeys pairs."
66
error_check_good txn [is_valid_txn $txn $env] TRUE
67
for {set i 0; set ret [$db get -txn $txn key000$i]} {\
68
$i < $nkeys && [llength $ret] != 0} {\
69
incr i; set ret [$db get -txn $txn key000$i]} {
70
set key_set($i) [lindex [lindex $ret 0] 0]
71
set data_set($i) [lindex [lindex $ret 0] 1]
72
set dbc [$db cursor -txn $txn]
74
error_check_good db_cursor:$i [is_substr $dbc_set($i) $db] 1
75
set ret [$dbc_set($i) get -set $key_set($i)]
76
error_check_bad dbc_set($i)_get:set [llength $ret] 0
80
set ctxn [$env txn -parent $txn]
81
error_check_good ctxn [is_valid_txn $txn $env] TRUE
83
# if mkeys is above 1000, need to adjust below for lexical order
85
puts "\tTest$tstn.d: Add $mkeys pairs to force split."
86
for {set i $nkeys} { $i < $mkeys } { incr i } {
88
set ret [$db put -txn $ctxn key0$i $data$i]
89
} elseif { $i >= 10 } {
90
set ret [$db put -txn $ctxn key00$i $data$i]
92
set ret [$db put -txn $ctxn key000$i $data$i]
94
error_check_good dbput:more $ret 0
97
puts "\tTest$tstn.e: Abort."
98
error_check_good ctxn_abort [$ctxn abort] 0
100
puts "\tTest$tstn.f: Check and see that cursors maintained reference."
101
for {set i 0} { $i < $nkeys } {incr i} {
102
set ret [$dbc_set($i) get -current]
103
error_check_bad dbc$i:get:current [llength $ret] 0
104
set ret2 [$dbc_set($i) get -set $key_set($i)]
105
error_check_bad dbc$i:get:set [llength $ret2] 0
106
error_check_good dbc$i:get(match) $ret $ret2
109
# Put (and this time keep) the keys that caused the split.
110
# We'll delete them to test reverse splits.
111
puts "\tTest$tstn.g: Put back added keys."
112
for {set i $nkeys} { $i < $mkeys } { incr i } {
114
set ret [$db put -txn $txn key0$i $data$i]
115
} elseif { $i >= 10 } {
116
set ret [$db put -txn $txn key00$i $data$i]
118
set ret [$db put -txn $txn key000$i $data$i]
120
error_check_good dbput:more $ret 0
123
puts "\tTest$tstn.h: Delete added keys to force reverse split."
124
set ctxn [$env txn -parent $txn]
125
error_check_good ctxn [is_valid_txn $txn $env] TRUE
126
for {set i $nkeys} { $i < $mkeys } { incr i } {
128
error_check_good db_del:$i [$db del -txn $ctxn key0$i] 0
129
} elseif { $i >= 10 } {
130
error_check_good db_del:$i \
131
[$db del -txn $ctxn key00$i] 0
133
error_check_good db_del:$i \
134
[$db del -txn $ctxn key000$i] 0
138
puts "\tTest$tstn.i: Abort."
139
error_check_good ctxn_abort [$ctxn abort] 0
141
puts "\tTest$tstn.j: Verify cursor reference."
142
for {set i 0} { $i < $nkeys } {incr i} {
143
set ret [$dbc_set($i) get -current]
144
error_check_bad dbc$i:get:current [llength $ret] 0
145
set ret2 [$dbc_set($i) get -set $key_set($i)]
146
error_check_bad dbc$i:get:set [llength $ret2] 0
147
error_check_good dbc$i:get(match) $ret $ret2
150
puts "\tTest$tstn.j: Cleanup."
152
for {set i 0} { $i < $nkeys } {incr i} {
153
error_check_good dbc_close:$i [$dbc_set($i) close] 0
156
error_check_good commit [$txn commit] 0
157
error_check_good dbclose [$db close] 0
158
error_check_good envclose [$env close] 0
160
puts "\tTest$tstn complete."