~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/recd014.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 1999-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  recd014
9
 
# TEST  This is a recovery test for create/delete of queue extents.  We
10
 
# TEST  then need to recover and make sure the file is correctly existing
11
 
# TEST  or not, as the case may be.
12
 
proc recd014 { method args} {
13
 
        global fixed_len
14
 
        source ./include.tcl
15
 
 
16
 
        if { ![is_queueext $method] == 1 } {
17
 
                puts "Recd014: Skipping for method $method"
18
 
                return
19
 
        }
20
 
        set pgindex [lsearch -exact $args "-pagesize"]
21
 
        if { $pgindex != -1 } {
22
 
                puts "Recd014: skipping for specific pagesizes"
23
 
                return
24
 
        }
25
 
 
26
 
        set orig_fixed_len $fixed_len
27
 
        #
28
 
        # We will use 512-byte pages, to be able to control
29
 
        # when extents get created/removed.
30
 
        #
31
 
        set fixed_len 300
32
 
 
33
 
        set opts [convert_args $method $args]
34
 
        set omethod [convert_method $method]
35
 
        #
36
 
        # We want to set -extent 1 instead of what
37
 
        # convert_args gave us.
38
 
        #
39
 
        set exti [lsearch -exact $opts "-extent"]
40
 
        incr exti
41
 
        set opts [lreplace $opts $exti $exti 1]
42
 
 
43
 
        puts "Recd014: $method extent creation/deletion tests"
44
 
 
45
 
        # Create the database and environment.
46
 
        env_cleanup $testdir
47
 
 
48
 
        set testfile recd014.db
49
 
        set flags "-create -txn -home $testdir"
50
 
 
51
 
        puts "\tRecd014.a: creating environment"
52
 
        set env_cmd "berkdb_env $flags"
53
 
 
54
 
        puts "\tRecd014.b: Create test commit"
55
 
        ext_recover_create $testdir $env_cmd $omethod \
56
 
            $opts $testfile commit
57
 
        puts "\tRecd014.b: Create test abort"
58
 
        ext_recover_create $testdir $env_cmd $omethod \
59
 
            $opts $testfile abort
60
 
 
61
 
        puts "\tRecd014.c: Consume test commit"
62
 
        ext_recover_consume $testdir $env_cmd $omethod \
63
 
            $opts $testfile commit
64
 
        puts "\tRecd014.c: Consume test abort"
65
 
        ext_recover_consume $testdir $env_cmd $omethod \
66
 
            $opts $testfile abort
67
 
 
68
 
        set fixed_len $orig_fixed_len
69
 
        puts "\tRecd014.d: Verify db_printlog can read logfile"
70
 
        set tmpfile $testdir/printlog.out
71
 
        set stat [catch {exec $util_path/db_printlog -h $testdir \
72
 
            > $tmpfile} ret]
73
 
        error_check_good db_printlog $stat 0
74
 
        fileremove $tmpfile
75
 
}
76
 
 
77
 
