]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not sync any files in wal mode if "PRAGMA synchronous=off" is set. If files are...
authordan <dan@noemail.net>
Sat, 17 Apr 2010 17:34:41 +0000 (17:34 +0000)
committerdan <dan@noemail.net>
Sat, 17 Apr 2010 17:34:41 +0000 (17:34 +0000)
FossilOrigin-Name: 0ae91b0008b242a47385fc1f295c6b645483ee22

manifest
manifest.uuid
src/log.c
src/log.h
src/pager.c

index 2d93f8ada9447f6e2bfd5253b40fd00660887e94..628fe3b0e0248ed6314566a207c86b40063ac4ab 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\swith\strunk\scommit\s[3e646e3f4c].
-D 2010-04-17T15:45:35
+C Do\snot\ssync\sany\sfiles\sin\swal\smode\sif\s"PRAGMA\ssynchronous=off"\sis\sset.\sIf\sfiles\sare\ssynced,\spass\seither\sSQLITE_SYNC_FULL\sor\sSQLITE_SYNC_NORMAL\sto\sthe\sxSync()\scallback\sas\sconfigured\sby\s"PRAGMA\sfullfsync".
+D 2010-04-17T17:34:42
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -131,8 +131,8 @@ F src/journal.c b0ea6b70b532961118ab70301c00a33089f9315c
 F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
 F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
 F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
-F src/log.c a72baea84cecef9a4e45308b1504e6fe69c8284e
-F src/log.h a2654af46ce7b5732f4d5a731abfdd180f0a06d9
+F src/log.c 8bcd490de703a12563c939a59cb4e187a0c67fe3
+F src/log.h 3cfec02156f5db3d233352897a47601930a29955
 F src/main.c c0e7192bad5b90544508b241eb2487ac661de890
 F src/malloc.c a08f16d134f0bfab6b20c3cd142ebf3e58235a6a
 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
@@ -154,7 +154,7 @@ F src/os_common.h 240c88b163b02c21a9f21f87d49678a0aa21ff30
 F src/os_os2.c 75a8c7b9a00a2cf1a65f9fa4afbc27d46634bb2f
 F src/os_unix.c 5bf0015cebe2f21635da2af983c348eb88b3b4c1
 F src/os_win.c 1c7453c2df4dab26d90ff6f91272aea18bcf7053
-F src/pager.c 751ada65b9a4aa0b31c36ffa3f6548200a55ca16
+F src/pager.c 344eddf3c59eed4b4aca31abbf762d0e301ae44d
 F src/pager.h ce5d076f3860a5f2d7460c582cd68383343b33cf
 F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
 F src/pcache.c ace8f6a5ecd4711cc66a1b23053be7109bd437cf
@@ -805,7 +805,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 9bc9b6847303d0324543a9ded8dd0473490122d8 3e646e3f4cd0ca288e444561e951cecfdaee2ab5
-R 9ec1fc417b85c6217c6e7a04071a1912
+P 43463970f5885fb116588695146f2a56cb22804a
+R 0e49b7b76893a9b984350c6fdab0ea9a
 U dan
