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

MySQL数据库

开发平台:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: recd009.tcl,v 1.13 2000/12/07 19:13:46 sue Exp $
  7. #
  8. # Recovery Test 9.
  9. # Test stability of record numbers across splits
  10. # and reverse splits and across recovery.
  11. proc recd009 { method {select 0} args} {
  12. global fixed_len
  13. source ./include.tcl
  14. if { [is_rbtree $method] != 1 && [is_rrecno $method] != 1} {
  15. puts "Recd009 skipping for method $method."
  16. return
  17. }
  18. set opts [convert_args $method $args]
  19. set method [convert_method $method]
  20. puts "tRecd009: Test record numbers across splits and recovery"
  21. set testfile recd009.db
  22. env_cleanup $testdir
  23. set mkeys 1000
  24. set nkeys 5
  25. set data "data"
  26. puts "tRecd009.a: Create $method environment and database."
  27. set flags "-create -txn -home $testdir"
  28. set env_cmd "berkdb env $flags"
  29. set dbenv [eval $env_cmd]
  30. error_check_good dbenv [is_valid_env $dbenv] TRUE
  31. set oflags "-env $dbenv -create -mode 0644 $opts $method"
  32. set db [eval {berkdb_open} $oflags $testfile]
  33. error_check_good dbopen [is_valid_db $db] TRUE
  34. # Fill page with small key/data pairs.  Keep at leaf.
  35. puts "tRecd009.b: Fill page with $nkeys small key/data pairs."
  36. for { set i 1 } { $i <= $nkeys } { incr i } {
  37. if { [is_recno $method] == 1 } {
  38. set key $i
  39. } else {
  40. set key key000$i
  41. }
  42. set ret [$db put $key $data$i]
  43. error_check_good dbput $ret 0
  44. }
  45. error_check_good db_close [$db close] 0
  46. error_check_good env_close [$dbenv close] 0
  47. set newnkeys [expr $nkeys + 1]
  48. # List of recovery tests: {CMD MSG} pairs.
  49. set rlist {
  50. { {recd009_split DB TXNID 1 $method $newnkeys $mkeys}
  51.     "Recd009.c: split"}
  52. { {recd009_split DB TXNID 0 $method $newnkeys $mkeys}
  53.     "Recd009.d: reverse split"}
  54. }
  55. foreach pair $rlist {
  56. set cmd [subst [lindex $pair 0]]
  57. set msg [lindex $pair 1]
  58. if { $select != 0 } {
  59. set tag [lindex $msg 0]
  60. set tail [expr [string length $tag] - 2]
  61. set tag [string range $tag $tail $tail]
  62. if { [lsearch $select $tag] == -1 } {
  63. continue
  64. }
  65. }
  66. set reverse [string first "reverse" $msg]
  67. if { $reverse == -1 } {
  68. set abortkeys $nkeys
  69. set commitkeys $mkeys
  70. set abortpg 0
  71. set commitpg 1
  72. } else {
  73. set abortkeys $mkeys
  74. set commitkeys $nkeys
  75. set abortpg 1
  76. set commitpg 0
  77. }
  78. op_recover abort $testdir $env_cmd $testfile $cmd $msg
  79. recd009_recnocheck $testdir $testfile $opts $abortkeys $abortpg
  80. op_recover commit $testdir $env_cmd $testfile $cmd $msg
  81. recd009_recnocheck $testdir $testfile $opts 
  82.     $commitkeys $commitpg
  83. }
  84. puts "tRecd009.e: Verify db_printlog can read logfile"
  85. set tmpfile $testdir/printlog.out
  86. set stat [catch {exec $util_path/db_printlog -h $testdir 
  87.     > $tmpfile} ret]
  88. error_check_good db_printlog $stat 0
  89. fileremove $tmpfile
  90. }
  91. #
  92. # This procedure verifies that the database has only numkeys number
  93. # of keys and that they are in order.
  94. #
  95. proc recd009_recnocheck { tdir testfile opts numkeys numpg} {
  96. source ./include.tcl
  97. set db [eval {berkdb_open} $opts $tdir/$testfile]
  98. error_check_good dbopen [is_valid_db $db] TRUE
  99. puts "tRecd009_recnocheck: Verify page count of $numpg on split."
  100. set stat [$db stat]
  101. error_check_bad stat:check-split [is_substr $stat 
  102. "{{Internal pages} 0}"] $numpg
  103. set type [$db get_type]
  104. set dbc [$db cursor]
  105. error_check_good dbcursor [is_valid_cursor $dbc $db] TRUE
  106. set i 1
  107. puts "tRecd009_recnocheck: Checking $numkeys record numbers."
  108. for {set d [$dbc get -first]} { [llength $d] != 0 } {
  109.     set d [$dbc get -next]} {
  110. if { [is_btree $type] } {
  111. set thisi [$dbc get -get_recno]
  112. } else {
  113. set thisi [lindex [lindex $d 0] 0]
  114. }
  115. error_check_good recno_check $i $thisi
  116. error_check_good record_count [expr $i <= $numkeys] 1
  117. incr i
  118. }
  119. error_check_good curs_close [$dbc close] 0
  120. error_check_good db_close [$db close] 0
  121. }
  122. proc recd009_split { db txn split method nkeys mkeys } {
  123. global errorCode
  124. source ./include.tcl
  125. set data "data"
  126. set isrecno [is_recno $method]
  127. # if mkeys is above 1000, need to adjust below for lexical order
  128. if { $split == 1 } {
  129. puts "tRecd009_split: Add $mkeys pairs to force split."
  130. for {set i $nkeys} { $i <= $mkeys } { incr i } {
  131. if { $isrecno == 1 } {
  132. set key $i
  133. } else {
  134. if { $i >= 100 } {
  135. set key key0$i
  136. } elseif { $i >= 10 } {
  137. set key key00$i
  138. } else {
  139. set key key000$i
  140. }
  141. }
  142. set ret [$db put -txn $txn $key $data$i]
  143. error_check_good dbput:more $ret 0
  144. }
  145. } else {
  146. puts "tRecd009_split: Delete added keys to force reverse split."
  147. # Since rrecno renumbers, we delete downward.
  148. for {set i $mkeys} { $i >= $nkeys } { set i [expr $i - 1] } {
  149. if { $isrecno == 1 } {
  150. set key $i
  151. } else {
  152. if { $i >= 100 } {
  153. set key key0$i
  154. } elseif { $i >= 10 } {
  155. set key key00$i
  156. } else {
  157. set key key000$i
  158. }
  159. }
  160. error_check_good db_del:$i [$db del -txn $txn $key] 0
  161. }
  162. }
  163. return 0
  164. }