proc ext_recover_create { dir env_cmd method opts dbfile txncmd } {
78
 
        global log_log_record_types
79
 
        global fixed_len
80
 
        global alphabet
81
 
        source ./include.tcl
82
 
 
83
 
        # Keep track of the log types we've seen
84
 
        if { $log_log_record_types == 1} {
85
 
                logtrack_read $dir
86
 
        }
87
 
 
88
 
        env_cleanup $dir
89
 
        # Open the environment and set the copy/abort locations
90
 
        set env [eval $env_cmd]
91
 
 
92
 
        set init_file $dir/$dbfile.init
93
 
        set noenvflags "-create $method -mode 0644 -pagesize 512 $opts $dbfile"
94
 
        set oflags "-env $env $noenvflags"
95
 
 
96
 
        set t [$env txn]
97
 
        error_check_good txn_begin [is_valid_txn $t $env] TRUE
98
 
 
99
 
        set ret [catch {eval {berkdb_open} -txn $t $oflags} db]
100
 
        error_check_good txn_commit [$t commit] 0
101
 
 
102
 
        set t [$env txn]
103
 
        error_check_good txn_begin [is_valid_txn $t $env] TRUE
104
 
 
105
 
        #
106
 
        # The command to execute to create an extent is a put.
107
 
        # We are just creating the first one, so our extnum is 0.
108
 
        #
109
 
        set extnum 0
110
 
        set data [chop_data $method [replicate $alphabet 512]]
111
 
        puts "\t\tExecuting command"
112
 
        set putrecno [$db put -txn $t -append $data]
113
 
        error_check_good db_put $putrecno 1
114
 
 
115
 
        # Sync the db so any changes to the file that are
116
 
        # in mpool get written to the disk file before the
117
 
        # diff.
118
 
        puts "\t\tSyncing"
119
 
        error_check_good db_sync [$db sync] 0
120
 
 
121
 
        catch { file copy -force $dir/$dbfile $dir/$dbfile.afterop } res
122
 
        copy_extent_file $dir $dbfile afterop
123
 
 
124
 
        error_check_good txn_$txncmd:$t [$t $txncmd] 0
125
 
        #
126
 
        # If we don't abort, then we expect success.
127
 
        # If we abort, we expect no file created.
128
 
        #
129
 
        set dbq [make_ext_filename $dir $dbfile $extnum]
130
 
        error_check_good extput:exists1 [file exists $dbq] 1
131
 
        set ret [$db get $putrecno]
132
 
        if {$txncmd == "abort"} {
133
 
                #
134
 
                # Operation was aborted.   Verify our entry is not there.
135
 
                #
136
 
                puts "\t\tCommand executed and aborted."
137
 
                error_check_good db_get [llength $ret] 0
138
 
        } else {
139
 
                #
140
 
                # Operation was committed, verify it exists.
141
 
                #
142
 
                puts "\t\tCommand executed and committed."
143
 
                error_check_good db_get [llength $ret] 1
144
 
                catch { file copy -force $dir/$dbfile $init_file } res
145
 
                copy_extent_file $dir $dbfile init
146
 
        }
147
 
        set t [$env txn]
148
 
        error_check_good txn_begin [is_valid_txn $t $env] TRUE
149
 
        error_check_good db_close [$db close] 0
150
 
        error_check_good txn_commit [$t commit] 0
151
 
        error_check_good env_close [$env close] 0
152
 
 
153
 
        #
154
 
        # Run recovery here.  Should be a no-op.  Verify that
155
 
        # the file still does/n't exist when we are done.
156
 
        #
157
 
        berkdb debug_check
158
 
        puts -nonewline "\t\tAbout to run recovery (no-op) ... "
159
 
        flush stdout
160
 
 
161
 
        set stat [catch {exec $util_path/db_recover -h $dir -c} result]
162
 
        if { $stat == 1 } {
163
 
                error "FAIL: Recovery error: $result."
164
 
                return
165
 
        }
166
 
        puts "complete"
167
 
        #
168
 
        # Verify it did not change.
169
 
        #
170
 
        error_check_good extput:exists2 [file exists $dbq] 1
171
 
        ext_create_check $dir $txncmd $init_file $dbfile $noenvflags $putrecno
172
 
 
173
 
        #
174
 
        # Need a new copy to get the right LSN into the file.
175
 
        #
176
 
        catch { file copy -force $dir/$dbfile $init_file } res
177
 
        copy_extent_file $dir $dbfile init
178
 
 
179
 
        #
180
 
        # Undo.
181
 
        # Now move the .afterop file to $dbfile.  Run recovery again.
182
 
        #
183
 
        file copy -force $dir/$dbfile.afterop $dir/$dbfile
184
 
        move_file_extent $dir $dbfile afterop copy
185
 
 
186
 
        berkdb debug_check
187
 
        puts -nonewline "\t\tAbout to run recovery (afterop) ... "
188
 
        flush stdout
189
 
 
190
 
        set stat [catch {exec $util_path/db_recover -h $dir -c} result]
191
 
        if { $stat == 1 } {
192
 
                error "FAIL: Recovery error: $result."
193
 
                return
194
 
        }
195
 
        puts "complete"
196
 
        ext_create_check $dir $txncmd $init_file $dbfile $noenvflags $putrecno
197
 
 
198
 
        #
199
 
        # To redo, remove the dbfiles.  Run recovery again.
200
 
        #
201
 
        catch { file rename -force $dir/$dbfile $dir/$dbfile.renamed } res
202
 
        copy_extent_file $dir $dbfile renamed rename
203
 
 
204
 
        berkdb debug_check
205
 
        puts -nonewline "\t\tAbout to run recovery (init) ... "
206
 
        flush stdout
207
 
 
208
 
        set stat [catch {exec $util_path/db_recover -h $dir -c} result]
209
 
        #
210
 
        # !!!
211
 
        # Even though db_recover exits with status 0, it should print out
212
 
        # a warning because the file didn't exist.  Db_recover writes this
213
 
        # to stderr.  Tcl assumes that ANYTHING written to stderr is an
214
 
        # error, so even though we exit with 0 status, we still get an
215
 
        # error back from 'catch'.  Look for the warning.
216
 
        #
217
 
        if { $stat == 1 && [is_substr $result "warning"] == 0 } {
218
 
                error "FAIL: Recovery error: $result."
219
 
                return
220
 
        }
221
 
        puts "complete"
222
 
 
223
 
        #
224
 
        # Verify it was redone.  However, since we removed the files
225
 
        # to begin with, recovery with abort will not recreate the
226
 
        # extent.  Recovery with commit will.
227
 
        #
228
 
        if {$txncmd == "abort"} {
229
 
                error_check_good extput:exists3 [file exists $dbq] 0
230
 
        } else {
231
 
                error_check_good extput:exists3 [file exists $dbq] 1
232
 
        }
233
 
}
234
 
 
235
 
