recd005.tcl
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:7k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1996, 1997, 1998, 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: recd005.tcl,v 11.27 2000/12/15 21:41:38 ubell Exp $
  7. #
  8. # Recovery Test 5.
  9. # Make sure that we can do catastrophic recovery even if we open
  10. # files using the same log file id.
  11. proc recd005 { method args} {
  12. source ./include.tcl
  13. global rand_init
  14. set args [convert_args $method $args]
  15. set omethod [convert_method $method]
  16. puts "Recd005: $method catastropic recovery"
  17. berkdb srand $rand_init
  18. set testfile1 recd005.1.db
  19. set testfile2 recd005.2.db
  20. set eflags 
  21.     "-create -txn -lock_max 2000 -lock_max_objects 2000 -home $testdir"
  22. set tnum 0
  23. foreach sizes "{1000 10} {10 1000}" {
  24. foreach ops "{abort abort} {abort commit} {commit abort} 
  25. {commit commit}" {
  26. env_cleanup $testdir
  27. incr tnum
  28. set s1 [lindex $sizes 0]
  29. set s2 [lindex $sizes 1]
  30. set op1 [lindex $ops 0]
  31. set op2 [lindex $ops 1]
  32. puts "tRecd005.$tnum: $s1 $s2 $op1 $op2"
  33. puts "tRecd005.$tnum.a: creating environment"
  34. set env_cmd "berkdb env $eflags"
  35. set dbenv [eval $env_cmd]
  36. error_check_bad dbenv $dbenv NULL
  37. # Create the two databases.
  38. set oflags 
  39.     "-create -mode 0644 -env $dbenv $args $omethod"
  40. set db1 [eval {berkdb_open} $oflags $testfile1]
  41. error_check_bad db_open $db1 NULL
  42. error_check_good db_open [is_substr $db1 db] 1
  43. error_check_good db_close [$db1 close] 0
  44. set db2 [eval {berkdb_open} $oflags $testfile2]
  45. error_check_bad db_open $db2 NULL
  46. error_check_good db_open [is_substr $db2 db] 1
  47. error_check_good db_close [$db2 close] 0
  48. $dbenv close
  49. set dbenv [eval $env_cmd]
  50. puts "tRecd005.$tnum.b: Populating databases"
  51. do_one_file 
  52.     $testdir $method $dbenv $env_cmd $testfile1 $s1 $op1
  53. do_one_file 
  54.     $testdir $method $dbenv $env_cmd $testfile2 $s2 $op2
  55. puts "tRecd005.$tnum.c: Verifying initial population"
  56. check_file $testdir $env_cmd $testfile1 $op1
  57. check_file $testdir $env_cmd $testfile2 $op2
  58. # Now, close the environment (so that recovery will work
  59. # on NT which won't allow delete of an open file).
  60. reset_env $dbenv
  61. berkdb debug_check
  62. puts -nonewline 
  63.     "tRecd005.$tnum.d: About to run recovery ... "
  64. flush stdout
  65. set stat [catch 
  66.     {exec $util_path/db_recover -h $testdir -c} 
  67.     result]
  68. if { $stat == 1 } {
  69. error "Recovery error: $result."
  70. }
  71. puts "complete"
  72. # Substitute a file that will need recovery and try
  73. # running recovery again.
  74. if { $op1 == "abort" } {
  75. file copy -force $testdir/$testfile1.afterop 
  76.     $testdir/$testfile1
  77. move_file_extent $testdir $testfile1 
  78.     afterop copy
  79. } else {
  80. file copy -force $testdir/$testfile1.init 
  81.     $testdir/$testfile1
  82. move_file_extent $testdir $testfile1 init copy
  83. }
  84. if { $op2 == "abort" } {
  85. file copy -force $testdir/$testfile2.afterop 
  86.     $testdir/$testfile2
  87. move_file_extent $testdir $testfile2 
  88.     afterop copy
  89. } else {
  90. file copy -force $testdir/$testfile2.init 
  91.     $testdir/$testfile2
  92. move_file_extent $testdir $testfile2 init copy
  93. }
  94. berkdb debug_check
  95. puts -nonewline "tRecd005.$tnum.e:
  96.     About to run recovery on pre-op database ... "
  97. flush stdout
  98. set stat 
  99.     [catch {exec $util_path/db_recover 
  100.     -h $testdir -c} result]
  101. if { $stat == 1 } {
  102. error "Recovery error: $result."
  103. }
  104. puts "complete"
  105. set dbenv [eval $env_cmd]
  106. check_file $testdir $env_cmd $testfile1 $op1
  107. check_file $testdir $env_cmd $testfile2 $op2
  108. reset_env $dbenv
  109. puts "tRecd005.$tnum.f:
  110.     Verify db_printlog can read logfile"
  111. set tmpfile $testdir/printlog.out
  112. set stat [catch 
  113.     {exec $util_path/db_printlog -h $testdir 
  114.     > $tmpfile} ret]
  115. error_check_good db_printlog $stat 0
  116. fileremove $tmpfile
  117. }
  118. }
  119. }
  120. proc do_one_file { dir method env env_cmd filename num op } {
  121. source ./include.tcl
  122. set init_file $dir/$filename.t1
  123. set afterop_file $dir/$filename.t2
  124. set final_file $dir/$filename.t3
  125. # Save the initial file and open the environment and the first file
  126. file copy -force $dir/$filename $dir/$filename.init
  127. copy_extent_file $dir $filename init
  128. set oflags "-unknown -env $env"
  129. set db [eval {berkdb_open} $oflags $filename]
  130. # Dump out file contents for initial case
  131. set tflags ""
  132. open_and_dump_file $filename $env $tflags $init_file nop 
  133.     dump_file_direction "-first" "-next"
  134. set txn [$env txn]
  135. error_check_bad txn_begin $txn NULL
  136. error_check_good txn_begin [is_substr $txn $env] 1
  137. # Now fill in the db and the txnid in the command
  138. populate $db $method $txn $num 0 0
  139. # Sync the file so that we can capture a snapshot to test
  140. # recovery.
  141. error_check_good sync:$db [$db sync] 0
  142. file copy -force $dir/$filename $dir/$filename.afterop
  143. copy_extent_file $dir $filename afterop
  144. open_and_dump_file $testdir/$filename.afterop NULL $tflags 
  145.     $afterop_file nop dump_file_direction "-first" "-next"
  146. error_check_good txn_$op:$txn [$txn $op] 0
  147. if { $op == "commit" } {
  148. puts "ttFile $filename executed and committed."
  149. } else {
  150. puts "ttFile $filename executed and aborted."
  151. }
  152. # Dump out file and save a copy.
  153. error_check_good sync:$db [$db sync] 0
  154. open_and_dump_file $testdir/$filename NULL $tflags $final_file nop 
  155.     dump_file_direction "-first" "-next"
  156. file copy -force $dir/$filename $dir/$filename.final
  157. copy_extent_file $dir $filename final
  158. # If this is an abort, it should match the original file.
  159. # If this was a commit, then this file should match the
  160. # afterop file.
  161. if { $op == "abort" } {
  162. filesort $init_file $init_file.sort
  163. filesort $final_file $final_file.sort
  164. error_check_good 
  165.     diff(initial,post-$op):diff($init_file,$final_file) 
  166.     [filecmp $init_file.sort $final_file.sort] 0
  167. } else {
  168. filesort $afterop_file $afterop_file.sort
  169. filesort $final_file $final_file.sort
  170. error_check_good 
  171.     diff(post-$op,pre-commit):diff($afterop_file,$final_file) 
  172.     [filecmp $afterop_file.sort $final_file.sort] 0
  173. }
  174. error_check_good close:$db [$db close] 0
  175. }
  176. proc check_file { dir env_cmd filename op } {
  177. source ./include.tcl
  178. set init_file $dir/$filename.t1
  179. set afterop_file $dir/$filename.t2
  180. set final_file $dir/$filename.t3
  181. set tflags ""
  182. open_and_dump_file $testdir/$filename NULL $tflags $final_file nop 
  183.     dump_file_direction "-first" "-next"
  184. if { $op == "abort" } {
  185. filesort $init_file $init_file.sort
  186. filesort $final_file $final_file.sort
  187. error_check_good 
  188.     diff(initial,post-$op):diff($init_file,$final_file) 
  189.     [filecmp $init_file.sort $final_file.sort] 0
  190. } else {
  191. filesort $afterop_file $afterop_file.sort
  192. filesort $final_file $final_file.sort
  193. error_check_good 
  194.     diff(pre-commit,post-$op):diff($afterop_file,$final_file) 
  195.     [filecmp $afterop_file.sort $final_file.sort] 0
  196. }
  197. }