Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add tests to simulate power-failure on devices that support IOCAP_SEQUENTIAL or IOCAP_SAFE_APPEND. (CVS 4284) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
bdf5cb8d25d93d48220ce46acad2ccf9 |
User & Date: | danielk1977 2007-08-24 08:15:54.000 |
Context
2007-08-24
| ||
11:43 | Remove unnecessary sqlite3MallocDisallow() that was preventing win32 from running. (CVS 4285) (check-in: eb6c98fc10 user: drh tags: trunk) | |
08:15 | Add tests to simulate power-failure on devices that support IOCAP_SEQUENTIAL or IOCAP_SAFE_APPEND. (CVS 4284) (check-in: bdf5cb8d25 user: danielk1977 tags: trunk) | |
04:15 | Bug fix in the memory leak trace output. (CVS 4283) (check-in: a1b495c28a user: drh tags: trunk) | |
Changes
Changes to src/journal.c.
1 2 3 4 5 6 7 8 9 10 11 12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | - + | /* ** 2007 August 22 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** |
︙ | |||
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | + + + + + + + + + + + | p->pMethod = &JournalFileMethods; p->nBuf = nBuf; p->flags = flags; p->zJournal = zName; p->pVfs = pVfs; return SQLITE_OK; } /* ** If the argument p points to a JournalFile structure, and the underlying ** file has not yet been created, create it now. */ int sqlite3JournalCreate(sqlite3_file *p){ if( p->pMethods!=&JournalFileMethods ){ return SQLITE_OK; } return createFile((JournalFile *)p); } /* ** Return the number of bytes required to store a JournalFile that uses vfs ** pVfs to create the underlying on-disk files. */ int sqlite3JournalSize(sqlite3_vfs *pVfs){ return (pVfs->szOsFile+sizeof(JournalFile)); } #endif |
Changes to src/pager.c.
︙ | |||
14 15 16 17 18 19 20 | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | - + | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** |
︙ | |||
4188 4189 4190 4191 4192 4193 4194 | 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 | - + + - - - + + + + + - + + + + + + + | pagerEnter(pPager); /* If this is an in-memory db, or no pages have been written to, or this ** function has already been called, it is a no-op. */ if( pPager->state!=PAGER_SYNCED && !MEMDB && pPager->dirtyCache ){ PgHdr *pPg; |
︙ |
Changes to src/sqliteInt.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | - + | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** |
︙ | |||
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 | 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 | + | int sqlite3Reprepare(Vdbe*); void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*); CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); #ifdef SQLITE_ENABLE_ATOMIC_WRITE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); int sqlite3JournalSize(sqlite3_vfs *); int sqlite3JournalCreate(sqlite3_file *); #else #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile) #endif #if SQLITE_MAX_EXPR_DEPTH>0 void sqlite3ExprSetHeight(Expr *); int sqlite3SelectExprHeight(Select *); |
︙ |
Changes to src/test6.c.
︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - + | ** ****************************************************************************** ** ** This file contains code that modified the OS layer in order to simulate ** the effect on the database file of an OS crash or power failure. This ** is used to test the ability of SQLite to recover from those situations. */ |
︙ | |||
158 159 160 161 162 163 164 | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | - + - - + + + + + + + + + + + + + - - + + + - + + + + + + + + + + + + + + + + + + + + + - + + + - + + + - + + + | /* ** Flush the write-list as if xSync() had been called on file handle ** pFile. If isCrash is true, simulate a crash. */ static int writeListSync(CrashFile *pFile, int isCrash){ int rc = SQLITE_OK; int iDc = g.iDeviceCharacteristics; |
︙ | |||
485 486 487 488 489 490 491 | 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | - + - + | ** The caller will have allocated pVfs->szOsFile bytes of space ** at pFile. This file uses this space for the CrashFile structure ** and allocates space for the "real" file structure using ** sqlite3_malloc(). The assumption here is (pVfs->szOsFile) is ** equal or greater than sizeof(CrashFile). */ static int cfOpen( |
︙ | |||
523 524 525 526 527 528 529 | 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + | } if( rc!=SQLITE_OK && pWrapper->pMethod ){ sqlite3OsClose(pFile); } return rc; } |
︙ |
Changes to test/crash3.test.
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | + + + + - + | # 2007 August 23 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # This file contains tests that verify that SQLite can correctly rollback # databases after crashes when using the special IO modes triggered # by device IOCAP flags. # |
︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | + + | } set res } {{$res1} or {$res2}} }] uplevel $script } # This block tests crash-recovery when the IOCAP_ATOMIC flags is set. # # Each iteration of the following loop sets up the database to contain # the following schema and data: # # CREATE TABLE abc(a, b, c); # INSERT INTO abc VALUES(1, 2, 3); # # Then execute the SQL statement, scheduling a crash for part-way through |
︙ | |||
91 92 93 94 95 96 97 98 99 100 | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | do_test2 crash3-1.$tn.3 { execsql { SELECT * FROM abc } } {1 2 3} $res2 incr tn } } # This block tests both the IOCAP_SEQUENTIAL and IOCAP_SAFE_APPEND flags. # db close file delete -force test.db test.db-journal sqlite3 db test.db do_test crash3-2.0 { execsql { BEGIN; CREATE TABLE abc(a PRIMARY KEY, b, c); CREATE TABLE def(d PRIMARY KEY, e, f); PRAGMA default_cache_size = 10; INSERT INTO abc VALUES(randstr(10,1000),randstr(10,1000),randstr(10,1000)); INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; COMMIT; } } {} set tn 1 foreach {::crashfile ::delay ::char} { test.db 1 sequential test.db 1 safe_append test.db-journal 1 sequential test.db-journal 1 safe_append test.db-journal 2 safe_append test.db-journal 2 sequential test.db-journal 3 sequential test.db-journal 3 safe_append } { for {set ii 0} {$ii < 100} {incr ii} { set ::SQL [subst { SELECT randstr($ii,$ii+10); BEGIN; DELETE FROM abc WHERE random()%5; INSERT INTO abc SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc WHERE (random()%5)==0; DELETE FROM def WHERE random()%5; INSERT INTO def SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM def WHERE (random()%5)==0; COMMIT; }] do_test crash3-2.$tn.$ii { crashsql -file $::crashfile -delay $::delay -char $::char $::SQL db close sqlite3 db test.db execsql {PRAGMA integrity_check} } {ok} } incr tn } # The following block tests an interaction between IOCAP_ATOMIC and # IOCAP_SEQUENTIAL. At one point, if both flags were set, small # journal files that contained only a single page, but were required # for some other reason (i.e. nTrunk) were not being written to # disk. # for {set ii 0} {$ii < 10} {incr ii} { db close file delete -force test.db test.db-journal crashsql -file test.db -char {sequential atomic} { CREATE TABLE abc(a, b, c); } sqlite3 db test.db do_test crash3-3.$ii { execsql {PRAGMA integrity_check} } {ok} } finish_test |