]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Avoid reading frames that have already been checkpointed from the wal file.
authordan <dan@noemail.net>
Wed, 12 Aug 2015 19:42:08 +0000 (19:42 +0000)
committerdan <dan@noemail.net>
Wed, 12 Aug 2015 19:42:08 +0000 (19:42 +0000)
FossilOrigin-Name: 5669ac4a40429abc3f44540fc9d2f3b79b404bdf

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

index c0121c70db7cf97100cea2ff10b2b6340285eca7..ebe04a4a711bac6aff3058dbe04cc7589812531b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Minor\soptimization\sfor\sfts5\sAPI\sxInst().
-D 2015-08-12T15:36:58.855
+C Avoid\sreading\sframes\sthat\shave\salready\sbeen\scheckpointed\sfrom\sthe\swal\sfile.
+D 2015-08-12T19:42:08.239
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2fc9ca6bf5949d415801c007ed3004a4bdb7c380
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -408,7 +408,7 @@ F src/vdbesort.c f5009e7a35e3065635d8918b9a31f498a499976b
 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0
 F src/vtab.c 082b35a25a26e3d36f365ca8cd73c1922532f05e
 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
-F src/wal.c 6fb6b68969e4692593c2552c4e7bff5882de2cb8
+F src/wal.c 9eb487483eed48310f999d9735263f33c71026b3
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
 F src/where.c c745d3aa78ad1aa8982febb99f2f17ee5cbac069
@@ -1256,7 +1256,7 @@ F test/wal2.test 1f841d2048080d32f552942e333fd99ce541dada
 F test/wal3.test 2b5445e5da44780b9b44712f5a38523f7aeb0941
 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
 F test/wal5.test 88b5d9a6a3d1532497ee9f4296f010d66f07e33c
-F test/wal6.test 527581f5527bf9c24394991e2be83000aace5f9e
+F test/wal6.test 4421cd5a2fa99d29cc91ef12fb23bed171ed3a4c
 F test/wal64k.test 163655ecd2cb8afef4737cac2a40fdd2eeaf20b8
 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd
 F test/wal8.test 75c42e1bc4545c277fed212f8fc9b7723cd02216
@@ -1372,7 +1372,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P f7682435278419829a46bb4cc9b5625d46549e22
-R 5c7dc1bc59e7a8c21161b1ef8857c7b8
+P efb7c9c5d0015c8c966f8d6742c05cda82fc146a
+R 91c715455a10615960997cdbeb286182
+T *branch * wal-read-change
+T *sym-wal-read-change *
+T -sym-trunk *
 U dan
-Z c11fd987f7eb5e43e308c10674f8c3b9
+Z 265f3376267bf1285595a2e2dc6d13aa
index 584731300e9206a815d722b9e1f92893fa743577..52606f1923920086f1a14ca5103918c409d6af95 100644 (file)
@@ -1 +1 @@
-efb7c9c5d0015c8c966f8d6742c05cda82fc146a
\ No newline at end of file
+5669ac4a40429abc3f44540fc9d2f3b79b404bdf
\ No newline at end of file
index f7e2594001c257a863347eda396ec849d859096a..0e4d07d37205123a50e75d020c0c84428cc8b4a5 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -2372,6 +2372,8 @@ int sqlite3WalFindFrame(
   u32 iRead = 0;                  /* If !=0, WAL frame to return data from */
   u32 iLast = pWal->hdr.mxFrame;  /* Last page in WAL for this reader */
   int iHash;                      /* Used to loop through N hash tables */
+  u32 iFirst;
+  int iMinHash;
 
   /* This routine is only be called from within a read transaction. */
   assert( pWal->readLock>=0 || pWal->lockError );
@@ -2382,7 +2384,10 @@ int sqlite3WalFindFrame(
   ** then the WAL is ignored by the reader so return early, as if the 
   ** WAL were empty.
   */
-  if( iLast==0 || pWal->readLock==0 ){
+  if( iLast==0 
+   || pWal->readLock==0 
+   || iLast==(iFirst = walCkptInfo(pWal)->nBackfill)
+  ){
     *piRead = 0;
     return SQLITE_OK;
   }
@@ -2412,7 +2417,8 @@ int sqlite3WalFindFrame(
   **     This condition filters out entries that were added to the hash
   **     table after the current read-transaction had started.
   */
-  for(iHash=walFramePage(iLast); iHash>=0 && iRead==0; iHash--){
+  iMinHash = walFramePage(iFirst);
+  for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){
     volatile ht_slot *aHash;      /* Pointer to hash table */
     volatile u32 *aPgno;          /* Pointer to array of page numbers */
     u32 iZero;                    /* Frame number corresponding to aPgno[0] */
@@ -2427,7 +2433,7 @@ int sqlite3WalFindFrame(
     nCollide = HASHTABLE_NSLOT;
     for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
       u32 iFrame = aHash[iKey] + iZero;
-      if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
+      if( iFrame<=iLast && iFrame>iFirst && aPgno[aHash[iKey]]==pgno ){
         assert( iFrame>iRead || CORRUPT_DB );
         iRead = iFrame;
       }
index 2498907ea908549f9ecc636b0ba1ba3170565fa3..d96166ef5975eef37f4c7af86caa419ead663a90 100644 (file)
@@ -193,5 +193,47 @@ do_test 3.x {
   db2 close
 } {}
 
+#-------------------------------------------------------------------------
+# Check that if a wal file has been partially checkpointed, no frames are
+# read from the checkpointed part.
+#
+reset_db
+do_execsql_test 4.1 {
+  PRAGMA page_size = 1024;
+  PRAGMA journal_mode = wal;
+  CREATE TABLE t1(a, b);
+  CREATE TABLE t2(a, b);
+  PRAGMA wal_checkpoint = truncate;
+} {wal 0 0 0}
+
+do_test 4.2 {
+  execsql { INSERT INTO t1 VALUES(1, 2) }
+  file size test.db-wal
+} [wal_file_size 1 1024]
+
+do_test 4.3 {
+  sqlite3 db2 test.db
+  execsql { 
+    BEGIN;
+    INSERT INTO t2 VALUES(3, 4);
+  }
+  execsql { PRAGMA wal_checkpoint = passive } db2
+} {0 1 1}
+
+do_test 4.3 {
+  execsql { COMMIT }
+  db2 close
+  hexio_write test.db-wal 0 [string repeat 00 2000]
+  sqlite3 db2 test.db
+} {}
+
+do_test 4.4.1 { 
+  catchsql { SELECT * FROM t1 } db2 
+} {0 {1 2}}
+do_test 4.4.2 { 
+  catchsql { SELECT * FROM t2 } db2 
+} {1 {database disk image is malformed}}
+
+
 finish_test