]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Increase coverage provided by permutation "coverage-wal" on this branch.
authordan <dan@noemail.net>
Sat, 29 Dec 2018 16:34:22 +0000 (16:34 +0000)
committerdan <dan@noemail.net>
Sat, 29 Dec 2018 16:34:22 +0000 (16:34 +0000)
FossilOrigin-Name: f664f940a7eb6938b1ee171143a691e2f497aec921f979be63ef844d38053f56

manifest
manifest.uuid
src/wal.c
test/concfault2.test [new file with mode: 0644]
test/concurrent2.test
test/permutations.test
test/wal2recover2.test
test/wal2savepoint.test
test/wal2snapshot.test

index 150a647bf7028f578fce5ddeab16621c875d49a2..e3a877e463ea982da7ca284cdd15893179c9bfc1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\slatest\swal2\schanges\swith\sthis\sbranch.
-D 2018-12-27T17:11:59.756
+C Increase\scoverage\sprovided\sby\spermutation\s"coverage-wal"\son\sthis\sbranch.
+D 2018-12-29T16:34:22.239
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in d8b254f8bb81bab43c340d70d17dc3babab40fcc8a348c8255881f780a45fee6
@@ -597,7 +597,7 @@ F src/vdbesort.c 90aad5a92608f2dd771c96749beabdb562c9d881131a860a7a5bccf66dc3be7
 F src/vdbetrace.c 79d6dbbc479267b255a7de8080eee6e729928a0ef93ed9b0bfa5618875b48392
 F src/vtab.c 70188a745dc4e57d26e942681ff4b2912b7c8249ad5de3f60f0677b4337bcfaa
 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
-F src/wal.c 80b66beb428e6e99abbb3ebc924bf8121936d0185d74931b50ff667779574f09
+F src/wal.c 598891224a5b45d984b8cf24517aa907c47b03d46578bed58f74b7e28b8d3250
 F src/wal.h c398e0269e8f37495cedb63b5e288c2aac6f6d103d05fb55f4affec21311615d
 F src/walker.c fb94aadc9099ff9c6506d0a8b88d51266005bcaa265403f3d7caf732a562eb66
 F src/where.c 3818e8a736a05d2cb194e64399af707e367fbcc5c251d785804d02eaf121288e
@@ -735,8 +735,9 @@ F test/collateB.test 1e68906951b846570f29f20102ed91d29e634854ee47454d725f2151eca
 F test/colmeta.test 2c765ea61ee37bc43bbe6d6047f89004e6508eb1
 F test/colname.test fb28b3687e03625425bc216edf8b186ce974aa71008e2aa1f426a7dcb75a601d
 F test/concfault.test 500f17c3fcfe7705114422bcc6ddd3c740001a43
+F test/concfault2.test 0c4094db632e585244ca3b1cbfb74b794dd93629bf699bd1a2b511055c52c0bc
 F test/concurrent.test 86661967a680670127a62a819e60dc93c2d3d49043ac95b26dfa70d3e60dbde5
-F test/concurrent2.test 9dfbeb0a323733fe1d13443371734bb94a674dbf777f464365475903873111f8
+F test/concurrent2.test f447dfae67e4d80a2b61e2796c2c081564a8126cf96c39a14780e89c8c53eff5
 F test/concurrent3.test 530671ac706f6a1d0f4992dbdd33a86408330d03cd90fb9e82ecb1b27f5fd081
 F test/concurrent4.test e0b12cd467137e50259df3b4f837507e82aaa07c35941c88664dc8ed1d089c44
 F test/concurrent5.test 0c16cbf7446af162a14e6def30445e94016064eb994e5aa4ebb2bebc59554176
@@ -1200,7 +1201,7 @@ F test/pagesize.test 5769fc62d8c890a83a503f67d47508dfdc543305
 F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b
 F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442
 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff
-F test/permutations.test 2ef576293b632574521da217837c185b839b5e5edf379a78261facf4250bba07
+F test/permutations.test 7a4a5b031cff772029df1ab1a65e93d8bd453fbd721180e9d074c9219c32c175
 F test/pg_common.tcl 301ac19c1a52fd55166d26db929b3b89165c634d52b5f8ad76ea8cb06960db30
 F test/pragma.test c267bf02742c823a191960895b3d52933cebd7beee26757d1ed694f213fcd867
 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f
