1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Add the "truncate" journal mode which commits transactions by truncating the

rollback journal file to zero length and not calling fsync(). (CVS 5745)

FossilOrigin-Name: 7c561f2e9264de676c1028943f6c3d06542fd802
This commit is contained in:
drh
2008-09-26 21:08:08 +00:00
parent 9e2d64b8d3
commit 04335886a1
7 changed files with 92 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
C Make\ssure\sthe\squeueMutex\sis\sheld\sprior\sto\swriting\sthe\spQueueLast\sfield\nof\sthe\swrite\squeue\sin\sthe\sasync\sdemonstration\scode.\s\sTicket\s#3405.\s(CVS\s5744)
D 2008-09-26T20:02:50
C Add\sthe\s"truncate"\sjournal\smode\swhich\scommits\stransactions\sby\struncating\sthe\nrollback\sjournal\sfile\sto\szero\slength\sand\snot\scalling\sfsync().\s(CVS\s5745)
D 2008-09-26T21:08:08
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in e4ab842f9a64ef61d57093539a8aab76b12810db
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -137,12 +137,12 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c e391fc95adc744bbdcefd4d11e3066998185a0a0
F src/os_unix.c f33b69d8a85372b270fe37ee664a4c2140a5217d
F src/os_win.c 3209dc0ed734291764393ea8d534ba0d8696a540
F src/pager.c 7a3ba14e27cf134e54f0f4f58d307de13a7ea28d
F src/pager.h 1ef5a3f8e0b4c8b30f19c8e01d4fca2db9bb5797
F src/pager.c 6426902ba983ce6872fcec20ba72796a79d6cead
F src/pager.h 30e71f447ecbcfef707bb72cc813ce37ab5a2bc9
F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8
F src/pcache.c 52108517c38bcf023f3977085a66aacb520a5385
F src/pcache.h 0b6871e820159629915e8688b5c67a81a203773f
F src/pragma.c e633b6b7dabc110e2abfed4e35ba34a4039cb65c
F src/pragma.c 0b1c2d2a241dd79a7361bbeb8ff575a9e9d7cd71
F src/prepare.c c7e00ed1b0bdcf699b1aad651247d4dc3d281b0b
F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
F src/random.c 11bbdf7def3746a762fbdb56c9d04648135ad6d8
@@ -390,7 +390,7 @@ F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
F test/join5.test 86675fc2919269aa923c84dd00ee4249b97990fe
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
F test/jrnlmode.test 1ab9729d6bbb6fb355cbb4bb41f1f0c271fc251a
F test/jrnlmode.test 54469696db41e185a37aed3b3848998cca4e0c37
F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51
F test/laststmtchanges.test 18ead86c8a87ade949a1d5658f6dc4bb111d1b02
F test/like.test fef924922828d5a2a5bff80b9bdd9ff57a1ca500
@@ -453,7 +453,7 @@ F test/pageropt.test 3ee6578891baaca967f0bd349e4abfa736229e1a
F test/pagesize.test 0d9ff3fedfce6e5ffe8fa7aca9b6d3433a2e843b
F test/pcache.test 515b4c26e9f57660357dfff5b6b697acac1abc5f
F test/pcache2.test 2b4fa1bee5cfc338d8c04eb6ed7eaf41f478bf7c
F test/permutations.test 41832b86c152c140bcdf75a35a7c82badd8912b9
F test/permutations.test 9f9ee1a8899cc26c7f850c92bfc7efc85bb71161
F test/pragma.test c86359a8e0b28abdcc0ff4936f7966c446d0479a
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
@@ -637,7 +637,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 28fd0a50ca8529892f5b1ababd38d494889eed6d
R 42f79e8d6bad8dc05f28b70884a1cf00
P 5622a1e285fc4d5720f7180a0eb551952f2df331
R d784c96d098146eb0a9f2a9c5180ad72
U drh
Z c1f39a8806852672a67f740f0e33cd9d
Z ac8d7bb3e53159a4cf0d1bb60149a10e

View File