-Z 5c9ba544c6cd36a35ee164445a4a1f25
+Z ad3f9c0ef28635a13cd67b8f240d7d22
index d1955142890637fbfcf5292530571bf839f89b48..ed4b8c00cd7126a846b79632838433d33d3aa6e4 100644 (file)
@@ -1 +1 @@
-43463970f5885fb116588695146f2a56cb22804a
\ No newline at end of file
+0ae91b0008b242a47385fc1f295c6b645483ee22
\ No newline at end of file
index 4253d659af17c3032edabe9db5eda4d776ecd01d..a6d7f3544026776067439bea3890359adee29286 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -140,7 +140,6 @@ struct Log {
   LogSummary *pSummary;           /* Log file summary data */
   sqlite3_vfs *pVfs;              /* The VFS used to create pFd */
   sqlite3_file *pFd;              /* File handle for log file */
-  int sync_flags;                 /* Flags to use with OsSync() */
   int isLocked;                   /* Non-zero if a snapshot is held open */
   int isWriteLocked;              /* True if this is the writer connection */
   LogSummaryHdr hdr;              /* Log summary header for current snapshot */
@@ -242,42 +241,6 @@ static void logNormalizePath(char *zPath){
   z[j] = 0;
 }
 
-/*
-** Lock the summary file pSummary->fd.
-*/
-static int logSummaryLock(LogSummary *pSummary){
-  int rc;
-  struct flock f;
-  memset(&f, 0, sizeof(f));
-  f.l_type = F_WRLCK;
-  f.l_whence = SEEK_SET;
-  f.l_start = 0;
-  f.l_len = 1;
-  rc = fcntl(pSummary->fd, F_SETLKW, &f);
-  if( rc!=0 ){
-    return SQLITE_IOERR;
-  }
-  return SQLITE_OK;
-}
-
-/*
-** Unlock the summary file pSummary->fd.
-*/
-static int logSummaryUnlock(LogSummary *pSummary){
-  int rc;
-  struct flock f;
-  memset(&f, 0, sizeof(f));
-  f.l_type = F_UNLCK;
-  f.l_whence = SEEK_SET;
-  f.l_start = 0;
-  f.l_len = 1;
-  rc = fcntl(pSummary->fd, F_SETLK, &f);
-  if( rc!=0 ){
-    return SQLITE_IOERR;
-  }
-  return SQLITE_OK;
-}
-
 /*
 ** Memory map the first nByte bytes of the summary file opened with 
 ** pSummary->fd at pSummary->aData. If the summary file is smaller than
@@ -875,7 +838,6 @@ int sqlite3LogOpen(
   if( !pRet ) goto out;
   pRet->pVfs = pVfs;
   pRet->pFd = (sqlite3_file *)&pRet[1];
-  pRet->sync_flags = SQLITE_SYNC_NORMAL;
 
   /* Normalize the path name. */
   zWal = sqlite3_mprintf("%s-wal", zDb);
@@ -1038,6 +1000,7 @@ static void logIteratorFree(LogIterator *p){
 static int logCheckpoint(
   Log *pLog,                      /* Log connection */
   sqlite3_file *pFd,              /* File descriptor open on db file */
+  int sync_flags,                 /* Flags for OsSync() (or 0) */
   u8 *zBuf                        /* Temporary buffer to use */
 ){
   int rc;                         /* Return code */
@@ -1055,8 +1018,10 @@ static int logCheckpoint(
   if( !pIter ) return SQLITE_NOMEM;
 
   /* Sync the log file to disk */
-  rc = sqlite3OsSync(pLog->pFd, pLog->sync_flags);
-  if( rc!=SQLITE_OK ) goto out;
+  if( sync_flags ){
+    rc = sqlite3OsSync(pLog->pFd, sync_flags);
+    if( rc!=SQLITE_OK ) goto out;
+  }
 
   /* Iterate through the contents of the log, copying data to the db file. */
   while( 0==logIteratorNext(pIter, &iDbpage, &iFrame) ){
@@ -1073,8 +1038,10 @@ static int logCheckpoint(
   if( rc!=SQLITE_OK ) goto out;
 
   /* Sync the database file. If successful, update the log-summary. */
-  rc = sqlite3OsSync(pFd, pLog->sync_flags);
-  if( rc!=SQLITE_OK ) goto out;
+  if( sync_flags ){
+    rc = sqlite3OsSync(pFd, sync_flags);
+    if( rc!=SQLITE_OK ) goto out;
+  }
   pLog->hdr.iLastPg = 0;
   pLog->hdr.iCheck1 = 2;
   pLog->hdr.iCheck2 = 3;
@@ -1111,6 +1078,7 @@ static int logCheckpoint(
 int sqlite3LogClose(
   Log *pLog,                      /* Log to close */
   sqlite3_file *pFd,              /* Database file */
+  int sync_flags,                 /* Flags to pass to OsSync() (or 0) */
   u8 *zBuf                        /* Buffer of at least page-size bytes */
 ){
   int rc = SQLITE_OK;
@@ -1154,7 +1122,7 @@ int sqlite3LogClose(
         **   2. Truncate the log file.
         **   3. Unlink the log-summary file.
         */
-        rc = logCheckpoint(pLog, pFd, zBuf);
+        rc = logCheckpoint(pLog, pFd, sync_flags, zBuf);
         if( rc==SQLITE_OK ){
           rc = sqlite3OsDelete(pLog->pVfs, pSummary->zPath, 0);
         }
@@ -1181,17 +1149,6 @@ int sqlite3LogClose(
   return rc;
 }
 
-/*
-** Set the flags to pass to the sqlite3OsSync() function when syncing
-** the log file.
-*/
-#if 0
-void sqlite3LogSetSyncflags(Log *pLog, int sync_flags){
-  assert( sync_flags==SQLITE_SYNC_NORMAL || sync_flags==SQLITE_SYNC_FULL );
-  pLog->sync_flags = sync_flags;
-}
-#endif
-
 /*
 ** Enter and leave the log-summary mutex. In this context, entering the
 ** log-summary mutex means:
@@ -1487,7 +1444,7 @@ int sqlite3LogFrames(
   PgHdr *pList,                   /* List of dirty pages to write */
   Pgno nTruncate,                 /* Database size after this commit */
   int isCommit,                   /* True if this is a commit */
-  int isSync                      /* True to sync the log file */
+  int sync_flags                  /* Flags to pass to OsSync() (or 0) */
 ){
   int rc;                         /* Used to catch return codes */
   u32 iFrame;                     /* Next frame address */
@@ -1544,7 +1501,7 @@ int sqlite3LogFrames(
   }
 
   /* Sync the log file if the 'isSync' flag was specified. */
-  if( isSync ){
+  if( sync_flags ){
     i64 iSegment = sqlite3OsSectorSize(pLog->pFd);
     i64 iOffset = logFrameOffset(iFrame+1, nPgsz);
 
@@ -1570,7 +1527,7 @@ int sqlite3LogFrames(
       iOffset += nPgsz;
     }
 
-    rc = sqlite3OsSync(pLog->pFd, pLog->sync_flags);
+    rc = sqlite3OsSync(pLog->pFd, sync_flags);
     if( rc!=SQLITE_OK ){
       return rc;
     }
@@ -1623,6 +1580,7 @@ int sqlite3LogFrames(
 int sqlite3LogCheckpoint(
   Log *pLog,                      /* Log connection */
   sqlite3_file *pFd,              /* File descriptor open on db file */
+  int sync_flags,                 /* Flags to sync db file with (or 0) */
   u8 *zBuf,                       /* Temporary buffer to use */
   int (*xBusyHandler)(void *),    /* Pointer to busy-handler function */
   void *pBusyHandlerArg           /* Argument to pass to xBusyHandler */
@@ -1649,7 +1607,7 @@ int sqlite3LogCheckpoint(
   /* Copy data from the log to the database file. */
   rc = logSummaryReadHdr(pLog, 0);
   if( rc==SQLITE_OK ){
-    rc = logCheckpoint(pLog, pFd, zBuf);
+    rc = logCheckpoint(pLog, pFd, sync_flags, zBuf);
   }
 
   /* Release the locks. */
index 816f9354eb49eacc53c5a928c9bc5c1cd90bc84b..5da5fb10513d3a7dfe12f42bc05f02aaa39a91db 100644 (file)
--- a/src/log.h
+++ b/src/log.h
 
 #include "sqliteInt.h"
 
-/* Flags that may be set in the 'flags' argument to sqlite3LogWrite(): */
-#define LOG_MASK_COMMIT        0x08
-#define LOG_MASK_MASTERJOURNAL 0x10
-#define LOG_MASK_TRUNCATE      0x20
-
-
-#define LOG_TRUNCATE_BIT       0x80000000 
-
 /* Connection to a log file. There is one object of this type for each pager. */
 typedef struct Log Log;
 
 /* Open and close a connection to a log file. */
 int sqlite3LogOpen(sqlite3_vfs*, const char *zDb, Log **ppLog);
-int sqlite3LogClose(Log *pLog, sqlite3_file *pFd, u8 *zBuf);
-
-/* Configure the log connection. */
-void sqlite3LogSetSyncflags(Log *, int sync_flags);
+int sqlite3LogClose(Log *pLog, sqlite3_file *pFd, int sync_flags, u8 *zBuf);
 
-/* Used by readers to open (lock) and close (unlock) a database snapshot. */
+/* Used by readers to open (lock) and close (unlock) a snapshot. */
 int sqlite3LogOpenSnapshot(Log *pLog, int *);
 void sqlite3LogCloseSnapshot(Log *pLog);
 
@@ -48,13 +37,14 @@ void sqlite3LogMaxpgno(Log *pLog, Pgno *pPgno);
 /* Obtain or release the WRITER lock. */
 int sqlite3LogWriteLock(Log *pLog, int op);
 
-/* Write a segment to the log. */
+/* Write a frame or frames to the log. */
 int sqlite3LogFrames(Log *pLog, int, PgHdr *, Pgno, int, int);
 
 /* Copy pages from the log to the database file */ 
 int sqlite3LogCheckpoint(
   Log *pLog,                      /* Log connection */
   sqlite3_file *pFd,              /* File descriptor open on db file */
+  int sync_flags,                 /* Flags to sync db file with (or 0) */
   u8 *zBuf,                       /* Temporary buffer to use */
   int (*xBusyHandler)(void *),    /* Pointer to busy-handler function */
   void *pBusyHandlerArg           /* Argument to pass to xBusyHandler */
index 68d561400f78a6b896b86e223a7c504965cfbcf1..5fb259ff73e7094aaa32519bf5a0c38afebb1c8b 100644 (file)
@@ -2871,7 +2871,9 @@ int sqlite3PagerClose(Pager *pPager){
   sqlite3BeginBenignMalloc();
   pPager->errCode = 0;
   pPager->exclusiveMode = 0;
-  sqlite3LogClose(pPager->pLog, pPager->fd, pTmp);
+  sqlite3LogClose(pPager->pLog, pPager->fd, 
+    (pPager->noSync ? 0 : pPager->sync_flags), pTmp
+  );
   pPager->pLog = 0;
   pager_reset(pPager);
   if( MEMDB ){
@@ -4881,7 +4883,7 @@ int sqlite3PagerCommitPhaseOne(
       PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
       if( pList ){
         rc = sqlite3LogFrames(pPager->pLog, pPager->pageSize, pList,
-            pPager->dbSize, 1, pPager->fullSync
+            pPager->dbSize, 1, (pPager->fullSync ? pPager->sync_flags : 0)
         );
       }
       sqlite3PcacheCleanAll(pPager->pPCache);
@@ -5700,6 +5702,7 @@ int sqlite3PagerCheckpoint(Pager *pPager){
   if( pPager->pLog ){
     u8 *zBuf = (u8 *)pPager->pTmpSpace;
     rc = sqlite3LogCheckpoint(pPager->pLog, pPager->fd, 
+        (pPager->noSync ? 0 : pPager->sync_flags),
         zBuf, pPager->xBusyHandler, pPager->pBusyHandlerArg
     );
   }