~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/recd013.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 2000-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: recd013.tcl,v 11.14 2001/07/02 16:52:10 krinsky Exp $
 
7
#
 
8
# Recovery Test 13.
 
9
# Smoke test of aborted cursor adjustments.
 
10
#
 
11
# XXX
 
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
 
20
# run recovery!)
 
21
proc recd013 { method { nitems 100 } args } {
 
22
        source ./include.tcl
 
23
        global alphabet log_log_record_types
 
24
 
 
25
        set args [convert_args $method $args]
 
26
        set omethod [convert_method $method]
 
27
        set tnum 13
 
28
        set pgsz 512
 
29
 
 
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"
 
34
                return
 
35
        }
 
36
 
 
37
        set testfile recd0$tnum.db
 
38
        env_cleanup $testdir
 
39
 
 
40
        set i 0
 
41
        if { [is_record_based $method] == 1 } {
 
42
                set keybase ""
 
43
        } else {
 
44
                set keybase "key"
 
45
        }
 
46
 
 
47
        puts "\tRecd0$tnum.a:\
 
48
            Create environment, database, and parent transaction."
 
49
        set flags "-create -txn -home $testdir"
 
50
 
 
51
        set env_cmd "berkdb env $flags"
 
52
        set env [eval $env_cmd]
 
53
        error_check_good dbenv [is_valid_env $env] TRUE
 
54
 
 
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
 
58
 
 
59
        # Create a database containing $nitems items, numbered with odds.
 
60
        # We'll then put the even numbers during the body of the test.
 
61
        set txn [$env txn]
 
62
        error_check_good init_txn [is_valid_txn $txn $env] TRUE
 
63
        for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
 
64
                set key $keybase$i
 
65
                set data [chop_data $method $i$alphabet]
 
66
 
 
67
                # First, try to put the item in a child transaction,
 
68
                # then abort and verify all the cursors we've done up until
 
69
                # now.
 
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]]]
 
78
                }
 
79
 
 
80
                # Then put for real.
 
81
                error_check_good init_put($i) [$db put -txn $txn $key $data] 0
 
82
 
 
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]]]
 
88
 
 
89
                # And verify all the cursors, including the one we just
 
90
                # created.
 
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]]]
 
95
                }
 
96
        }
 
97
 
 
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]]]
 
102
        }
 
103
 
 
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 } {
 
109
                set key $keybase$i
 
110
                set data [chop_data $method $i$alphabet]
 
111
                error_check_good child_put($i) [$db put -txn $ctxn $key $data] 0
 
112
 
 
113
                # If we're a renumbering recno, this is uninteresting.
 
114
                # Stir things up by putting a few additional records at
 
115
                # the beginning.
 
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
 
121
                        # expect a recno!
 
122
                        error_check_good rrecno_put($i) \
 
123
                            [$curs put -before ADDITIONAL.$i] 1
 
124
                        error_check_good curs_close [$curs close] 0
 
125
                }
 
126
        }
 
127
 
 
128
        puts "\t\tRecd0$tnum.b.2: Verify cursor stability after abort."
 
129
        error_check_good ctxn_abort [$ctxn abort] 0
 
130
 
 
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]]]
 
134
        }
 
135
 
 
136
        # Clean up cursors.
 
137
        for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
 
138
                error_check_good dbc($i)_close [$dbc($i) close] 0
 
139
        }
 
140
 
 
141
        # Sync and verify.
 
142
        error_check_good txn_commit [$txn commit] 0
 
143
        set txn [$env txn]
 
144
        error_check_good txn [is_valid_txn $txn $env] TRUE
 
145
 
 
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
 
149
 
 
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 } {
 
154
                set key $keybase$i
 
155
                set data [chop_data $method $i$alphabet]
 
156
                error_check_good child_put($i) [$db put -txn $txn $key $data] 0
 
157
        }
 
158
        error_check_good txn_commit [$txn commit] 0
 
