Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add the "truncate" journal mode which commits transactions by truncating the rollback journal file to zero length and not calling fsync(). (CVS 5745) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7c561f2e9264de676c1028943f6c3d06 |
User & Date: | drh 2008-09-26 21:08:08.000 |
Context
2008-09-29
| ||
00:11 | fix #3077: use full version in pkg-config files (CVS 5746) (check-in: efe095e0cb user: vapier tags: trunk) | |
2008-09-26
| ||
21:08 | Add the "truncate" journal mode which commits transactions by truncating the rollback journal file to zero length and not calling fsync(). (CVS 5745) (check-in: 7c561f2e92 user: drh tags: trunk) | |
20:02 | Make sure the queueMutex is held prior to writing the pQueueLast field of the write queue in the async demonstration code. Ticket #3405. (CVS 5744) (check-in: 5622a1e285 user: drh tags: trunk) | |
Changes
Changes to src/pager.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ** 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. ** | | | 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. ** ** @(#) $Id: pager.c,v 1.495 2008/09/26 21:08:08 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" /* ** Macros for troubleshooting. Normally turned off */ |
︙ | ︙ | |||
967 968 969 970 971 972 973 | } sqlite3PagerStmtCommit(pPager); if( pPager->stmtOpen && !pPager->exclusiveMode ){ sqlite3OsClose(pPager->stfd); pPager->stmtOpen = 0; } if( pPager->journalOpen ){ | > > > > | > | 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | } sqlite3PagerStmtCommit(pPager); if( pPager->stmtOpen && !pPager->exclusiveMode ){ sqlite3OsClose(pPager->stfd); pPager->stmtOpen = 0; } if( pPager->journalOpen ){ if( pPager->journalMode==PAGER_JOURNALMODE_TRUNCATE && (rc = sqlite3OsTruncate(pPager->jfd, 0))==SQLITE_OK ){ pPager->journalOff = 0; pPager->journalStarted = 0; }else if( pPager->exclusiveMode || pPager->journalMode==PAGER_JOURNALMODE_PERSIST ){ rc = zeroJournalHdr(pPager, hasMaster); pager_error(pPager, rc); pPager->journalOff = 0; pPager->journalStarted = 0; }else{ assert( pPager->journalMode==PAGER_JOURNALMODE_DELETE || rc ); sqlite3OsClose(pPager->jfd); pPager->journalOpen = 0; if( rc==SQLITE_OK && !pPager->tempFile ){ rc = sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0); } } sqlite3BitvecDestroy(pPager->pInJournal); |
︙ | ︙ | |||
4203 4204 4205 4206 4207 4208 4209 | if( eMode>=0 && !pPager->tempFile ){ pPager->exclusiveMode = eMode; } return (int)pPager->exclusiveMode; } /* | | > > | > > > > | | < | > < > > | 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 | if( eMode>=0 && !pPager->tempFile ){ pPager->exclusiveMode = eMode; } return (int)pPager->exclusiveMode; } /* ** Get/set the journal-mode for this pager. Parameter eMode must be one of: ** ** PAGER_JOURNALMODE_QUERY ** PAGER_JOURNALMODE_DELETE ** PAGER_JOURNALMODE_TRUNCATE ** PAGER_JOURNALMODE_PERSIST ** PAGER_JOURNALMODE_OFF ** ** If the parameter is not _QUERY, then the journal-mode is set to the ** value specified. ** ** The returned indicate the current (possibly updated) ** journal-mode. */ int sqlite3PagerJournalMode(Pager *pPager, int eMode){ assert( eMode==PAGER_JOURNALMODE_QUERY || eMode==PAGER_JOURNALMODE_DELETE || eMode==PAGER_JOURNALMODE_TRUNCATE || eMode==PAGER_JOURNALMODE_PERSIST || eMode==PAGER_JOURNALMODE_OFF ); assert( PAGER_JOURNALMODE_QUERY<0 ); if( eMode>=0 ){ pPager->journalMode = eMode; }else{ assert( eMode==PAGER_JOURNALMODE_QUERY ); } return (int)pPager->journalMode; } /* ** Get/set the size-limit used for persistent journal files. */ |
︙ | ︙ |
Changes to src/pager.h.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** ** @(#) $Id: pager.h,v 1.84 2008/09/26 21:08:08 drh Exp $ */ #ifndef _PAGER_H_ #define _PAGER_H_ /* ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise |
︙ | ︙ | |||
61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /* ** Valid values for the second argument to sqlite3PagerJournalMode(). */ #define PAGER_JOURNALMODE_QUERY -1 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */ #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ /* ** See source code comments for a detailed description of the following ** routines: */ int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, void(*)(DbPage*), int,int,int); void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler); | > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | /* ** Valid values for the second argument to sqlite3PagerJournalMode(). */ #define PAGER_JOURNALMODE_QUERY -1 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */ #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */ /* ** See source code comments for a detailed description of the following ** routines: */ int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, void(*)(DbPage*), int,int,int); void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler); |
︙ | ︙ |
Changes to src/pragma.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2003 April 6 ** ** 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 code used to implement the PRAGMA command. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2003 April 6 ** ** 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 code used to implement the PRAGMA command. ** ** $Id: pragma.c,v 1.188 2008/09/26 21:08:08 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* Ignore this whole file if pragmas are disabled */ #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER) |
︙ | ︙ | |||
445 446 447 448 449 450 451 | /* ** PRAGMA [database.]journal_mode ** PRAGMA [database.]journal_mode = (delete|persist|off) */ if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){ int eMode; | | | | 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | /* ** PRAGMA [database.]journal_mode ** PRAGMA [database.]journal_mode = (delete|persist|off) */ if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){ int eMode; static char * const azModeName[] = {"delete", "persist", "off", "truncate"}; if( zRight==0 ){ eMode = PAGER_JOURNALMODE_QUERY; }else{ int n = strlen(zRight); eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1; while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){ eMode--; } } if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){ /* Simple "PRAGMA journal_mode;" statement. This is a query for ** the current default journal mode (which may be different to |
︙ | ︙ | |||
487 488 489 490 491 492 493 494 495 496 497 498 499 500 | } db->dfltJournalMode = eMode; } pPager = sqlite3BtreePager(pDb->pBt); eMode = sqlite3PagerJournalMode(pPager, eMode); } assert( eMode==PAGER_JOURNALMODE_DELETE || eMode==PAGER_JOURNALMODE_PERSIST || eMode==PAGER_JOURNALMODE_OFF ); sqlite3VdbeSetNumCols(v, 1); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", P4_STATIC); sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, azModeName[eMode], P4_STATIC); sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); | > | 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | } db->dfltJournalMode = eMode; } pPager = sqlite3BtreePager(pDb->pBt); eMode = sqlite3PagerJournalMode(pPager, eMode); } assert( eMode==PAGER_JOURNALMODE_DELETE || eMode==PAGER_JOURNALMODE_TRUNCATE || eMode==PAGER_JOURNALMODE_PERSIST || eMode==PAGER_JOURNALMODE_OFF ); sqlite3VdbeSetNumCols(v, 1); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", P4_STATIC); sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, azModeName[eMode], P4_STATIC); sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
︙ | ︙ |
Changes to test/jrnlmode.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2008 April 17 # # 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 implements regression tests for SQLite library. The focus # of these tests is the journal mode pragma. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2008 April 17 # # 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 implements regression tests for SQLite library. The focus # of these tests is the journal mode pragma. # # $Id: jrnlmode.test,v 1.6 2008/09/26 21:08:08 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable {!pager_pragmas} { finish_test return |
︙ | ︙ | |||
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | do_test jrnlmode-1.7 { execsql { PRAGMA journal_mode; PRAGMA main.journal_mode; PRAGMA temp.journal_mode; } } {delete delete delete} do_test jrnlmode-1.8 { execsql { PRAGMA journal_mode = off; PRAGMA journal_mode = invalid; } } {off off} ifcapable attach { do_test jrnlmode-1.9 { execsql { | > > > > > > > > > > > > | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | do_test jrnlmode-1.7 { execsql { PRAGMA journal_mode; PRAGMA main.journal_mode; PRAGMA temp.journal_mode; } } {delete delete delete} do_test jrnlmode-1.7.1 { execsql { PRAGMA journal_mode = truncate; } } {truncate} do_test jrnlmode-1.7.2 { execsql { PRAGMA journal_mode; PRAGMA main.journal_mode; PRAGMA temp.journal_mode; } } {truncate truncate truncate} do_test jrnlmode-1.8 { execsql { PRAGMA journal_mode = off; PRAGMA journal_mode = invalid; } } {off off} ifcapable attach { do_test jrnlmode-1.9 { execsql { PRAGMA journal_mode = PERSIST; ATTACH ':memory:' as aux1; } execsql { PRAGMA main.journal_mode; PRAGMA aux1.journal_mode; } } {persist persist} do_test jrnlmode-1.10 { execsql { PRAGMA main.journal_mode = OFF; } execsql { PRAGMA main.journal_mode; PRAGMA temp.journal_mode; PRAGMA aux1.journal_mode; } } {off persist persist} |
︙ | ︙ | |||
107 108 109 110 111 112 113 | PRAGMA main.journal_mode; PRAGMA aux1.journal_mode; PRAGMA aux2.journal_mode; } } {off persist persist} do_test jrnlmode-1.11 { execsql { | | | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | PRAGMA main.journal_mode; PRAGMA aux1.journal_mode; PRAGMA aux2.journal_mode; } } {off persist persist} do_test jrnlmode-1.11 { execsql { PRAGMA aux1.journal_mode = DELETE; } execsql { PRAGMA main.journal_mode; PRAGMA aux1.journal_mode; PRAGMA aux2.journal_mode; } } {off delete persist} |
︙ | ︙ | |||
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | PRAGMA main.journal_mode; PRAGMA temp.journal_mode; PRAGMA aux1.journal_mode; PRAGMA aux2.journal_mode; PRAGMA aux3.journal_mode; } } {delete delete delete delete delete} do_test jrnlmode-1.99 { execsql { DETACH aux1; DETACH aux2; DETACH aux3; } | > > > > > > > > > > > > | 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 | PRAGMA main.journal_mode; PRAGMA temp.journal_mode; PRAGMA aux1.journal_mode; PRAGMA aux2.journal_mode; PRAGMA aux3.journal_mode; } } {delete delete delete delete delete} do_test jrnlmode-1.14 { execsql { PRAGMA journal_mode = TRUNCATE; } execsql { PRAGMA main.journal_mode; PRAGMA temp.journal_mode; PRAGMA aux1.journal_mode; PRAGMA aux2.journal_mode; PRAGMA aux3.journal_mode; } } {truncate truncate truncate truncate truncate} do_test jrnlmode-1.99 { execsql { DETACH aux1; DETACH aux2; DETACH aux3; } |
︙ | ︙ |
Changes to test/permutations.test.
1 2 3 4 5 6 7 8 9 10 11 | # 2008 June 21 # # 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. # #*********************************************************************** # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # 2008 June 21 # # 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. # #*********************************************************************** # # $Id: permutations.test,v 1.31 2008/09/26 21:08:08 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Argument processing. # #puts "PERM-DEBUG: argv=$argv" |
︙ | ︙ | |||
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | # Run some tests in exclusive locking mode. # run_tests "exclusive" -description { Run tests in exclusive locking mode. } -presql { pragma locking_mode = 'exclusive' } -include { rollback.test select1.test select2.test malloc.test ioerr.test } # Run some tests in persistent journal mode. # run_tests "persistent_journal" -description { Run tests in persistent-journal mode. } -presql { pragma journal_mode = persist } -include { delete.test delete2.test insert.test rollback.test select1.test select2.test trans.test update.test vacuum.test } # Run some error tests in persistent journal mode. # run_tests "persistent_journal_error" -description { Run malloc.test and ioerr.test in persistent-journal mode. } -presql { pragma journal_mode = persist | > > > > > > > > > > > > > > > > > > > > > > > > > | 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | # Run some tests in exclusive locking mode. # run_tests "exclusive" -description { Run tests in exclusive locking mode. } -presql { pragma locking_mode = 'exclusive' } -include { vacuum.test rollback.test select1.test select2.test malloc.test ioerr.test } # Run some tests in exclusive locking mode with truncated journals. # run_tests "exclusive-truncate" -description { Run tests in exclusive locking mode and truncate journal mode. } -presql { pragma locking_mode = 'exclusive'; pragma journal_mode = TRUNCATE; } -include { delete.test delete2.test insert.test rollback.test select1.test select2.test update.test malloc.test ioerr.test } # Run some tests in persistent journal mode. # run_tests "persistent_journal" -description { Run tests in persistent-journal mode. } -presql { pragma journal_mode = persist } -include { delete.test delete2.test insert.test rollback.test select1.test select2.test trans.test update.test vacuum.test } # Run some tests in truncating journal mode. # run_tests "truncate_journal" -description { Run tests in persistent-journal mode. } -presql { pragma journal_mode = truncate } -include { delete.test delete2.test insert.test rollback.test select1.test select2.test trans.test update.test vacuum.test malloc.test ioerr.test } # Run some error tests in persistent journal mode. # run_tests "persistent_journal_error" -description { Run malloc.test and ioerr.test in persistent-journal mode. } -presql { pragma journal_mode = persist |
︙ | ︙ |