]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not attempt to switch wal files when writing if the current transaction read from...
authordan <Dan Kennedy>
Sat, 14 Dec 2024 16:41:39 +0000 (16:41 +0000)
committerdan <Dan Kennedy>
Sat, 14 Dec 2024 16:41:39 +0000 (16:41 +0000)
FossilOrigin-Name: 693cc8e8db6c00249211bdfc21be2bff169ca6b0c4560522dd404615e8ba3b76

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

index ed4b67285ca1f02fcecb70748503bef7de612bd8..658424d0a6d8f8896253b801985f2e31129a7d74 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sproblem\swith\sthe\soutput\sof\s"PRAGMA\swal_checkpoint"\sintroduced\slong\sago\sby\s[63483e22c775183e].
-D 2024-12-13T20:18:29.915
+C Do\snot\sattempt\sto\sswitch\swal\sfiles\swhen\swriting\sif\sthe\scurrent\stransaction\sread\sfrom\sboth\swal\sfiles.\sThis\sfix\sis\salready\son\sbranch\s'bedrock'.
+D 2024-12-14T16:41:39.812
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -860,7 +860,7 @@ F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf8
 F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3
 F src/vtab.c 316cd48e9320660db3047cd306cd056e4361180cebb4d0f10a39244e10c11422
 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
-F src/wal.c c80108214438d8112963ac4a28e2ddfb92fc993b33bf25fdc77440e30ff6c268
+F src/wal.c 42f0823a65218643d213633b52e2a80ca70b193f6f7802c6edb040448860e9e8
 F src/wal.h 97b8a9903387401377b59507e86b93a148ef1ad4e5ce0f23659a12dcdce56af2
 F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
 F src/where.c b34adb09fdb2a4f57a0bafd4194b501047ef383976fef9f0ac3f395f4881694d
@@ -2003,7 +2003,7 @@ F test/wal2recover3.test 4a91689e165a38bc401736e6518188c2b0ff4fa1566d1810b886753
 F test/wal2rewrite.test 6ca6f631ffcf871240beab5f02608913fd075c6d0d31310b026c8383c65c9f9c
 F test/wal2rollback.test 23adc4a099b23f6aaea8b04fdca1c35861d887dd80f8be7da2d5273eb777e428
 F test/wal2savepoint.test c380512ec1f97012cfc753e718bf3df38f51e7c319110e1cae25094a33b371c4
-F test/wal2simple.test 2aaf8d81e889035e6021369bec45758f89ac3a13ae7bcefc111ea1aabe3f9cfd
+F test/wal2simple.test 471f6d404c19b94968ef4c74566914e544d31c5fa0afc8f1b31af117d7014a8b
 F test/wal2snapshot.test 7a5f4629a3c43a43c3440b8b2ea9f07de91a46b0b9eea5f08f62b5bf5b6468df
 F test/wal3.test 5de023bb862fd1eb9d2ad26fa8d9c43abb5370582e5b08b2ae0d6f93661bc310
 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
@@ -2216,8 +2216,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P d3ce95f7e0335b8522a1805ab602b64856ced3007c507ba42039c6183ef9ac3d
-R ee2cfb61cc5fc78106af5b84f79ac024
+P c5f7bba8683a9aa503750abb7fd937566983dc1ca08361eca8b9b185294b909a
+R 9126283d88fd2ef1f08bb80d8fab9c01
 U dan
-Z 2ab193829137f4720a5ca440c0e08d93
+Z 875bffc535ab8b30264831dbcb04504f
 # Remove this line to create a well-formed Fossil manifest.