@@ -1 +1 @@
5622a1e285fc4d5720f7180a0eb551952f2df331
7c561f2e9264de676c1028943f6c3d06542fd802

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.494 2008/09/23 16:41:30 danielk1977 Exp $
** @(#) $Id: pager.c,v 1.495 2008/09/26 21:08:08 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -971,7 +971,11 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
pPager->stmtOpen = 0;
}
if( pPager->journalOpen ){
if( pPager->exclusiveMode
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);
@@ -979,6 +983,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
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 ){
@@ -4207,24 +4212,31 @@ int sqlite3PagerLockingMode(Pager *pPager, int eMode){
}
/*
** Get/set the journal-mode for this pager. Parameter eMode must be one
** of PAGER_JOURNALMODE_QUERY, PAGER_JOURNALMODE_DELETE or
** PAGER_JOURNALMODE_PERSIST. If the parameter is not _QUERY, then
** the journal-mode is set to the value specified.
** Get/set the journal-mode for this pager. Parameter eMode must be one of:
**
** The returned value is either PAGER_JOURNALMODE_DELETE or
** PAGER_JOURNALMODE_PERSIST, indicating the current (possibly updated)
** 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 );
assert( PAGER_JOURNALMODE_DELETE>=0 && PAGER_JOURNALMODE_PERSIST>=0 );
if( eMode>=0 ){
pPager->journalMode = eMode;
}else{
assert( eMode==PAGER_JOURNALMODE_QUERY );
}
return (int)pPager->journalMode;
}

View File

@@ -13,7 +13,7 @@
** 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.83 2008/09/18 17:34:44 danielk1977 Exp $
** @(#) $Id: pager.h,v 1.84 2008/09/26 21:08:08 drh Exp $
*/
#ifndef _PAGER_H_
@@ -65,6 +65,7 @@ typedef struct PgHdr DbPage;
#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

View File

@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.187 2008/09/16 14:38:03 danielk1977 Exp $
** $Id: pragma.c,v 1.188 2008/09/26 21:08:08 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -449,13 +449,13 @@ void sqlite3Pragma(
*/
if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
int eMode;
static char * const azModeName[] = {"delete", "persist", "off"};
static char * const azModeName[] = {"delete", "persist", "off", "truncate"};
if( zRight==0 ){
eMode = PAGER_JOURNALMODE_QUERY;
}else{
int n = strlen(zRight);
eMode = 2;
eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1;
while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){
eMode--;
}
@@ -491,6 +491,7 @@ void sqlite3Pragma(
eMode = sqlite3PagerJournalMode(pPager, eMode);
}
assert( eMode==PAGER_JOURNALMODE_DELETE
|| eMode==PAGER_JOURNALMODE_TRUNCATE
|| eMode==PAGER_JOURNALMODE_PERSIST
|| eMode==PAGER_JOURNALMODE_OFF );
sqlite3VdbeSetNumCols(v, 1);

View File

@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The focus
# of these tests is the journal mode pragma.
#
# $Id: jrnlmode.test,v 1.5 2008/08/02 20:09:37 drh Exp $
# $Id: jrnlmode.test,v 1.6 2008/09/26 21:08:08 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -67,6 +67,18 @@ do_test jrnlmode-1.7 {
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;
@@ -76,7 +88,7 @@ do_test jrnlmode-1.8 {
ifcapable attach {
do_test jrnlmode-1.9 {
execsql {
PRAGMA journal_mode = persist;
PRAGMA journal_mode = PERSIST;
ATTACH ':memory:' as aux1;
}
execsql {
@@ -86,7 +98,7 @@ ifcapable attach {
} {persist persist}
do_test jrnlmode-1.10 {
execsql {
PRAGMA main.journal_mode = off;
PRAGMA main.journal_mode = OFF;
}
execsql {
PRAGMA main.journal_mode;
@@ -111,7 +123,7 @@ ifcapable attach {
} {off persist persist}
do_test jrnlmode-1.11 {
execsql {
PRAGMA aux1.journal_mode = delete;
PRAGMA aux1.journal_mode = DELETE;
}
execsql {
PRAGMA main.journal_mode;
@@ -142,6 +154,18 @@ ifcapable attach {
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 {

View File

@@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: permutations.test,v 1.30 2008/09/12 10:22:40 danielk1977 Exp $
# $Id: permutations.test,v 1.31 2008/09/26 21:08:08 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -377,10 +377,23 @@ run_tests "exclusive" -description {
} -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 {
@@ -392,6 +405,18 @@ run_tests "persistent_journal" -description {
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 {