1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2000-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: recd013.tcl,v 11.14 2001/07/02 16:52:10 krinsky Exp $
9
# Smoke test of aborted cursor adjustments.
12
# Other tests that cover more specific variants of the same issue
13
# are in the access method tests for now. This is probably wrong; we
14
# put this one here because they're closely based on and intertwined
15
# with other, non-transactional cursor stability tests that are among
16
# the access method tests, and because we need at least one test to
17
# fit under recd and keep logtrack from complaining. We'll sort out the mess
18
# later; the important thing, for now, is that everything that needs to gets
19
# tested. (This really shouldn't be under recd at all, since it doesn't
21
proc recd013 { method { nitems 100 } args } {
23
global alphabet log_log_record_types
25
set args [convert_args $method $args]
26
set omethod [convert_method $method]
30
puts "Recd0$tnum $method ($args): Test of aborted cursor adjustments."
31
set pgindex [lsearch -exact $args "-pagesize"]
32
if { $pgindex != -1 } {
33
puts "Recd013: skipping for specific pagesizes"
37
set testfile recd0$tnum.db
41
if { [is_record_based $method] == 1 } {
47
puts "\tRecd0$tnum.a:\
48
Create environment, database, and parent transaction."
49
set flags "-create -txn -home $testdir"
51
set env_cmd "berkdb env $flags"
52
set env [eval $env_cmd]
53
error_check_good dbenv [is_valid_env $env] TRUE
55
set oflags "-env $env -create -mode 0644 -pagesize $pgsz $args $omethod"
56
set db [eval {berkdb_open} $oflags $testfile]
57
error_check_good dbopen [is_valid_db $db] TRUE
59
# Create a database containing $nitems items, numbered with odds.
60
# We'll then put the even numbers during the body of the test.
62
error_check_good init_txn [is_valid_txn $txn $env] TRUE
63
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
65
set data [chop_data $method $i$alphabet]
67
# First, try to put the item in a child transaction,
68
# then abort and verify all the cursors we've done up until
70
set ctxn [$env txn -parent $txn]
71
error_check_good child_txn($i) [is_valid_txn $ctxn $env] TRUE
72
error_check_good fake_put($i) [$db put -txn $ctxn $key $data] 0
73
error_check_good ctxn_abort($i) [$ctxn abort] 0
74
for { set j 1 } { $j < $i } { incr j 2 } {
75
error_check_good dbc_get($j) [$dbc($j) get -current] \
76
[list [list $keybase$j \
77
[pad_data $method $j$alphabet]]]
81
error_check_good init_put($i) [$db put -txn $txn $key $data] 0
83
# Set a cursor of the parent txn to each item.
84
set dbc($i) [$db cursor -txn $txn]
85
error_check_good dbc_getset($i) \
86
[$dbc($i) get -set $key] \
87
[list [list $keybase$i [pad_data $method $i$alphabet]]]
89
# And verify all the cursors, including the one we just
91
for { set j 1 } { $j <= $i } { incr j 2 } {
92
error_check_good dbc_get($j) [$dbc($j) get -current] \
93
[list [list $keybase$j \
94
[pad_data $method $j$alphabet]]]
98
puts "\t\tRecd0$tnum.a.1: Verify cursor stability after init."
99
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
100
error_check_good dbc_get($i) [$dbc($i) get -current] \
101
[list [list $keybase$i [pad_data $method $i$alphabet]]]
104
puts "\tRecd0$tnum.b: Put test."
105
puts "\t\tRecd0$tnum.b.1: Put items."
106
set ctxn [$env txn -parent $txn]
107
error_check_good txn [is_valid_txn $ctxn $env] TRUE
108
for { set i 2 } { $i <= 2 * $nitems } { incr i 2 } {
110
set data [chop_data $method $i$alphabet]
111
error_check_good child_put($i) [$db put -txn $ctxn $key $data] 0
113
# If we're a renumbering recno, this is uninteresting.
114
# Stir things up by putting a few additional records at
116
if { [is_rrecno $method] == 1 } {
117
set curs [$db cursor -txn $ctxn]
118
error_check_bad llength_get_first \
119
[llength [$curs get -first]] 0
120
error_check_good cursor [is_valid_cursor $curs $db] TRUE
122
error_check_good rrecno_put($i) \
123
[$curs put -before ADDITIONAL.$i] 1
124
error_check_good curs_close [$curs close] 0
128
puts "\t\tRecd0$tnum.b.2: Verify cursor stability after abort."
129
error_check_good ctxn_abort [$ctxn abort] 0
131
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
132
error_check_good dbc_get($i) [$dbc($i) get -current] \
133
[list [list $keybase$i [pad_data $method $i$alphabet]]]
137
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
138
error_check_good dbc($i)_close [$dbc($i) close] 0
142
error_check_good txn_commit [$txn commit] 0
144
error_check_good txn [is_valid_txn $txn $env] TRUE
146
error_check_good db_sync [$db sync] 0
147
error_check_good db_verify \
148
[verify_dir $testdir "\t\tRecd0$tnum.b.3: "] 0
150
# Now put back all the even records, this time in the parent.
151
# Commit and re-begin the transaction so we can abort and
152
# get back to a nice full database.
153
for { set i 2 } { $i <= 2 * $nitems } { incr i 2 } {
155
set data [chop_data $method $i$alphabet]
156
error_check_good child_put($i) [$db put -txn $txn $key $data] 0
158
error_check_good txn_commit [$txn commit] 0
160
error_check_good txn [is_valid_txn $txn $env] TRUE
162
# Delete test. Set a cursor to each record. Delete the even ones
163
# in the parent and check cursor stability. Then open a child
164
# transaction, and delete the odd ones. Verify that the database
166
puts "\tRecd0$tnum.c: Delete test."
169
# Create cursors pointing at each item.
170
for { set i 1 } { $i <= 2 * $nitems } { incr i } {
171
set dbc($i) [$db cursor -txn $txn]
172
error_check_good dbc($i)_create [is_valid_cursor $dbc($i) $db] \
174
error_check_good dbc_getset($i) [$dbc($i) get -set $keybase$i] \
175
[list [list $keybase$i [pad_data $method $i$alphabet]]]
178
puts "\t\tRecd0$tnum.c.1: Delete even items in child txn and abort."
180
if { [is_rrecno $method] != 1 } {
182
set bound [expr 2 * $nitems]
185
# In rrecno, deletes will renumber the items, so we have
186
# to take that into account when we delete by recno.
188
set bound [expr $nitems + 1]
192
set ctxn [$env txn -parent $txn]
193
for { set i $init } { $i <= $bound } { incr i $step } {
194
error_check_good del($i) [$db del -txn $ctxn $keybase$i] 0
196
error_check_good ctxn_abort [$ctxn abort] 0
198
# Verify that no items are deleted.
199
for { set i 1 } { $i <= 2 * $nitems } { incr i } {
200
error_check_good dbc_get($i) [$dbc($i) get -current] \
201
[list [list $keybase$i [pad_data $method $i$alphabet]]]
204
puts "\t\tRecd0$tnum.c.2: Delete even items in child txn and commit."
205
set ctxn [$env txn -parent $txn]
206
for { set i $init } { $i <= $bound } { incr i $step } {
207
error_check_good del($i) [$db del -txn $ctxn $keybase$i] 0
209
error_check_good ctxn_commit [$ctxn commit] 0
211
# Verify that even items are deleted and odd items are not.
212
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
213
if { [is_rrecno $method] != 1 } {
216
set j [expr ($i - 1) / 2 + 1]
218
error_check_good dbc_get($i) [$dbc($i) get -current] \
219
[list [list $keybase$j [pad_data $method $i$alphabet]]]
221
for { set i 2 } { $i <= 2 * $nitems } { incr i 2 } {
222
error_check_good dbc_get($i) [$dbc($i) get -current] \
226
puts "\t\tRecd0$tnum.c.3: Delete odd items in child txn."
228
set ctxn [$env txn -parent $txn]
230
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
231
if { [is_rrecno $method] != 1 } {
234
# If this is an rrecno, just delete the first
235
# item repeatedly--the renumbering will make
236
# that delete everything.
239
error_check_good del($i) [$db del -txn $ctxn $keybase$j] 0
242
# Verify that everyone's deleted.
243
for { set i 1 } { $i <= 2 * $nitems } { incr i } {
244
error_check_good get_deleted($i) \
245
[llength [$db get -txn $ctxn $keybase$i]] 0
248
puts "\t\tRecd0$tnum.c.4: Verify cursor stability after abort."
249
error_check_good ctxn_abort [$ctxn abort] 0
251
# Verify that even items are deleted and odd items are not.
252
for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
253
if { [is_rrecno $method] != 1 } {
256
set j [expr ($i - 1) / 2 + 1]
258
error_check_good dbc_get($i) [$dbc($i) get -current] \
259
[list [list $keybase$j [pad_data $method $i$alphabet]]]
261
for { set i 2 } { $i <= 2 * $nitems } { incr i 2 } {
262
error_check_good dbc_get($i) [$dbc($i) get -current] \
267
for { set i 1 } { $i <= 2 * $nitems } { incr i } {
268
error_check_good dbc($i)_close [$dbc($i) close] 0
272
error_check_good db_sync [$db sync] 0
273
error_check_good db_verify \
274
[verify_dir $testdir "\t\tRecd0$tnum.c.5: "] 0
276
puts "\tRecd0$tnum.d: Clean up."
277
error_check_good txn_commit [$txn commit] 0
278
error_check_good db_close [$db close] 0
279
error_check_good env_close [$env close] 0
280
error_check_good verify_dir \
281
[verify_dir $testdir "\t\tRecd0$tnum.d.1: "] 0
283
if { $log_log_record_types == 1 } {
284
logtrack_read $testdir