index 4d9fe6678e8aadf573a0af1970f9727f2b48a96c..6c7c0600cb2eda9dd70d752bb75781893413844a 100644 (file)
@@ -1 +1 @@
-c5f7bba8683a9aa503750abb7fd937566983dc1ca08361eca8b9b185294b909a
+693cc8e8db6c00249211bdfc21be2bff169ca6b0c4560522dd404615e8ba3b76
index 5f43689f8fc4ad7b800fe79168e3d47010999895..987eed318dcf5933c9311bdf0f1f6b1041aadfc7 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -4593,32 +4593,46 @@ static int walRestartLog(Wal *pWal){
     int iApp = walidxGetFile(&pWal->hdr);
     u32 nWalSize = WAL_DEFAULT_WALSIZE;
     if( pWal->mxWalSize>0 ){
+      /* mxWalSize is in bytes. Convert this to a number of frames. */
       nWalSize = (pWal->mxWalSize-WAL_HDRSIZE+pWal->szPage+WAL_FRAME_HDRSIZE-1) 
         / (pWal->szPage+WAL_FRAME_HDRSIZE);
       nWalSize = MAX(nWalSize, 1);
     }
 
-    if( walidxGetMxFrame(&pWal->hdr, iApp)>=nWalSize ){
-      volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
-      u32 mxFrame = walidxGetMxFrame(&pWal->hdr, !iApp);
-      if( mxFrame==0 || pInfo->nBackfill ){
-        rc = wal2RestartOk(pWal, iApp);
-        if( rc==SQLITE_OK ){
-          int iNew = !iApp;
-          pWal->nCkpt++;
-          walidxSetFile(&pWal->hdr, iNew);
-          walidxSetMxFrame(&pWal->hdr, iNew, 0);
-          sqlite3Put4byte((u8*)&pWal->hdr.aSalt[0], pWal->hdr.aFrameCksum[0]);
-          sqlite3Put4byte((u8*)&pWal->hdr.aSalt[1], pWal->hdr.aFrameCksum[1]);
-          walIndexWriteHdr(pWal);
-          pInfo->nBackfill = 0;
-          wal2RestartFinished(pWal, iApp);
-          walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
-          pWal->readLock = iNew ? WAL_LOCK_PART2_FULL1 : WAL_LOCK_PART1_FULL2;
-          rc = walLockShared(pWal, WAL_READ_LOCK(pWal->readLock));
-        }else if( rc==SQLITE_BUSY ){
-          rc = SQLITE_OK;
-        }
+    assert( iApp==0 || pWal->readLock==WAL_LOCK_PART2 
+                    || pWal->readLock==WAL_LOCK_PART2_FULL1 );
+    assert( iApp==1 || pWal->readLock==WAL_LOCK_PART1 
+                    || pWal->readLock==WAL_LOCK_PART1_FULL2 );
+
+    /* Switch to wal file !iApp if 
+    **
+    **   (a) Wal file iApp (the current wal file) contains >= nWalSize frames.
+    **   (b) This client is not reading from wal file !iApp.
+    **   (c) No other client is reading from wal file !iApp.
+    **
+    ** Condition (b) guarantees that wal file !iApp is either empty or
+    ** completely checkpointed. 
+    */
+    if( (pWal->readLock==WAL_LOCK_PART1 || pWal->readLock==WAL_LOCK_PART2)
+     && walidxGetMxFrame(&pWal->hdr, iApp)>=nWalSize 
+    ){
+      rc = wal2RestartOk(pWal, iApp);
+      if( rc==SQLITE_OK ){
+        volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
+        int iNew = !iApp;
+        pWal->nCkpt++;
+        walidxSetFile(&pWal->hdr, iNew);
+        walidxSetMxFrame(&pWal->hdr, iNew, 0);
+        sqlite3Put4byte((u8*)&pWal->hdr.aSalt[0], pWal->hdr.aFrameCksum[0]);
+        sqlite3Put4byte((u8*)&pWal->hdr.aSalt[1], pWal->hdr.aFrameCksum[1]);
+        walIndexWriteHdr(pWal);
+        pInfo->nBackfill = 0;
+        wal2RestartFinished(pWal, iApp);
+        walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
+        pWal->readLock = iNew ? WAL_LOCK_PART2_FULL1 : WAL_LOCK_PART1_FULL2;
+        rc = walLockShared(pWal, WAL_READ_LOCK(pWal->readLock));
+      }else if( rc==SQLITE_BUSY ){
+        rc = SQLITE_OK;
       }
     }
   }else if( pWal->readLock==0 ){
index 3ccd4b91a448c52c6762f3a2f72f0801e8472de3..3d50d3e950a1d77dcddbd70f28734679bcd6ad2c 100644 (file)
@@ -470,6 +470,32 @@ do_test 7.5.4 {
   list [file size test.db-wal] [file size test.db-wal2] [file size test.db]
 } {22040 12608 87040}
 
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 8.0 {
+  PRAGMA journal_size_limit = 10000;
+  PRAGMA journal_mode = wal2;
+  CREATE TABLE t1(x);
+  INSERT INTO t1 VALUES( hex( randomblob(5000) ) );
+  INSERT INTO t1 VALUES( hex( randomblob(5000) ) );
+  INSERT INTO t1 VALUES( hex( randomblob(5000) ) );
+  INSERT INTO t1 VALUES( hex( randomblob(5000) ) );
+  BEGIN;
+    INSERT INTO t1 VALUES( hex( randomblob(5000) ) );
+} {10000 wal2}
+
+sqlite3 db2 test.db
+do_execsql_test -db db2 8.1 {
+  PRAGMA wal_checkpoint;
+} {0 50 13}
+
+do_execsql_test 8.2 {
+  COMMIT;
+}
+
+db2 close
+
+
 #-------------------------------------------------------------------------
 reset_db
 do_execsql_test 9.0 {
@@ -486,6 +512,5 @@ do_execsql_test 9.1 {
   PRAGMA wal_checkpoint;
 } {0 50 13}
 
-
 finish_test