proc ext_create_check { dir txncmd init_file dbfile oflags putrecno } {
236
 
        if { $txncmd == "commit" } {
237
 
                #
238
 
                # Operation was committed. Verify it did not change.
239
 
                #
240
 
                error_check_good \
241
 
                    diff(initial,post-recover2):diff($init_file,$dir/$dbfile) \
242
 
                    [dbdump_diff "-dar" $init_file $dir $dbfile] 0
243
 
        } else {
244
 
                #
245
 
                # Operation aborted.  The file is there, but make
246
 
                # sure the item is not.
247
 
                #
248
 
                set xdb [eval {berkdb_open} $oflags]
249
 
                error_check_good db_open [is_valid_db $xdb] TRUE
250
 
                set ret [$xdb get $putrecno]
251
 
                error_check_good db_get [llength $ret] 0
252
 
                error_check_good db_close [$xdb close] 0
253
 
        }
254
 
}
255
 
 
256
 
proc ext_recover_consume { dir env_cmd method opts dbfile txncmd} {
257
 
        global log_log_record_types
258
 
        global alphabet
259
 
        source ./include.tcl
260
 
 
261
 
        # Keep track of the log types we've seen
262
 
        if { $log_log_record_types == 1} {
263
 
                logtrack_read $dir
264
 
        }
265
 
 
266
 
        env_cleanup $dir
267
 
        # Open the environment and set the copy/abort locations
268
 
        set env [eval $env_cmd]
269
 
 
270
 
        set oflags "-create -auto_commit $method -mode 0644 -pagesize 512 \
271
 
           -env $env $opts $dbfile"
272
 
 
273
 
        #
274
 
        # Open our db, add some data, close and copy as our
275
 
        # init file.
276
 
        #
277
 
        set db [eval {berkdb_open} $oflags]
278
 
        error_check_good db_open [is_valid_db $db] TRUE
279
 
 
280
 
        set extnum 0
281
 
        set data [chop_data $method [replicate $alphabet 512]]
282
 
 
283
 
        set txn [$env txn]
284
 
        error_check_good txn_begin [is_valid_txn $txn $env] TRUE
285
 
        set putrecno [$db put -txn $txn -append $data]
286
 
        error_check_good db_put $putrecno 1
287
 
        error_check_good commit [$txn commit] 0
288
 
        error_check_good db_close [$db close] 0
289
 
 
290
 
        puts "\t\tExecuting command"
291
 
 
292
 
        set init_file $dir/$dbfile.init
293
 
        catch { file copy -force $dir/$dbfile $init_file } res
294
 
        copy_extent_file $dir $dbfile init
295
 
 
296
 
        #
297
 
        # If we don't abort, then we expect success.
298
 
        # If we abort, we expect no file removed until recovery is run.
299
 
        #
300
 
        set db [eval {berkdb_open} $oflags]
301
 
        error_check_good db_open [is_valid_db $db] TRUE
302
 
 
303
 
        set t [$env txn]
304
 
        error_check_good txn_begin [is_valid_txn $t $env] TRUE
305
 
 
306
 
        set dbcmd "$db get -txn $t -consume"
307
 
        set ret [eval $dbcmd]
308
 
        error_check_good db_sync [$db sync] 0
309
 
 
310
 
        catch { file copy -force $dir/$dbfile $dir/$dbfile.afterop } res
311
 
        copy_extent_file $dir $dbfile afterop
312
 
 
313
 
        error_check_good txn_$txncmd:$t [$t $txncmd] 0
314
 
        error_check_good db_sync [$db sync] 0
315
 
        set dbq [make_ext_filename $dir $dbfile $extnum]
316
 
        if {$txncmd == "abort"} {
317
 
                #
318
 
                # Operation was aborted, verify ext did not change.
319
 
                #
320
 
                puts "\t\tCommand executed and aborted."
321
 
 
322
 
                #
323
 
                # Check that the file exists.  Final state.
324
 
                # Since we aborted the txn, we should be able
325
 
                # to get to our original entry.
326
 
                #
327
 
                error_check_good postconsume.1 [file exists $dbq] 1
328
 
                error_check_good \
329
 
                    diff(init,postconsume.2):diff($init_file,$dir/$dbfile)\
330
 
                    [dbdump_diff "-dar" $init_file $dir $dbfile] 0
331
 
        } else {
332
 
                #
333
 
                # Operation was committed, verify it does
334
 
                # not exist.
335
 
                #
336
 
                puts "\t\tCommand executed and committed."
337
 
                #
338
 
                # Check file existence.  Consume operations remove
339
 
                # the extent when we move off, which we should have
340
 
                # done.
341
 
                error_check_good consume_exists [file exists $dbq] 0
342
 
        }
343
 
        error_check_good db_close [$db close] 0
344
 
        error_check_good env_close [$env close] 0
345
 
 
346
 
        #
347
 
        # Run recovery here on what we ended up with.  Should be a no-op.
348
 
        #
349
 
        berkdb debug_check
350
 
        puts -nonewline "\t\tAbout to run recovery (no-op) ... "
351
 
        flush stdout
352
 
 
353
 
        set stat [catch {exec $util_path/db_recover -h $dir -c} result]
354
 
        if { $stat == 1 } {
355
 
                error "FAIL: Recovery error: $result."
356
 
                return
357
 
        }
358
 
        puts "complete"
359
 
        if { $txncmd == "abort"} {
360
 
                #
361
 
                # Operation was aborted, verify it did not change.
362
 
                #
363
 
                error_check_good \
364
 
                    diff(initial,post-recover1):diff($init_file,$dir/$dbfile) \
365
 
                    [dbdump_diff "-dar" $init_file $dir $dbfile] 0
366
 
        } else {
367
 
                #
368
 
                # Operation was committed, verify it does
369
 
                # not exist.  Both operations should result
370
 
                # in no file existing now that we've run recovery.
371
 
                #
372
 
                error_check_good after_recover1 [file exists $dbq] 0
373
 
        }
374
 
 
375
 
        #
376
 
        # Run recovery here. Re-do the operation.
377
 
        # Verify that the file doesn't exist
378
 
        # (if we committed)  or change (if we aborted)
379
 
        # when we are done.
380
 
        #
381
 
        catch { file copy -force $dir/$dbfile $init_file } res
382
 
        copy_extent_file $dir $dbfile init
383
 
        berkdb debug_check
384
 
        puts -nonewline "\t\tAbout to run recovery (init) ... "
385
 
        flush stdout
386
 
 
387
 
        set stat [catch {exec $util_path/db_recover -h $dir -c} result]
388
 
        if { $stat == 1 } {
389
 
                error "FAIL: Recovery error: $result."
390
 
                return
391
 
        }
392
 
        puts "complete"
393
 
        if { $txncmd == "abort"} {
394
 
                #
395
 
                # Operation was aborted, verify it did not change.
396
 
                #
397
 
                error_check_good \
398
 
                    diff(initial,post-recover1):diff($init_file,$dir/$dbfile) \
399
 
                    [dbdump_diff "-dar" $init_file $dir $dbfile] 0
400
 
        } else {
401
 
                #
402
 
                # Operation was committed, verify it does
403
 
                # not exist.  Both operations should result
404
 
                # in no file existing now that we've run recovery.
405
 
                #
406
 
                error_check_good after_recover2 [file exists $dbq] 0
407
 
        }
408
 
 
409
 
        #
410
 
        # Now move the .afterop file to $dbfile.  Run recovery again.
411
 
        #
412
 
        set filecopy [glob $dir/*.afterop]
413
 
        set afterop [lindex $filecopy 0]
414
 
        file rename -force $afterop $dir/$dbfile
415
 
        set afterop [string range $afterop \
416
 
            [expr [string last "/" $afterop] + 1]  \
417
 
            [string last "." $afterop]]
418
 
        move_file_extent $dir $dbfile afterop rename
419
 
 
420
 
        berkdb debug_check
421
 
        puts -nonewline "\t\tAbout to run recovery (afterop) ... "
422
 
        flush stdout
423
 
 
424
 
        set stat [catch {exec $util_path/db_recover -h $dir -c} result]
425
 
        if { $stat == 1 } {
426
 
                error "FAIL: Recovery error: $result."
427
 
                return
428
 
        }
429
 
        puts "complete"
430
 
 
431
 
        if { $txncmd == "abort"} {
432
 
                #
433
 
                # Operation was aborted, verify it did not change.
434
 
                #
435
 
                error_check_good \
436
 
                    diff(initial,post-recover2):diff($init_file,$dir/$dbfile) \
437
 
                    [dbdump_diff "-dar" $init_file $dir $dbfile] 0
438
 
        } else {
439
 
                #
440
 
                # Operation was committed, verify it still does
441
 
                # not exist.
442
 
                #
443
 
                error_check_good after_recover3 [file exists $dbq] 0
444
 
        }
445
 
}