1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996,2008 Oracle. All rights reserved. 4# 5# $Id: recd017.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST recd017 8# TEST Test recovery and security. This is basically a watered 9# TEST down version of recd001 just to verify that encrypted environments 10# TEST can be recovered. 11proc recd017 { method {select 0} args} { 12 global fixed_len 13 global encrypt 14 global passwd 15 global has_crypto 16 source ./include.tcl 17 18 # Skip test if release does not support encryption. 19 if { $has_crypto == 0 } { 20 puts "Skipping recd017 for non-crypto release." 21 return 22 } 23 24 set orig_fixed_len $fixed_len 25 set opts [convert_args $method $args] 26 set omethod [convert_method $method] 27 28 puts "Recd017: $method operation/transaction tests" 29 30 # Create the database and environment. 31 env_cleanup $testdir 32 33 # The recovery tests were originally written to 34 # do a command, abort, do it again, commit, and then 35 # repeat the sequence with another command. Each command 36 # tends to require that the previous command succeeded and 37 # left the database a certain way. To avoid cluttering up the 38 # op_recover interface as well as the test code, we create two 39 # databases; one does abort and then commit for each op, the 40 # other does prepare, prepare-abort, and prepare-commit for each 41 # op. If all goes well, this allows each command to depend 42 # exactly one successful iteration of the previous command. 43 set testfile recd017.db 44 set testfile2 recd017-2.db 45 46 set flags "-create -encryptaes $passwd -txn -home $testdir" 47 48 puts "\tRecd017.a.0: creating environment" 49 set env_cmd "berkdb_env $flags" 50 convert_encrypt $env_cmd 51 set dbenv [eval $env_cmd] 52 error_check_good dbenv [is_valid_env $dbenv] TRUE 53 54 # 55 # We need to create a database to get the pagesize (either 56 # the default or whatever might have been specified). 57 # Then remove it so we can compute fixed_len and create the 58 # real database. 59 set oflags "-create $omethod -mode 0644 \ 60 -env $dbenv -encrypt $opts $testfile" 61 set db [eval {berkdb_open} $oflags] 62 error_check_good db_open [is_valid_db $db] TRUE 63 set stat [$db stat] 64 # 65 # Compute the fixed_len based on the pagesize being used. 66 # We want the fixed_len to be 1/4 the pagesize. 67 # 68 set pg [get_pagesize $stat] 69 error_check_bad get_pagesize $pg -1 70 set fixed_len [expr $pg / 4] 71 error_check_good db_close [$db close] 0 72 error_check_good dbremove [berkdb dbremove -env $dbenv $testfile] 0 73 74 # Convert the args again because fixed_len is now real. 75 # Create the databases and close the environment. 76 # cannot specify db truncate in txn protected env!!! 77 set opts [convert_args $method ""] 78 convert_encrypt $env_cmd 79 set omethod [convert_method $method] 80 set oflags "-create $omethod -mode 0644 \ 81 -env $dbenv -encrypt $opts $testfile" 82 set db [eval {berkdb_open} $oflags] 83 error_check_good db_open [is_valid_db $db] TRUE 84 error_check_good db_close [$db close] 0 85 86 set oflags "-create $omethod -mode 0644 \ 87 -env $dbenv -encrypt $opts $testfile2" 88 set db [eval {berkdb_open} $oflags] 89 error_check_good db_open [is_valid_db $db] TRUE 90 error_check_good db_close [$db close] 0 91 92 error_check_good env_close [$dbenv close] 0 93 94 puts "\tRecd017.a.1: Verify db_printlog can read logfile" 95 set tmpfile $testdir/printlog.out 96 set stat [catch {exec $util_path/db_printlog -h $testdir -P $passwd \ 97 > $tmpfile} ret] 98 error_check_good db_printlog $stat 0 99 fileremove $tmpfile 100 101 # List of recovery tests: {CMD MSG} pairs. 102 set rlist { 103 { {DB put -txn TXNID $key $data} "Recd017.b: put"} 104 { {DB del -txn TXNID $key} "Recd017.c: delete"} 105 } 106 107 # These are all the data values that we're going to need to read 108 # through the operation table and run the recovery tests. 109 110 if { [is_record_based $method] == 1 } { 111 set key 1 112 } else { 113 set key recd017_key 114 } 115 set data recd017_data 116 foreach pair $rlist { 117 set cmd [subst [lindex $pair 0]] 118 set msg [lindex $pair 1] 119 if { $select != 0 } { 120 set tag [lindex $msg 0] 121 set tail [expr [string length $tag] - 2] 122 set tag [string range $tag $tail $tail] 123 if { [lsearch $select $tag] == -1 } { 124 continue 125 } 126 } 127 128 if { [is_queue $method] != 1 } { 129 if { [string first append $cmd] != -1 } { 130 continue 131 } 132 if { [string first consume $cmd] != -1 } { 133 continue 134 } 135 } 136 137# if { [is_fixed_length $method] == 1 } { 138# if { [string first partial $cmd] != -1 } { 139# continue 140# } 141# } 142 op_recover abort $testdir $env_cmd $testfile $cmd $msg 143 op_recover commit $testdir $env_cmd $testfile $cmd $msg 144 # 145 # Note that since prepare-discard ultimately aborts 146 # the txn, it must come before prepare-commit. 147 # 148 op_recover prepare-abort $testdir $env_cmd $testfile2 \ 149 $cmd $msg 150 op_recover prepare-discard $testdir $env_cmd $testfile2 \ 151 $cmd $msg 152 op_recover prepare-commit $testdir $env_cmd $testfile2 \ 153 $cmd $msg 154 } 155 set fixed_len $orig_fixed_len 156 return 157} 158