drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 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 | # |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 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. |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 17 | # |
| 18 | |
| 19 | set testdir [file dirname $argv0] |
| 20 | source $testdir/tester.tcl |
| 21 | set testprefix wal5 |
| 22 | |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 23 | # POWERSAFE_OVERWRITE defaults to true |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 24 | # |
| 25 | do_test zerodamage-1.0 { |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 26 | file_control_powersafe_overwrite db -1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 27 | } {0 1} |
| 28 | |
| 29 | # Check the ability to turn zero-damage on and off. |
| 30 | # |
| 31 | do_test zerodamage-1.1 { |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 32 | file_control_powersafe_overwrite db 0 |
| 33 | file_control_powersafe_overwrite db -1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 34 | } {0 0} |
| 35 | do_test zerodamage-1.2 { |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 36 | file_control_powersafe_overwrite db 1 |
| 37 | file_control_powersafe_overwrite db -1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 38 | } {0 1} |
| 39 | |
| 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 |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 48 | sqlite3 db file:test.db?psow=TRUE -uri 1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 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 | register_wholenumber_module db |
| 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 | } |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 71 | concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size] |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 72 | } {0 1 2576} |
| 73 | |
| 74 | # Repeat the previous step with zero-damage turned off. This time the |
| 75 | # maximum rollback journal size should be much larger. |
| 76 | # |
| 77 | do_test zerodamage-2.1 { |
| 78 | set ::max_journal_size 0 |
| 79 | db close |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 80 | sqlite3 db file:test.db?psow=FALSE -uri 1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 81 | db eval { |
| 82 | UPDATE t1 SET y=randomblob(50) WHERE x=124; |
| 83 | } |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 84 | concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size] |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 85 | } {0 0 24704} |
| 86 | |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 87 | # Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 88 | # WAL file does not get too big. |
| 89 | # |
| 90 | do_test zerodamage-3.0 { |
| 91 | db eval { |
| 92 | PRAGMA journal_mode=WAL; |
| 93 | } |
| 94 | db close |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 95 | sqlite3 db file:test.db?psow=TRUE -uri 1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 96 | db eval { |
| 97 | UPDATE t1 SET y=randomblob(50) WHERE x=124; |
| 98 | } |
| 99 | file size test.db-wal |
| 100 | } {1080} |
| 101 | |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 102 | # Repeat the previous with POWERSAFE_OVERWRITE off. Verify that the WAL file |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 103 | # is padded. |
| 104 | # |
| 105 | do_test zerodamage-3.1 { |
| 106 | db close |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame^] | 107 | sqlite3 db file:test.db?psow=FALSE -uri 1 |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 108 | db eval { |
| 109 | UPDATE t1 SET y=randomblob(50) WHERE x=124; |
| 110 | } |
| 111 | file size test.db-wal |
| 112 | } {8416} |