@@ -1621,11 +1622,11 @@ F test/wal2concurrent.test 7fc3e570073683a2a28f42bda46ecf516f5bc82afd703c1fbf4aa
 F test/wal2fault.test 2e8e60cacd5bcd451618aeffd05f676894d17202d3e2986e288d36e2c5993249
 F test/wal2lock.test 0ef98d72dc6bcf7711dedd684760488400d9a9a6eec0dc5d3822060437793552
 F test/wal2recover.test ba8f4bc9397c838734619f9e759bd98b00e355347b3cf80a2e677610d231d5d8
-F test/wal2recover2.test 3176a03eccebb203e5c5635d94624bf573392fccb3f9d39d9d9a27aab96e4c88
+F test/wal2recover2.test dcfedc46a0080aa6d37c762863da2f5c0ec941c46a6cfe85b412e792c08a2ac2
 F test/wal2rewrite.test 6ca6f631ffcf871240beab5f02608913fd075c6d0d31310b026c8383c65c9f9c
-F test/wal2savepoint.test 29725383e7eb8b78fed46333d69dc45b4ed321db43ecc81766aadea991874bef
+F test/wal2savepoint.test 2c82bd6a6ee5066c156040d2e9c2415646fcf96116ae7ad127eaf0c0b4a85f22
 F test/wal2simple.test 96206c98bf64ab20ec00a1c0f6c709e258b98b39f2149889361f31966ce5a703
-F test/wal2snapshot.test 95a919e1c73dee0e0212d10931d03cc1116f68a0ff603163e551aaa5ac7025c1
+F test/wal2snapshot.test f6c3945bea572fd8745774e95b8dca1e5832c696e2251bb0db33391ee567fe60
 F test/wal3.test 2a93004bc0fb2b5c29888964024695bade278ab2
 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
 F test/wal5.test 9c11da7aeccd83a46d79a556ad11a18d3cb15aa9
@@ -1820,7 +1821,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P b3a163b46cad19a2e6a90cdd5b4c2e94d66e80b7ad2a0c9857580fe74748a604 2f7f893a702728745445f6ef5f914c1157058a8fbdfd1a58cfb8906e5566729d
-R 6547c6db80a1c79963844ff8a3982182
+P ea96001e801fbf228d1fb63b9d3c73fd9da54994d3cfe383ea76edfa6da83b8d
+R 42c4829d3c89025ea70567a057d519f0
 U dan
