]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Return SQLITE_BUSY (not SQLITE_BUSY_SNAPSHOT) if sqlite3_snapshot_open() fails to...
authordan <dan@noemail.net>
Thu, 10 Dec 2015 19:11:34 +0000 (19:11 +0000)
committerdan <dan@noemail.net>
Thu, 10 Dec 2015 19:11:34 +0000 (19:11 +0000)
FossilOrigin-Name: 5343060bcc6c99029f731f8020d2cba3f405f207

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

index 2b87b9f307486c854efd61b5632cdb1e96701d09..a3a772f96ee83eafa409732659e6f9acae1af065 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\stests\sto\sensure\sthat\san\ssqlite3_snapshot_open()\sclient\scannot\sbe\stricked\sinto\sreading\sa\scorrupt\ssnapshot\seven\sif\sanother\sprocess\sfails\smid-checkpoint.
-D 2015-12-10T18:06:21.050
+C Return\sSQLITE_BUSY\s(not\sSQLITE_BUSY_SNAPSHOT)\sif\ssqlite3_snapshot_open()\sfails\sto\sobtain\sthe\sshared\scheckpointer\slock.
+D 2015-12-10T19:11:34.013
 F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc e8fdca1cb89a1b58b5f4d3a130ea9a3d28cb314d
@@ -415,7 +415,7 @@ F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d
 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0
 F src/vtab.c 2a8b44aa372c33f6154208e7a7f6c44254549806
 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
-F src/wal.c 32ee7dc4b689321d1650fba2e937ddc3bccfb06f
+F src/wal.c 94576d273e7feeae598188ebec641906a5b93a2f
 F src/wal.h 907943dfdef10b583e81906679a347e0ec6f1b1b
 F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba
 F src/where.c b18edbb9e5afabb77f4f27550c471c5c824e0fe7
@@ -1020,7 +1020,7 @@ F test/skipscan2.test d1d1450952b7275f0b0a3a981f0230532743951a
 F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5
 F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2
 F test/skipscan6.test 5866039d03a56f5bd0b3d172a012074a1d90a15b
-F test/snapshot.test 5631669a133c96aaa228f7233989f6d2d069fb02
+F test/snapshot.test 184c7ed21f204a5bd909246560edfac308467609
 F test/snapshot_fault.test 06472056c516be4610834de4688ea3357e8bde01
 F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
 F test/softheap1.test 843cd84db9891b2d01b9ab64cef3e9020f98d087
@@ -1410,7 +1410,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 8084eae0bc4f6513b1147fb890a6b2813f1c0a09
-R b7a6ff87063d246e894cc3fd88f3e89f
+P b908048b6cfa1ee2fe1f7a17bae475ddd9d0376c
+R 1311c20224293debd3e251bf775d0f5c
 U dan
-Z 1fe7db1e51b0eef5aa529631bb7527d1
+Z ae2ff3e1ce7fc4e495f8fcae9626097f
index 82eea9660d6e76853ad1a38f0844e5715eb004b4..202cc78fbbe266b2cabaa2f4944dd04e13493e01 100644 (file)
@@ -1 +1 @@
-b908048b6cfa1ee2fe1f7a17bae475ddd9d0376c
\ No newline at end of file
+5343060bcc6c99029f731f8020d2cba3f405f207
\ No newline at end of file
index 0439ed42537834fa2ade034569eed51ceb5aaa4c..e5527029ac6db62353b04484dc9f1b9ac1d7ab88 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -2432,23 +2432,26 @@ int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
       ** before checking pInfo->nBackfillAttempted.  */
       rc = walLockShared(pWal, WAL_CKPT_LOCK);
 
-      /* Check that the wal file has not been wrapped. Assuming that it has
-      ** not, also check that no checkpointer has attempted to checkpoint
-      ** any frames beyond pSnapshot->mxFrame. If either of these conditions
-      ** are true, return SQLTIE_BUSY_SNAPSHOT. Otherwise, overwrite pWal->hdr
-      ** with *pSnapshot and set *pChanged as appropriate for opening the
-      ** snapshot.  */
-      if( memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt))==0
-       && pSnapshot->mxFrame>=pInfo->nBackfillAttempted
-      ){
-        memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr));
-        *pChanged = bChanged;
-      }else{
-        rc = SQLITE_BUSY_SNAPSHOT;
+      if( rc==SQLITE_OK ){
+        /* Check that the wal file has not been wrapped. Assuming that it has
+        ** not, also check that no checkpointer has attempted to checkpoint any
+        ** frames beyond pSnapshot->mxFrame. If either of these conditions are
+        ** true, return SQLITE_BUSY_SNAPSHOT. Otherwise, overwrite pWal->hdr
+        ** with *pSnapshot and set *pChanged as appropriate for opening the
+        ** snapshot.  */
+        if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt))
+         && pSnapshot->mxFrame>=pInfo->nBackfillAttempted
+        ){
+          memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr));
+          *pChanged = bChanged;
+        }else{
+          rc = SQLITE_BUSY_SNAPSHOT;
+        }
+
+        /* Release the shared CKPT lock obtained above. */
+        walUnlockShared(pWal, WAL_CKPT_LOCK);
       }
 
-      /* Release the shared CKPT lock obtained above. */
-      walUnlockShared(pWal, WAL_CKPT_LOCK);
 
       if( rc!=SQLITE_OK ){
         sqlite3WalEndReadTransaction(pWal);
index c74a2859febab6c828c8e3e8ddd1868a959dcc4f..564881cae1ac0e1d6f085a4d826383995464009e 100644 (file)
@@ -246,5 +246,49 @@ do_test 4.2.4 {
   sqlite3_snapshot_free $snapshot
 } {}
 
+#-------------------------------------------------------------------------
+# Check that SQLITE_BUSY is returned if a checkpoint is running when
+# sqlite3_snapshot_open() is called.
+#
+reset_db
+db close
+testvfs tvfs
+sqlite3 db test.db -vfs tvfs
+
+do_execsql_test 5.1 {
+  PRAGMA journal_mode = wal;
+  CREATE TABLE x1(x, xx, xxx);
+  INSERT INTO x1 VALUES('z', 'zz', 'zzz');
+  BEGIN;
+    SELECT * FROM x1;
+} {wal z zz zzz}
+
+do_test 5.2 {
+  set ::snapshot [sqlite3_snapshot_get db main]
+  sqlite3 db2 test.db -vfs tvfs
+  execsql {
+    INSERT INTO x1 VALUES('a', 'aa', 'aaa');
+    COMMIT;
+  }
+} {}
+
+set t53 0
+proc write_callback {args} {
+breakpoint
+  do_test 5.3.[incr ::t53] {
+    execsql BEGIN
+    list [catch { sqlite3_snapshot_open db main $::snapshot } msg] $msg
+  } {1 SQLITE_BUSY}
+  catchsql COMMIT
+}
+
+tvfs filter xWrite
+tvfs script write_callback
+db2 eval { PRAGMA wal_checkpoint }
+db close
+db2 close
+tvfs delete
+sqlite3_snapshot_free $snapshot
+
 finish_test