dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 1 | # 2010 July 28 |
| 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 | |
| 13 | set testdir [file dirname $argv0] |
| 14 | source $testdir/tester.tcl |
| 15 | |
dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 16 | file_control_chunksize_test db main [expr 1024*1024] |
| 17 | |
| 18 | do_test fallocate-1.1 { |
| 19 | execsql { |
| 20 | PRAGMA page_size = 1024; |
| 21 | PRAGMA auto_vacuum = 1; |
| 22 | CREATE TABLE t1(a, b); |
| 23 | } |
| 24 | file size test.db |
| 25 | } [expr 1*1024*1024] |
| 26 | |
| 27 | do_test fallocate-1.2 { |
| 28 | execsql { INSERT INTO t1 VALUES(1, zeroblob(1024*900)) } |
| 29 | file size test.db |
| 30 | } [expr 1*1024*1024] |
| 31 | |
| 32 | do_test fallocate-1.3 { |
| 33 | execsql { INSERT INTO t1 VALUES(2, zeroblob(1024*900)) } |
| 34 | file size test.db |
| 35 | } [expr 2*1024*1024] |
| 36 | |
| 37 | do_test fallocate-1.4 { |
| 38 | execsql { DELETE FROM t1 WHERE a = 1 } |
| 39 | file size test.db |
| 40 | } [expr 1*1024*1024] |
| 41 | |
| 42 | do_test fallocate-1.5 { |
| 43 | execsql { DELETE FROM t1 WHERE a = 2 } |
| 44 | file size test.db |
| 45 | } [expr 1*1024*1024] |
| 46 | |
| 47 | do_test fallocate-1.6 { |
| 48 | execsql { PRAGMA freelist_count } |
| 49 | } {0} |
| 50 | |
dan | 502019c | 2010-07-28 14:26:17 +0000 | [diff] [blame] | 51 | # Start a write-transaction and read the "database file size" field from |
| 52 | # the journal file. This field should be set to the number of pages in |
| 53 | # the database file based on the size of the file on disk, not the actual |
| 54 | # logical size of the database within the file. |
| 55 | # |
| 56 | # We need to check this to verify that if in the unlikely event a rollback |
| 57 | # causes a database file to grow, the database grows to its previous size |
| 58 | # on disk, not to the minimum size required to hold the database image. |
| 59 | # |
| 60 | do_test fallocate-1.7 { |
| 61 | execsql { BEGIN; INSERT INTO t1 VALUES(1, 2); } |
dan | 4da30f8 | 2017-07-22 16:58:47 +0000 | [diff] [blame] | 62 | if {[permutation] != "inmemory_journal" |
| 63 | && [permutation] != "atomic-batch-write" |
dan | 69aedc8 | 2018-01-13 13:07:49 +0000 | [diff] [blame] | 64 | && [atomic_batch_write test.db]==0 |
dan | 4da30f8 | 2017-07-22 16:58:47 +0000 | [diff] [blame] | 65 | } { |
dan | 4f7b8d6 | 2010-08-06 14:37:13 +0000 | [diff] [blame] | 66 | hexio_get_int [hexio_read test.db-journal 16 4] |
| 67 | } else { |
| 68 | set {} 1024 |
| 69 | } |
dan | 502019c | 2010-07-28 14:26:17 +0000 | [diff] [blame] | 70 | } {1024} |
| 71 | do_test fallocate-1.8 { execsql { COMMIT } } {} |
| 72 | |
drh | 7c04c69 | 2019-01-21 14:49:14 +0000 | [diff] [blame] | 73 | do_test fallocate-1.8 { |
dan | b8852ae | 2019-01-19 15:27:09 +0000 | [diff] [blame] | 74 | set nPg [db one {PRAGMA page_count}] |
| 75 | set nFile [expr [file size test.db] / 1024] |
| 76 | list [expr $nPg<100] [expr $nFile>100] |
| 77 | } {1 1} |
| 78 | |
drh | 7c04c69 | 2019-01-21 14:49:14 +0000 | [diff] [blame] | 79 | do_execsql_test fallocate-1.9 { |
dan | b8852ae | 2019-01-19 15:27:09 +0000 | [diff] [blame] | 80 | PRAGMA max_page_count = 100; |
drh | 7c04c69 | 2019-01-21 14:49:14 +0000 | [diff] [blame] | 81 | } {100} |
dan | 502019c | 2010-07-28 14:26:17 +0000 | [diff] [blame] | 82 | |
| 83 | #------------------------------------------------------------------------- |
| 84 | # The following tests - fallocate-2.* - test that things work in WAL |
| 85 | # mode as well. |
| 86 | # |
dan | 4f7b8d6 | 2010-08-06 14:37:13 +0000 | [diff] [blame] | 87 | set skipwaltests [expr { |
| 88 | [permutation]=="journaltest" || [permutation]=="inmemory_journal" |
| 89 | }] |
dan | dc11061 | 2010-08-06 09:43:03 +0000 | [diff] [blame] | 90 | ifcapable !wal { set skipwaltests 1 } |
| 91 | |
| 92 | if {!$skipwaltests} { |
dan | 4f7b8d6 | 2010-08-06 14:37:13 +0000 | [diff] [blame] | 93 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 94 | forcedelete test.db |
dan | 4f7b8d6 | 2010-08-06 14:37:13 +0000 | [diff] [blame] | 95 | sqlite3 db test.db |
| 96 | file_control_chunksize_test db main [expr 32*1024] |
| 97 | |
| 98 | do_test fallocate-2.1 { |
| 99 | execsql { |
| 100 | PRAGMA page_size = 1024; |
| 101 | PRAGMA journal_mode = WAL; |
| 102 | CREATE TABLE t1(a, b); |
| 103 | } |
| 104 | file size test.db |
| 105 | } [expr 32*1024] |
| 106 | |
| 107 | do_test fallocate-2.2 { |
| 108 | execsql { INSERT INTO t1 VALUES(1, zeroblob(35*1024)) } |
| 109 | execsql { PRAGMA wal_checkpoint } |
| 110 | file size test.db |
| 111 | } [expr 64*1024] |
| 112 | |
| 113 | do_test fallocate-2.3 { |
| 114 | execsql { DELETE FROM t1 } |
| 115 | execsql { VACUUM } |
| 116 | file size test.db |
| 117 | } [expr 64*1024] |
| 118 | |
| 119 | do_test fallocate-2.4 { |
| 120 | execsql { PRAGMA wal_checkpoint } |
| 121 | file size test.db |
| 122 | } [expr 32*1024] |
| 123 | |
| 124 | do_test fallocate-2.5 { |
| 125 | execsql { |
| 126 | INSERT INTO t1 VALUES(2, randomblob(35*1024)); |
| 127 | PRAGMA wal_checkpoint; |
| 128 | INSERT INTO t1 VALUES(3, randomblob(128)); |
| 129 | DELETE FROM t1 WHERE a = 2; |
| 130 | VACUUM; |
| 131 | } |
| 132 | file size test.db |
| 133 | } [expr 64*1024] |
| 134 | |
| 135 | do_test fallocate-2.6 { |
| 136 | sqlite3 db2 test.db |
| 137 | execsql { BEGIN ; SELECT count(a) FROM t1 } db2 |
| 138 | execsql { |
| 139 | INSERT INTO t1 VALUES(4, randomblob(128)); |
| 140 | PRAGMA wal_checkpoint; |
| 141 | } |
| 142 | file size test.db |
| 143 | } [expr 64*1024] |
| 144 | |
| 145 | do_test fallocate-2.7 { |
| 146 | execsql { SELECT count(b) FROM t1 } db2 |
| 147 | } {1} |
| 148 | |
| 149 | do_test fallocate-2.8 { |
| 150 | execsql { COMMIT } db2 |
| 151 | execsql { PRAGMA wal_checkpoint } |
| 152 | file size test.db |
| 153 | } [expr 32*1024] |
dan | dc11061 | 2010-08-06 09:43:03 +0000 | [diff] [blame] | 154 | } |
| 155 | |
dan | 502019c | 2010-07-28 14:26:17 +0000 | [diff] [blame] | 156 | |
dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 157 | finish_test |