]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When committing a WAL transaction, do not write any pages to the WAL file with page...
authordan <dan@noemail.net>
Tue, 5 Apr 2011 16:09:08 +0000 (16:09 +0000)
committerdan <dan@noemail.net>
Tue, 5 Apr 2011 16:09:08 +0000 (16:09 +0000)
FossilOrigin-Name: 311d0b613d9cfa2dbcbb9ef2450041b1fd48770a

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

index 2b406206a10c51dc6d0ffbd47da21cd37724b655..70ae57dd5d864c5787f7b564220179b01639e64f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sdocumentation\stypo.
-D 2011-04-05T14:22:48.053
+C When\scommitting\sa\sWAL\stransaction,\sdo\snot\swrite\sany\spages\sto\sthe\sWAL\sfile\swith\spage\snumbers\sgreater\sthan\sthe\ssize\sof\sthe\sdatabase\simage\sin\spages.
+D 2011-04-05T16:09:08.127
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -164,7 +164,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
 F src/os_os2.c 2596fd2d5d0976c6c0c628d0c3c7c4e7a724f4cf
 F src/os_unix.c 32414676594a0a26cfccd7e02656230a3406eee7
 F src/os_win.c 24d72407a90551969744cf9bcbb1b4c72c5fa845
-F src/pager.c 6aa906b60a59664ba58d3f746164bb010d407ce1
+F src/pager.c 055239dcdfe12b3f5d97f6f01f85da01e2d6d912
 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1
 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
 F src/pcache.c 09d38c44ab275db581f7a2f6ff8b9bc7f8c0faaa
@@ -860,7 +860,7 @@ F test/vtabE.test 7c4693638d7797ce2eda17af74292b97e705cc61
 F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
-F test/wal.test 973a4747a69247a43cc03292c44f59cc76f4df65
+F test/wal.test 084b086913a205eab4dde4b9a9cf8c781a576bb8
 F test/wal2.test e561a8c6fdd1c2cd1876f3e39757934e7b7361f8
 F test/wal3.test 5c396cc22497244d627306f4c1d360167353f8dd
 F test/wal4.test 3404b048fa5e10605facaf70384e6d2943412e30
@@ -926,7 +926,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 5db4511d8a77b74be3503a7c34257ef6b07541f5
-R f66ac9973277650bde436573608ca94f
-U drh
-Z c91a504724af14c0a00d31f50ea2afef
+P d25c17ef6e2b916923489dccaaa018a2d6525401
+R c888a09e2325a742237e83457c23e497
+U dan
+Z 881050430264f599344995b52c518cce
index b15abcdb1158c65d6cd33f8ea5d5706996bba1ae..7db1b81310ac324bc48928f185d7ed67c6be4c9b 100644 (file)
@@ -1 +1 @@
-d25c17ef6e2b916923489dccaaa018a2d6525401
\ No newline at end of file
+311d0b613d9cfa2dbcbb9ef2450041b1fd48770a
\ No newline at end of file
index da13ddc6fead19d788439a2fac2b6bffc2b7a428..94f647dcc94e05653f30484f6b1ec2036a70f457 100644 (file)
@@ -2972,6 +2972,19 @@ static int pagerWalFrames(
   }
 #endif
 
+  if( isCommit ){
+    /* If a WAL transaction is being committed, there is no point in writing
+    ** any pages with page numbers greater than nTruncate into the WAL file.
+    ** They will never be read by any client. So remove them from the pDirty
+    ** list here. */
+    PgHdr *p;
+    PgHdr **ppNext = &pList;
+    for(p=pList; (*ppNext = p); p=p->pDirty){
+      if( p->pgno<=nTruncate ) ppNext = &p->pDirty;
+    }
+    assert( pList );
+  }
+
   if( pList->pgno==1 ) pager_write_changecounter(pList);
   rc = sqlite3WalFrames(pPager->pWal, 
       pPager->pageSize, pList, nTruncate, isCommit, syncFlags
@@ -2984,6 +2997,7 @@ static int pagerWalFrames(
   }
 
 #ifdef SQLITE_CHECK_PAGES
+  pList = sqlite3PcacheDirtyList(pPager->pPCache);
   for(p=pList; p; p=p->pDirty){
     pager_set_pagehash(p);
   }
index 257a87b0926fe15760e7cc0c9a6a08e9d3fd243b..ff88f314d20fcd19e06a2ece86fe07444cf29593 100644 (file)
@@ -19,6 +19,8 @@ source $testdir/lock_common.tcl
 source $testdir/malloc_common.tcl
 source $testdir/wal_common.tcl
 
+set testprefix wal
+
 ifcapable !wal {finish_test ; return }
 
 proc reopen_db {} {
@@ -1504,6 +1506,54 @@ do_test wal-23.4 {
   set ::log 
 } [list SQLITE_OK "Recovered $nPage frames from WAL file $walfile"]
 
+
+ifcapable autovacuum {
+  # This block tests that if the size of a database is reduced by a 
+  # transaction (because of an incremental or auto-vacuum), that no
+  # data is written to the WAL file for the truncated pages as part
+  # of the commit. e.g. if a transaction reduces the size of a database
+  # to N pages, data for page N+1 should not be written to the WAL file 
+  # when committing the transaction. At one point such data was being 
+  # written.
+  #
+  catch {db close}
+  forcedelete test.db
+  sqlite3 db test.db
+  do_execsql_test 24.1 {
+    PRAGMA auto_vacuum = 2;
+    PRAGMA journal_mode = WAL;
+    PRAGMA page_size = 1024;
+    CREATE TABLE t1(x);
+    INSERT INTO t1 VALUES(randomblob(5000));
+    INSERT INTO t1 SELECT * FROM t1;
+    INSERT INTO t1 SELECT * FROM t1;
+    INSERT INTO t1 SELECT * FROM t1;
+    INSERT INTO t1 SELECT * FROM t1;
+  } {wal}
+  do_execsql_test 24.2 { 
+    DELETE FROM t1;
+    PRAGMA wal_checkpoint;
+  } {0 109 109}
+  do_test 24.3 {
+    db close
+    sqlite3 db test.db
+    file exists test.db-wal
+  } 0
+  do_test 24.4 {
+    file size test.db
+  } [expr 84 * 1024]
+  do_test 24.5 {
+    execsql { 
+      PRAGMA incremental_vacuum;
+      PRAGMA wal_checkpoint;
+    }
+    file size test.db
+  } [expr 3 * 1024]
+  do_test 24.6 {
+    file size test.db-wal
+  } 2128
+}
+
 db close
 sqlite3_shutdown
 test_sqlite3_log