]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In persistent WAL mode, truncate the WAL file to the size specified by the
authordrh <drh@noemail.net>
Thu, 8 Dec 2011 19:50:32 +0000 (19:50 +0000)
committerdrh <drh@noemail.net>
Thu, 8 Dec 2011 19:50:32 +0000 (19:50 +0000)
journal_size_limit pragma when disconnecting from the WAL.

FossilOrigin-Name: 9687b305c2320109a8649612181eecd2e0da7c7b

manifest
manifest.uuid
src/wal.c
test/walpersist.test

index 349c059ce82107a0f906aac62b49a4dea327061a..5a23b09df7f4b9ce704c2fbe9cefe383b4f08b1c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Follow\sthe\spreviously\sestablished\spattern\sfor\sdetecting\spreprocessor\sdefines\sfor\sspecific\sflavors\sof\sWindows\s(for\sNT\sin\sthis\scase).
-D 2011-12-08T03:51:12.637
+C In\spersistent\sWAL\smode,\struncate\sthe\sWAL\sfile\sto\sthe\ssize\sspecified\sby\sthe\njournal_size_limit\spragma\swhen\sdisconnecting\sfrom\sthe\sWAL.
+D 2011-12-08T19:50:32.953
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -249,7 +249,7 @@ F src/vdbemem.c 2fc78b3e0fabcc1eaa23cd79dd2e30e6dcfe1e56
 F src/vdbesort.c 468d43c057063e54da4f1988b38b4f46d60e7790
 F src/vdbetrace.c 5d0dc3d5fd54878cc8d6d28eb41deb8d5885b114
 F src/vtab.c e9318d88feac85be8e27ee783ac8f5397933fc8a
-F src/wal.c 5fe1ba55b8fab9d3936bc9093af61ab9f1c580a1
+F src/wal.c 7e6e7fe68ee649505dca38c8ab83eda0d0d96ae5
 F src/wal.h 66b40bd91bc29a5be1c88ddd1f5ade8f3f48728a
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c f73752ca85c0ed221753fda98aeaf6b9d4616e0e
@@ -912,7 +912,7 @@ F test/walfault.test efb0d5724893133e71b8d9d90abdb781845a6bb0
 F test/walhook.test ed00a40ba7255da22d6b66433ab61fab16a63483
 F test/walmode.test 4022fe03ae6e830583672caa101f046438a0473c
 F test/walnoshm.test 84ca10c544632a756467336b7c3b864d493ee496
-F test/walpersist.test fd40d33765b2693f721c90c66d97f99757559006
+F test/walpersist.test 710b1b6cf6f8333e984f437724d1fa9e0511c5aa
 F test/walro.test e6bb27762c9f22601cbb8bff6e0acfd124e74b63
 F test/walshared.test 6dda2293880c300baf5d791c307f653094585761
 F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a
@@ -977,7 +977,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
-P 7fc535090ca3416706dff4abce10ac2d7f775e02
-R 6482ffb35478eb08f1e552e0a44aef9d
-U mistachkin
-Z 72aea825d319aa78f5f6763f21c44870
+P a0d92193dd5ae97608748f354aa17eb188431546
+R 2af387da3b388b68a597840e0b4cefff
+U drh
+Z 15eed8d4acdafc18909017c3c88afe5e
index f6b26e4b22f408d9e2fafa915d386e24ae955085..ca3c77e6c40adcf2db9c03e991b787155d6591c4 100644 (file)
@@ -1 +1 @@
-a0d92193dd5ae97608748f354aa17eb188431546
\ No newline at end of file
+9687b305c2320109a8649612181eecd2e0da7c7b
\ No newline at end of file
index 2c905a29e926d11c89c6f4eff2ce393c911d9c71..209c9097521c9c94071d605da0b92609a0006cf9 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -1781,6 +1781,26 @@ static int walCheckpoint(
   return rc;
 }
 
+/*
+** Attempt to limit the WAL size to the size limit defined by
+** PRAGMA journal_size_limit.
+*/
+static void walLimitSize(Wal *pWal){
+  if( pWal->mxWalSize>=0 ){
+    i64 sz;
+    int rx;
+    sqlite3BeginBenignMalloc();
+    rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
+    if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
+      rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
+    }
+    sqlite3EndBenignMalloc();
+    if( rx ){
+      sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
+    }
+  }
+}
+
 /*
 ** Close a connection to a log file.
 */
@@ -1814,6 +1834,8 @@ int sqlite3WalClose(
       sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersistWal);
       if( rc==SQLITE_OK && bPersistWal!=1 ){
         isDelete = 1;
+      }else{
+        walLimitSize(pWal);
       }
     }
 
@@ -2518,6 +2540,7 @@ int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData){
   return rc;
 }
 
+
 /*
 ** This function is called just before writing a set of frames to the log
 ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
@@ -2555,23 +2578,7 @@ static int walRestartLog(Wal *pWal){
         int i;                    /* Loop counter */
         u32 *aSalt = pWal->hdr.aSalt;       /* Big-endian salt values */
 
-        /* Limit the size of WAL file if the journal_size_limit PRAGMA is
-        ** set to a non-negative value.  Log errors encountered
-        ** during the truncation attempt. */
-        if( pWal->mxWalSize>=0 ){
-          i64 sz;
-          int rx;
-          sqlite3BeginBenignMalloc();
-          rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
-          if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
-            rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
-          }
-          sqlite3EndBenignMalloc();
-          if( rx ){
-            sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
-          }
-        }
-
+        walLimitSize(pWal);
         pWal->nCkpt++;
         pWal->hdr.mxFrame = 0;
         sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
index 175dcbf89603e874fbcac092f5ce82c72cc6dc7a..bf65bd1e1387a3b268bfd0870b7d3789d529bbb8 100644 (file)
@@ -67,7 +67,25 @@ do_test walpersist-1.11 {
   list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
 } {1 1 1}
 
-  
-
+# Make sure the journal_size_limit works to limit the size of the
+# persisted wal file.
+forcedelete test.db test.db-shm test.db-wal
+do_test walpersist-2.1 {
+  sqlite3 db test.db
+  db eval {
+    PRAGMA journal_mode=WAL;
+    PRAGMA wal_autocheckpoint=OFF;
+    PRAGMA journal_size_limit=12000;
+    CREATE TABLE t1(x);
+    INSERT INTO t1 VALUES(randomblob(50000));
+    UPDATE t1 SET x=randomblob(50000);
+  }
+  expr {[file size test.db-wal]>100000}
+} {1}
+do_test walpersist-2.2 {
+  file_control_persist_wal db 1
+  db close
+  file size test.db-wal
+} {12000}
 
 finish_test