From: dan Date: Tue, 9 Nov 2010 20:08:02 +0000 (+0000) Subject: Add "PRAGMA checkpoint_fullfsync". Similar to "PRAGMA fullfsync", but enables full... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02f441e408460dc13c8c7cb187324c2729ab2ba0;p=thirdparty%2Fsqlite.git Add "PRAGMA checkpoint_fullfsync". Similar to "PRAGMA fullfsync", but enables full fsyncs only during checkpoint operations. FossilOrigin-Name: 756589ad6e286a898ca34ff1b14d5bb4843529e1 --- diff --git a/manifest b/manifest index 5ee9f28c1b..61fe30a136 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Back\sout\sthe\sprior\sattempt\sto\senable\sfull-fsync\sfor\sWAL\sand\sattempt\sthe\ssame\nthing\susing\sa\scompletely\sdifferent\sapproach. -D 2010-11-09T01:53:48 +C Add\s"PRAGMA\scheckpoint_fullfsync".\sSimilar\sto\s"PRAGMA\sfullfsync",\sbut\senables\sfull\sfsyncs\sonly\sduring\scheckpoint\soperations. +D 2010-11-09T20:08:02 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in c58f7d37ad0f9b28655ba4e28c6cb0f879569cd7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -162,13 +159,13 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e F src/os_unix.c 79cf726c9a0bcc4691a01389031513c10bf15bed F src/os_win.c 51cb62f76262d961ea4249489383d714501315a7 -F src/pager.c a5f5d9787b11dfb0b6082e6f5846d00b459a8e19 +F src/pager.c b9809c31985b77437d89649b5dc351b45e01551b F src/pager.h ef8c8f71ab022cc2fff768a1175dd32355be9dcd F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07 F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050 F src/pcache1.c e921e8a1d52c93abde63cb6dad1fa39770410c52 -F src/pragma.c 3dbb254a99d7a5ccaff8eb1f8689556ff82fe6d0 +F src/pragma.c 6a641dec2c137092ef2b7489e4943b878cf2cbfd F src/prepare.c 23b5da0608820c9f76aa61d4955ebdbd23ffda36 F src/printf.c 8ae5082dd38a1b5456030c3755ec3a392cd51506 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -179,7 +176,7 @@ F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056 F src/sqlite.h.in 2d72a6242df41c517e38eec8791abcf5484a36f1 F src/sqlite3_private.h 2a814d17913732831acf13e7e87860105a3416e4 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 -F src/sqliteInt.h e33b15e8176442bf7484f0e716edfd1ce03b2979 +F src/sqliteInt.h a4231c81ff0d3767b61ca7a15268f91d778726b1 F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44 F src/status.c 496913d4e8441195f6f2a75b1c95993a45b9b30b F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -234,7 +231,7 @@ F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256 F src/vdbemem.c e5673f81a2381b35c60e73ef0a8502be2ab1041e F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2 F src/vtab.c 0e8e0cb30dffb078367e843e84e37ef99236c7e4 -F src/wal.c 419914f47fe2c632d62e2e8f68917683b7e81500 +F src/wal.c 5ac2119e23ee4424599d4275b66dc88d612a0543 F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f F src/where.c 7db3e41c2a846f9deeb24f1bbb75461b4010b7b5 @@ -558,7 +555,7 @@ F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb F test/pcache.test 4118a183908ecaed343a06fcef3ba82e87e0129d F test/pcache2.test 0d85f2ab6963aee28c671d4c71bec038c00a1d16 F test/permutations.test 17498d1219f922d5a6da893a94c4dc7766fb2426 -F test/pragma.test 90f2386eba9785875dc19c6c464106ad7cca12c1 +F test/pragma.test 421476c181fe8ddb528dcaac8b043aa1544983df F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 @@ -793,7 +790,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d F test/wal.test d83c3d227e9e9bb5c7a0c1447ea4a3c6cd5fced4 -F test/wal2.test 998e1807c7bea96f1a5246adf670d02137118339 +F test/wal2.test 03f5f0e14cf26120d2bc2daedb6952a93b981c8e F test/wal3.test 09278a6f54b3a847b502f426a63a0a3028c4e57e F test/wal4.test 6a68c45bc1ca24a3592ec449ddcb92b29d0e0e87 F test/wal_common.tcl 895d76138043b86bdccf36494054bdabcf65837b @@ -854,14 +851,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 77b343cfc3bef9b1a99e98fec6073626dab05657 fd4d38fa66de85676189ff4922fb1bf5f8cac9c4 -R 3023c4e1d42906020afbe1f5e513b1f2 -U drh -Z 0b9563616992466c031d218f11922948 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFM2KmwoxKgR168RlERAiauAKCI1qDSxQkR6dO7p8jSJgiwE1ynBACeL7xT -D2mdq8GqQe7zmNxnxNVQVBs= -=Tv5T ------END PGP SIGNATURE----- +P f59949fac1776ea2f58f41ee8aef8dd95b67725a +R 10ec051ad734b09d2ce7d88de83d010e +U dan +Z 13849545f92827f8d5abaf3d106e2e3f diff --git a/manifest.uuid b/manifest.uuid index 2a96a67df9..f235c37e80 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f59949fac1776ea2f58f41ee8aef8dd95b67725a \ No newline at end of file +756589ad6e286a898ca34ff1b14d5bb4843529e1 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index f0b5b77544..b73c78fb81 100644 --- a/src/pager.c +++ b/src/pager.c @@ -619,6 +619,7 @@ struct Pager { u8 tempFile; /* zFilename is a temporary file */ u8 readOnly; /* True for a read-only database */ u8 memDb; /* True to inhibit all file I/O */ + u8 ckptFullSync; /* True to pass SYNC_FULL to WalCheckpoint() */ /************************************************************************** ** The following block contains those class members that change during @@ -3082,6 +3083,19 @@ static int pagerOpenWalIfPresent(Pager *pPager){ } return rc; } + +/* +** Return the value of the flags parameter that should be passed to +** sqlite3OsSync() when checkpointing a WAL file. +*/ +static int walCkptSyncFlags(Pager *pPager){ + int flags = 0; + if( pPager->noSync==0 ){ + flags = pPager->sync_flags | (pPager->ckptFullSync?SQLITE_SYNC_FULL:0); + } + return flags; +} + #endif /* @@ -3262,10 +3276,16 @@ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){ ** and FULL=3. */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS -void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int bFullFsync){ +void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int fullFsync){ + assert( 0==(fullFsync & ~(SQLITE_FullFSync|SQLITE_CkptFullFSync)) ); pPager->noSync = (level==1 || pPager->tempFile) ?1:0; pPager->fullSync = (level==3 && !pPager->tempFile) ?1:0; - pPager->sync_flags = (bFullFsync?SQLITE_SYNC_FULL:SQLITE_SYNC_NORMAL); + if( fullFsync & SQLITE_FullFSync ){ + pPager->sync_flags = SQLITE_SYNC_FULL; + }else{ + pPager->sync_flags = SQLITE_SYNC_NORMAL; + } + pPager->ckptFullSync = (fullFsync & SQLITE_CkptFullFSync)!=0; } #endif @@ -3651,8 +3671,7 @@ int sqlite3PagerClose(Pager *pPager){ /* pPager->errCode = 0; */ pPager->exclusiveMode = 0; #ifndef SQLITE_OMIT_WAL - sqlite3WalClose(pPager->pWal, - (pPager->noSync ? 0 : pPager->sync_flags), + sqlite3WalClose(pPager->pWal, walCkptSyncFlags(pPager), pPager->pageSize, pTmp ); pPager->pWal = 0; @@ -6521,10 +6540,8 @@ int sqlite3PagerCheckpoint(Pager *pPager){ int rc = SQLITE_OK; if( pPager->pWal ){ u8 *zBuf = (u8 *)pPager->pTmpSpace; - rc = sqlite3WalCheckpoint(pPager->pWal, - (pPager->noSync ? 0 : pPager->sync_flags), - pPager->pageSize, zBuf - ); + int flags = walCkptSyncFlags(pPager); + rc = sqlite3WalCheckpoint(pPager->pWal, flags, pPager->pageSize, zBuf); } return rc; } @@ -6629,9 +6646,8 @@ int sqlite3PagerCloseWal(Pager *pPager){ if( rc==SQLITE_OK && pPager->pWal ){ rc = pagerLockDb(pPager, EXCLUSIVE_LOCK); if( rc==SQLITE_OK ){ - rc = sqlite3WalClose(pPager->pWal, - (pPager->noSync ? 0 : pPager->sync_flags), - pPager->pageSize, (u8*)pPager->pTmpSpace + rc = sqlite3WalClose(pPager->pWal, walCkptSyncFlags(pPager), + pPager->pageSize, (u8*)pPager->pTmpSpace ); pPager->pWal = 0; }else{ diff --git a/src/pragma.c b/src/pragma.c index 9a02e97b69..0855e554d1 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -172,6 +172,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ { "empty_result_callbacks", SQLITE_NullCallback }, { "legacy_file_format", SQLITE_LegacyFileFmt }, { "fullfsync", SQLITE_FullFSync }, + { "checkpoint_fullfsync", SQLITE_CkptFullFSync }, { "reverse_unordered_selects", SQLITE_ReverseOrder }, #ifndef SQLITE_OMIT_AUTOMATIC_INDEX { "automatic_index", SQLITE_AutoIndex }, @@ -1509,7 +1510,7 @@ void sqlite3Pragma( #ifndef SQLITE_OMIT_PAGER_PRAGMAS if( db->autoCommit ){ sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, - (db->flags&SQLITE_FullFSync)!=0); + db->flags&(SQLITE_FullFSync|SQLITE_CkptFullFSync)); } #endif pragma_out: diff --git a/src/sqliteInt.h b/src/sqliteInt.h index c44c25fa5c..573f112d31 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -914,6 +914,7 @@ struct sqlite3 { #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */ #define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */ #define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */ +#define SQLITE_CkptFullFSync 0x20000000 /* Use full fsync on checkpoint */ /* ** Bits of the sqlite3.flags field that are used by the diff --git a/src/wal.c b/src/wal.c index 01b7e497fc..22ce1fa77f 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1592,7 +1592,7 @@ static int walCheckpoint( /* Sync the WAL to disk */ if( sync_flags ){ - rc = sqlite3OsSync(pWal->pWalFd, sync_flags | SQLITE_SYNC_FULL ); + rc = sqlite3OsSync(pWal->pWalFd, sync_flags); } /* If the database file may grow as a result of this checkpoint, hint @@ -1628,7 +1628,7 @@ static int walCheckpoint( testcase( IS_BIG_INT(szDb) ); rc = sqlite3OsTruncate(pWal->pDbFd, szDb); if( rc==SQLITE_OK && sync_flags ){ - rc = sqlite3OsSync(pWal->pDbFd, sync_flags | SQLITE_SYNC_FULL); + rc = sqlite3OsSync(pWal->pDbFd, sync_flags); } } if( rc==SQLITE_OK ){ diff --git a/test/pragma.test b/test/pragma.test index 36a304fedb..211e0c3f13 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -1293,7 +1293,7 @@ dbX eval {PRAGMA temp_store_directory = ""} dbX close set skip_lock_proxy_tests [path_is_dos "."] -ifcapable !lock_proxy_pragmas&&prefer_proxy_locking { +ifcapable !lock_proxy_pragmas||prefer_proxy_locking { set skip_lock_proxy_tests 1 } diff --git a/test/wal2.test b/test/wal2.test index 16f5ce5f26..e32b1e3b7b 100644 --- a/test/wal2.test +++ b/test/wal2.test @@ -1153,4 +1153,59 @@ if {$::tcl_platform(platform) == "unix"} { } } +#------------------------------------------------------------------------- +# Test that "PRAGMA checkpoint_fullsync" appears to be working. +# +foreach {tn sql reslist} { + 1 { } {8 0 3 0 5 0} + 2 { PRAGMA checkpoint_fullfsync = 1 } {8 4 3 2 5 2} + 3 { PRAGMA checkpoint_fullfsync = 0 } {8 0 3 0 5 0} +} { + faultsim_delete_and_reopen + + execsql $sql + do_execsql_test wal2-14.$tn.1 { PRAGMA journal_mode = WAL } {wal} + + set sqlite_sync_count 0 + set sqlite_fullsync_count 0 + + do_execsql_test wal2-14.$tn.2 { + PRAGMA wal_autocheckpoint = 10; + CREATE TABLE t1(a, b); -- 2 wal syncs + INSERT INTO t1 VALUES(1, 2); -- 1 wal sync + PRAGMA wal_checkpoint; -- 1 wal sync, 1 db sync + BEGIN; + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + COMMIT; -- 1 wal sync + PRAGMA wal_checkpoint; -- 1 wal sync, 1 db sync + } {10} + + do_test wal2-14.$tn.3 { + list $sqlite_sync_count $sqlite_fullsync_count + } [lrange $reslist 0 1] + + set sqlite_sync_count 0 + set sqlite_fullsync_count 0 + + do_test wal2-14.$tn.4 { + execsql { INSERT INTO t1 VALUES(7, zeroblob(12*4096)) } + list $sqlite_sync_count $sqlite_fullsync_count + } [lrange $reslist 2 3] + + set sqlite_sync_count 0 + set sqlite_fullsync_count 0 + + do_test wal2-14.$tn.5 { + execsql { PRAGMA wal_autocheckpoint = 1000 } + execsql { INSERT INTO t1 VALUES(9, 10) } + execsql { INSERT INTO t1 VALUES(11, 12) } + execsql { INSERT INTO t1 VALUES(13, 14) } + db close + list $sqlite_sync_count $sqlite_fullsync_count + } [lrange $reslist 4 5] +} + + + finish_test