zerodamage.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # 2011 December 21
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # This file implements tests of the SQLITE_IOCAP_POWERSAFE_OVERWRITE property
  13. # and the SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control for manipulating it.
  14. #
  15. # The name of this file comes from the fact that we used to call the
  16. # POWERSAFE_OVERWRITE property ZERO_DAMAGE.
  17. #
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. set testprefix zerodamage
  21. ifcapable !vtab {
  22. finish_test
  23. return
  24. }
  25. # POWERSAFE_OVERWRITE defaults to true
  26. #
  27. do_test zerodamage-1.0 {
  28. file_control_powersafe_overwrite db -1
  29. } {0 1}
  30. # Check the ability to turn zero-damage on and off.
  31. #
  32. do_test zerodamage-1.1 {
  33. file_control_powersafe_overwrite db 0
  34. file_control_powersafe_overwrite db -1
  35. } {0 0}
  36. do_test zerodamage-1.2 {
  37. file_control_powersafe_overwrite db 1
  38. file_control_powersafe_overwrite db -1
  39. } {0 1}
  40. # Run a transaction with zero-damage on, a small page size and a much larger
  41. # sectorsize. Verify that the maximum journal size is small - that the
  42. # rollback journal is not being padded.
  43. #
  44. do_test zerodamage-2.0 {
  45. db close
  46. testvfs tv -default 1
  47. tv sectorsize 8192
  48. sqlite3 db file:test.db?psow=TRUE -uri 1
  49. unset -nocomplain ::max_journal_size
  50. set ::max_journal_size 0
  51. proc xDeleteCallback {method file args} {
  52. set sz [file size $file]
  53. if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
  54. }
  55. tv filter xDelete
  56. tv script xDeleteCallback
  57. load_static_extension db wholenumber
  58. db eval {
  59. PRAGMA page_size=1024;
  60. PRAGMA journal_mode=DELETE;
  61. PRAGMA cache_size=5;
  62. CREATE VIRTUAL TABLE nums USING wholenumber;
  63. CREATE TABLE t1(x, y);
  64. INSERT INTO t1 SELECT value, randomblob(100) FROM nums
  65. WHERE value BETWEEN 1 AND 400;
  66. }
  67. set ::max_journal_size 0
  68. db eval {
  69. UPDATE t1 SET y=randomblob(50) WHERE x=123;
  70. }
  71. concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
  72. } {0 1 2576}
  73. # Repeat the previous step with zero-damage turned off. This time the
  74. # maximum rollback journal size should be much larger.
  75. #
  76. do_test zerodamage-2.1 {
  77. set ::max_journal_size 0
  78. db close
  79. sqlite3 db file:test.db?psow=FALSE -uri 1
  80. db eval {
  81. UPDATE t1 SET y=randomblob(50) WHERE x=124;
  82. }
  83. concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
  84. } {0 0 24704}
  85. ifcapable wal {
  86. # Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
  87. # WAL file does not get too big.
  88. #
  89. do_test zerodamage-3.0 {
  90. db eval {
  91. PRAGMA journal_mode=WAL;
  92. }
  93. db close
  94. sqlite3 db file:test.db?psow=TRUE -uri 1
  95. db eval {
  96. UPDATE t1 SET y=randomblob(50) WHERE x=124;
  97. }
  98. file size test.db-wal
  99. } {1080}
  100. # Repeat the previous with POWERSAFE_OVERWRITE off. Verify that the WAL file
  101. # is padded.
  102. #
  103. do_test zerodamage-3.1 {
  104. db close
  105. sqlite3 db file:test.db?psow=FALSE -uri 1
  106. db eval {
  107. UPDATE t1 SET y=randomblob(50) WHERE x=124;
  108. }
  109. file size test.db-wal
  110. } {8416}
  111. }
  112. finish_test