159
        set txn [$env txn]
 
160
        error_check_good txn [is_valid_txn $txn $env] TRUE
 
161
 
 
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
 
165
        # is empty.
 
166
        puts "\tRecd0$tnum.c: Delete test."
 
167
        unset dbc
 
168
 
 
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] \
 
173
                    TRUE
 
174
                error_check_good dbc_getset($i) [$dbc($i) get -set $keybase$i] \
 
175
                    [list [list $keybase$i [pad_data $method $i$alphabet]]]
 
176
        }
 
177
 
 
178
        puts "\t\tRecd0$tnum.c.1: Delete even items in child txn and abort."
 
179
 
 
180
        if { [is_rrecno $method] != 1 } {
 
181
                set init 2
 
182
                set bound [expr 2 * $nitems]
 
183
                set step 2
 
184
        } else {
 
185
                # In rrecno, deletes will renumber the items, so we have
 
186
                # to take that into account when we delete by recno.
 
187
                set init 2
 
188
                set bound [expr $nitems + 1]
 
189
                set step 1
 
190
        }
 
191
 
 
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
 
195
        }
 
196
        error_check_good ctxn_abort [$ctxn abort] 0
 
197
 
 
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]]]
 
202
        }
 
203
 
 
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
 
208
        }
 
209
        error_check_good ctxn_commit [$ctxn commit] 0
 
210
 
 
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 } {
 
214
                        set j $i
 
215
                } else {
 
216
                        set j [expr ($i - 1) / 2 + 1]
 
217
                }
 
218
                error_check_good dbc_get($i) [$dbc($i) get -current] \
 
219
                    [list [list $keybase$j [pad_data $method $i$alphabet]]]
 
220
        }
 
221
        for { set i 2 } { $i <= 2 * $nitems } { incr i 2 } {
 
222
                error_check_good dbc_get($i) [$dbc($i) get -current] \
 
223
                    [list [list "" ""]]
 
224
        }
 
225
 
 
226
        puts "\t\tRecd0$tnum.c.3: Delete odd items in child txn."
 
227
 
 
228
        set ctxn [$env txn -parent $txn]
 
229
 
 
230
        for { set i 1 } { $i <= 2 * $nitems } { incr i 2 } {
 
231
                if { [is_rrecno $method] != 1 } {
 
232
                        set j $i
 
233
                } else {
 
234
                        # If this is an rrecno, just delete the first
 
235
                        # item repeatedly--the renumbering will make
 
236
                        # that delete everything.
 
237
                        set j 1
 
238
                }
 
239
                error_check_good del($i) [$db del -txn $ctxn $keybase$j] 0
 
240
        }
 
241
 
 
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
 
246
        }
 
247
 
 
248
        puts "\t\tRecd0$tnum.c.4: Verify cursor stability after abort."
 
249
        error_check_good ctxn_abort [$ctxn abort] 0
 
250
 
 
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 } {
 
254
                        set j $i
 
255
                } else {
 
256
                        set j [expr ($i - 1) / 2 + 1]
 
257
                }
 
258
                error_check_good dbc_get($i) [$dbc($i) get -current] \
 
259
                    [list [list $keybase$j [pad_data $method $i$alphabet]]]
 
260
        }
 
261
        for { set i 2 } { $i <= 2 * $nitems } { incr i 2 } {
 
262
                error_check_good dbc_get($i) [$dbc($i) get -current] \
 
263
                    [list [list "" ""]]
 
264
        }
 
265
 
 
266
        # Clean up cursors.
 
267
        for { set i 1 } { $i <= 2 * $nitems } { incr i } {
 
268
                error_check_good dbc($i)_close [$dbc($i) close] 0
 
269
        }
 
270
 
 
271
        # Sync and verify.
 
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
 
275
 
 
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
 
282
 
 
283
        if { $log_log_record_types == 1 } {
 
284
                logtrack_read $testdir
 
285
        }
 
286
}