1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996, 2013 Oracle and/or its affiliates. All rights reserved. 4# 5# $Id$ 6# 7# TEST recd019 8# TEST Test txn id wrap-around and recovery. 9proc recd019 { method {numid 50} args} { 10 global fixed_len 11 global txn_curid 12 global log_log_record_types 13 source ./include.tcl 14 15 set orig_fixed_len $fixed_len 16 set opts [convert_args $method $args] 17 set omethod [convert_method $method] 18 19 puts "Recd019: $method txn id wrap-around test" 20 21 # Create the database and environment. 22 env_cleanup $testdir 23 24 set testfile recd019.db 25 26 set flags "-create -txn wrnosync -home $testdir" 27 28 puts "\tRecd019.a: creating environment" 29 set env_cmd "berkdb_env $flags" 30 set dbenv [eval $env_cmd] 31 error_check_good dbenv [is_valid_env $dbenv] TRUE 32 33 # Test txn wrapping. Force a txn_recycle msg. 34 # 35 set new_curid $txn_curid 36 set new_maxid [expr $new_curid + $numid] 37 error_check_good txn_id_set [$dbenv txn_id_set $new_curid $new_maxid] 0 38 39 # 40 # We need to create a database to get the pagesize (either 41 # the default or whatever might have been specified). 42 # Then remove it so we can compute fixed_len and create the 43 # real database. 44 set oflags "-create $omethod -mode 0644 \ 45 -env $dbenv $opts $testfile" 46 set db [eval {berkdb_open} $oflags] 47 error_check_good db_open [is_valid_db $db] TRUE 48 set stat [$db stat] 49 # 50 # Compute the fixed_len based on the pagesize being used. 51 # We want the fixed_len to be 1/4 the pagesize. 52 # 53 set pg [get_pagesize $stat] 54 error_check_bad get_pagesize $pg -1 55 set fixed_len [expr $pg / 4] 56 error_check_good db_close [$db close] 0 57 error_check_good dbremove [berkdb dbremove -env $dbenv $testfile] 0 58 59 # Convert the args again because fixed_len is now real. 60 # Create the databases and close the environment. 61 # cannot specify db truncate in txn protected env!!! 62 set opts [convert_args $method $args] 63 set omethod [convert_method $method] 64 set oflags "-create $omethod -mode 0644 \ 65 -env $dbenv -auto_commit $opts $testfile" 66 set db [eval {berkdb_open} $oflags] 67 error_check_good db_open [is_valid_db $db] TRUE 68 69 # 70 # Force txn ids to wrap twice and then some. 71 # 72 set nument [expr $numid * 3 - 2] 73 puts "\tRecd019.b: Wrapping txn ids after $numid" 74 set file $testdir/$testfile.init 75 catch { file copy -force $testdir/$testfile $file} res 76 copy_extent_file $testdir $testfile init 77 for { set i 1 } { $i <= $nument } { incr i } { 78 # Use 'i' as key so method doesn't matter 79 set key $i 80 set data $i 81 82 # Put, in a txn. 83 set txn [$dbenv txn] 84 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 85 error_check_good db_put \ 86 [$db put -txn $txn $key [chop_data $method $data]] 0 87 error_check_good txn_commit [$txn commit] 0 88 } 89 error_check_good db_close [$db close] 0 90 set file $testdir/$testfile.afterop 91 catch { file copy -force $testdir/$testfile $file} res 92 copy_extent_file $testdir $testfile afterop 93 error_check_good env_close [$dbenv close] 0 94 95 # Keep track of the log types we've seen 96 if { $log_log_record_types == 1} { 97 logtrack_read $testdir 98 } 99 100 # Now, loop through and recover. 101 puts "\tRecd019.c: Run recovery (no-op)" 102 set ret [catch {exec $util_path/db_recover -h $testdir} r] 103 error_check_good db_recover $ret 0 104 105 puts "\tRecd019.d: Run recovery (initial file)" 106 set file $testdir/$testfile.init 107 catch { file copy -force $file $testdir/$testfile } res 108 move_file_extent $testdir $testfile init copy 109 110 set ret [catch {exec $util_path/db_recover -h $testdir} r] 111 error_check_good db_recover $ret 0 112 113 puts "\tRecd019.e: Run recovery (after file)" 114 set file $testdir/$testfile.afterop 115 catch { file copy -force $file $testdir/$testfile } res 116 move_file_extent $testdir $testfile afterop copy 117 118 set ret [catch {exec $util_path/db_recover -h $testdir} r] 119 error_check_good db_recover $ret 0 120 set fixed_len $orig_fixed_len 121 return 122} 123