-Z 04d8d4c3b9345edf2ad657de9636b01f
+Z 4b3d49cde64b9c3f6154999717a75fb6
index 2195f75437eadf77df2f8947590f1acc27e4ba98..8da0b44113b13edd3e6443aa63d91135414dbafd 100644 (file)
@@ -1 +1 @@
-ea96001e801fbf228d1fb63b9d3c73fd9da54994d3cfe383ea76edfa6da83b8d
\ No newline at end of file
+f664f940a7eb6938b1ee171143a691e2f497aec921f979be63ef844d38053f56
\ No newline at end of file
index 288bd0cb9d2f5ad32e7a9bb799486942b1a37c16..4ba35d85848a999375b5f21c715562508cf28063 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -1320,9 +1320,7 @@ static void walCleanupHash(Wal *pWal){
   if( mxFrame==0 ) return;
 
   /* Obtain pointers to the hash-table and page-number array containing 
-  ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
-  ** that the page said hash-table and array reside on is already mapped.
-  */
+  ** the entry that corresponds to frame pWal->hdr.mxFrame.  */
   assert( pWal->nWiData>walFramePage(iExternal) );
   assert( pWal->apWiData[walFramePage(iExternal)] );
   walHashGet(pWal, walFramePage(iExternal), &sLoc);
@@ -3870,13 +3868,12 @@ int sqlite3WalLockForCommit(
     }else if( memcmp(&pWal->hdr, (void*)&head, sizeof(WalIndexHdr))!=0 ){
       int bWal2 = isWalMode2(pWal);
       int iHash;
-      int iLastHash = walFramePage(head.mxFrame);
       int nLoop = 1+(bWal2 && walidxGetFile(&head)!=walidxGetFile(&pWal->hdr));
       int iLoop;
       
 
       assert( nLoop==1 || nLoop==2 );
-      for(iLoop=0; iLoop<nLoop && rc==SQLITE_OK; iLoop++){
+      for(iLoop=0; rc==SQLITE_OK && iLoop<nLoop; iLoop++){
         u32 iFirst;               /* First (external) wal frame to check */
         u32 iLastHash;            /* Last hash to check this loop */
         u32 mxFrame;              /* Last (external) wal frame to check */
@@ -3929,7 +3926,7 @@ int sqlite3WalLockForCommit(
                 u8 *aOld = &((u8*)pPage1->pData)[40];
                 int sz;
                 i64 iOff;
-                int iFrame = sLoc.iZero + i;
+                u32 iFrame = sLoc.iZero + i;
                 int iWal = 0;
                 if( bWal2 ){
                   iWal = walExternalDecode(iFrame, &iFrame);
@@ -4049,9 +4046,30 @@ int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
     ** was in before the client began writing to the database. 
     */
     memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
-    assert( walidxGetFile(&pWal->hdr)==iWal );
     iNew = walidxGetMxFrame(&pWal->hdr, walidxGetFile(&pWal->hdr));
 
+    /* BEGIN CONCURRENT transactions are different, as the header just
+    ** memcpy()d into pWal->hdr may not be the same as the current header 
+    ** when the transaction was started. Instead, pWal->hdr now contains
+    ** the header written by the most recent successful COMMIT. Because
+    ** Wal.writeLock is set, if this is a BEGIN CONCURRENT transaction,
+    ** the rollback must be taking place because an error occurred during
+    ** a COMMIT.
+    **
+    ** The code below is still valid. All frames between (iNew+1) and iMax 
+    ** must have been written by this transaction before the error occurred.
+    ** The exception is in wal2 mode - if the current wal file at the time
+    ** of the last COMMIT is not wal file iWal, then the error must have
+    ** occurred in WalLockForCommit(), before any pages were written
+    ** to the database file. In this case return early.  */
+#ifndef SQLITE_OMIT_CONCURRENT
+    if( walidxGetFile(&pWal->hdr)!=iWal ){
+      assert( isWalMode2(pWal) );
+      return SQLITE_OK;
+    }
+#endif
+    assert( walidxGetFile(&pWal->hdr)==iWal );
+
     for(iFrame=iNew+1; ALWAYS(rc==SQLITE_OK) && iFrame<=iMax; iFrame++){
       /* This call cannot fail. Unless the page for which the page number
       ** is passed as the second argument is (a) in the cache and 
diff --git a/test/concfault2.test b/test/concfault2.test
new file mode 100644 (file)
index 0000000..3c46ca4
--- /dev/null
@@ -0,0 +1,65 @@
+# 2018 Dec 28
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file contains fault injection tests designed to test the concurrent
+# transactions feature.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/malloc_common.tcl
+set testprefix concfault2
+
+ifcapable !concurrent {
+  finish_test
+  return
+}
+
+do_execsql_test 1.0 {
+  PRAGMA auto_vacuum = 0;
+  PRAGMA journal_mode = wal2;
+  CREATE TABLE t1(a PRIMARY KEY, b);
+  CREATE TABLE t2(a PRIMARY KEY, b);
+  INSERT INTO t1 VALUES(randomblob(1000), randomblob(100));
+  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+  DELETE FROM t1 WHERE rowid%2;
+} {wal2}
+
+do_test 1.1 {
+  list [expr [file size test.db-wal]>75000] [file size test.db-shm]
+} {1 32768}
+
+faultsim_save_and_close
+
+do_faultsim_test 1 -prep {
+  faultsim_restore_and_reopen
+  execsql {
+    BEGIN CONCURRENT;
+      INSERT INTO t2 VALUES(1, 2);
+  }
+  sqlite3 db2 test.db
+  execsql {
+    PRAGMA journal_size_limit = 10000;
+    INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
+  } db2
+  db2 close
+} -body {
+  execsql { COMMIT }
+} -test {
+  faultsim_test_result {0 {}} 
+  catchsql { ROLLBACK }
+  faultsim_integrity_check
+}
+finish_test
+
index 65f0022ab275332cf606e9555d7318573a089166..8185cb443be2d55a3b048501fb98241aa59de17d 100644 (file)
@@ -23,6 +23,10 @@ ifcapable !concurrent {
   return
 }
 
+do_test 0.1 {
+  llength [sqlite3_wal_info db main]
+} {2}
+
 do_multiclient_test tn {
 
   do_test 1.$tn.1 {
index c0a2c2ef90f6a57cb6e3c9aede1b8dd71fd41574..c4c1925be9aa308ab39ffdc3995181bd7ce3fdb8 100644 (file)
@@ -445,6 +445,7 @@ wal2savepoint.test wal2lock.test wal2recover2.test
   concurrent.test concurrent2.test concurrent3.test
   concurrent4.test concurrent5.test concurrent6.test
   concurrent7.test
+  concfault.test concfault2.test
 
   walvfs.test walfault2.test nockpt.test
   snapshot2.test snapshot3.test snapshot4.test
index a8614dccf2d3dd97161bec72d3b3df348db344dd..e6280a5163cf14a4f351b99930730daf57c6466b 100644 (file)
@@ -220,6 +220,49 @@ foreach {tn nCkpt1 nCkpt2 res} [list \
   db2 close
 }
 
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 1.8.1 {
+  PRAGMA autovacuum = 0;
+  PRAGMA page_size = 4096;
+  CREATE TABLE t1(x);
+  CREATE TABLE t2(x);
+  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
+    INSERT INTO t1 SELECT i FROM s;
+  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
+    INSERT INTO t2 SELECT i FROM s;
+
+  PRAGMA journal_mode = wal2;
+  PRAGMA journal_size_limit = 10000;
+
+  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
+    INSERT INTO t2 SELECT i FROM s;
+} {wal2 10000}
+
+do_test 1.8.2 {
+  list [file size test.db-wal] [file size test.db-wal2]
+} {24752 0}
+
+do_execsql_test 1.8.3 { PRAGMA user_version = 123 }
+do_test 1.8.4 {
+  list [file size test.db-wal] [file size test.db-wal2]
+} {24752 4152}
+
+do_test 1.8.5 {
+  hexio_write test.db-wal2 [expr 56+16] 0400
+  fix_wal_cksums test.db-wal2
+} {}
+
+do_test 1.8.6 {
+  forcecopy test.db test.db2
+  forcecopy test.db-wal test.db2-wal
+  forcecopy test.db-wal2 test.db2-wal2
+  sqlite3 db2 test.db2
+  catchsql { SELECT * FROM sqlite_master } db2
+} {1 {database disk image is malformed}}
+db2 close
+
 #-------------------------------------------------------------------------
 reset_db
 do_execsql_test 1.0 {
index c875af88c4162771e86dc2d676041f188f695679..f46ff9228023ffc4dfb1697a0e1610f5ea1c98f6 100644 (file)
@@ -55,6 +55,19 @@ do_execsql_test 1.3 {
   PRAGMA integrity_check;
 } {210 ok}
 
+do_execsql_test 1.4 {
+  BEGIN;
+    SAVEPOINT abc;
+      WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s where i < 100)
+      INSERT INTO t1 SELECT random(), random(), random() FROM s;
+    ROLLBACK TO abc;
+    WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s where i < 10)
+    INSERT INTO t1 SELECT random(), random(), random() FROM s;
+  COMMIT;
+  SELECT count(*) FROM t1;
+  PRAGMA integrity_check;
+} {220 ok}
+
 
 finish_test
 
index 9f461db7d6b7e23208c38656d041c84aced85da2..c4331f6702e3532ec99057dc99cb79a73e290afe 100644 (file)
@@ -67,8 +67,18 @@ foreach {tn mode} {1 wal 2 wal2} {
       execsql COMMIT
     } {}
   } else {
-    do_test 2.6 {
+
+    do_test 2.6.1 {
+      execsql BEGIN
+      set res [
+        list [catch { sqlite3_snapshot_open_blob db main $SNAPSHOT } msg] $msg
+      ]
+      execsql COMMIT
+      set res
+    } {1 SQLITE_ERROR}
+    do_test 2.6.2 {
       execsql BEGIN
+      execsql {SELECT * FROM sqlite_master}
       set res [
         list [catch { sqlite3_snapshot_open_blob db main $SNAPSHOT } msg] $msg
       ]