diff --git a/manifest b/manifest index 9839cb02f7..d83ae52fa9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sversion\s3.39.0\sinto\sthe\sbegin-concurrent-pnu-wal2\sbranch. -D 2022-06-25T17:08:25.541 +C Merge\sin\sfix\sfor\swal2\srecovery. +D 2022-06-27T21:43:33.502 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -662,7 +662,7 @@ F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf8 F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c F src/vtab.c 3d72c780d1ea08906a198e4f033921a658a54590e3ed72c544995d84f3f9464a F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 -F src/wal.c 8d7c4c78e403062d31a9c88638cfd1403849830517a9a4973a3db5d82ddd233d +F src/wal.c 393ffbef8381b50265a3f0de5cf3c68d0df6c6867df429c5719c2446e9254126 F src/wal.h 7a733af13b966ecb81872ce397e862116b3575ea53245b90b139a2873ee87825 F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 9a44063e60d8f42dd9dc8147b8e8dcfc315bbd13e25c395211292c36d828c869 @@ -1792,6 +1792,7 @@ F test/wal2lock.test 0ef98d72dc6bcf7711dedd684760488400d9a9a6eec0dc5d38220604377 F test/wal2openclose.test 2b26be723ea7f4263c8d5d70b37efd1c359561a0526e39466c45fe8e6478daee F test/wal2recover.test ba8f4bc9397c838734619f9e759bd98b00e355347b3cf80a2e677610d231d5d8 F test/wal2recover2.test 698bd0da28b84f470dc5dd50340401fdb50cf8d7894de27d55b61d22130bb1e1 +F test/wal2recover3.test 4a91689e165a38bc401736e6518188c2b0ff4fa1566d1810b8867536db128177 F test/wal2rewrite.test 6ca6f631ffcf871240beab5f02608913fd075c6d0d31310b026c8383c65c9f9c F test/wal2rollback.test 23adc4a099b23f6aaea8b04fdca1c35861d887dd80f8be7da2d5273eb777e428 F test/wal2savepoint.test 3793a0ae97011fca358f79775f5d7d9f85da75c8e67686e2e19713da0cb0d99c @@ -2012,8 +2013,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d3fa692179fb2e704e22f1fa0a64152bd0d6d6b531e359fa038eecf909373d97 ad3a7005e704711fb9de9e96883db3aed82c4f132a66cb74daf67c2527d79f73 -R 2fdb6eee279557a448a7092c530a5c13 -U drh -Z 8186556c8d69c75aa7307dee637a1388 +P 09cfef38daa791c2ba114fcf960436322c5acde312234b2c5105c3d95b6c1337 f6eafb65a43c650b065abe4a59e329c977cab1856c72dc9162046576d7bbfc8a +R f31799482b95bcae31b3d170db6dd533 +U dan +Z 2366a33723999b5fb13a7962cf9ee9da # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bbd95b2498..f15fd92178 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -09cfef38daa791c2ba114fcf960436322c5acde312234b2c5105c3d95b6c1337 \ No newline at end of file +41d4f14bc657f361976c51e1e0d38d2dd2440127fd230f80a1eb8f2a03bc9325 \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 8e038fad09..5fe3c6ff1d 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1830,7 +1830,8 @@ static int walIndexRecover(Wal *pWal){ if( isOpen(pWal->apWalFd[1]) ){ /* The case where *-wal2 may follow *-wal */ if( nCkpt2<=0x0F && nCkpt2==nCkpt1+1 ){ - if( sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[0]))==hdr.aFrameCksum[0] + if( pWal->hdr.mxFrame + && sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[0]))==hdr.aFrameCksum[0] && sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[1]))==hdr.aFrameCksum[1] ){ walidxSetFile(&pWal->hdr, 1); @@ -1843,7 +1844,8 @@ static int walIndexRecover(Wal *pWal){ /* When *-wal may follow *-wal2 */ if( (nCkpt2==0x0F && nCkpt1==0) || (nCkpt2<0x0F && nCkpt2==nCkpt1-1) ){ - if( sqlite3Get4byte((u8*)(&hdr.aSalt[0]))==pWal->hdr.aFrameCksum[0] + if( hdr.mxFrame + && sqlite3Get4byte((u8*)(&hdr.aSalt[0]))==pWal->hdr.aFrameCksum[0] && sqlite3Get4byte((u8*)(&hdr.aSalt[1]))==pWal->hdr.aFrameCksum[1] ){ SWAP(WalIndexHdr, pWal->hdr, hdr); diff --git a/test/wal2recover3.test b/test/wal2recover3.test new file mode 100644 index 0000000000..eab3011341 --- /dev/null +++ b/test/wal2recover3.test @@ -0,0 +1,52 @@ +# 2022 June 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 implements regression tests for SQLite library. The +# focus of this file is testing the operation of the library in +# "PRAGMA journal_mode=WAL2" mode. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl +source $testdir/wal_common.tcl + +set testprefix wal2recover3 +ifcapable !wal {finish_test ; return } + +do_execsql_test 1.0 { + CREATE TABLE t1(x); + CREATE TABLE t2(x); + PRAGMA journal_mode = wal2; + PRAGMA wal_autocheckpoint = 0; + PRAGMA journal_size_limit = 10000; +} {wal2 0 10000} + +do_execsql_test 1.1 { + 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; +} + +db_save_and_close +set fd [open sv_test.db-wal2 r+] +seek $fd 4000 +puts -nonewline $fd 0 +close $fd + +db_restore_and_reopen +do_execsql_test 1.2 { + SELECT sql FROM sqlite_schema; +} {{CREATE TABLE t1(x)} {CREATE TABLE t2(x)}} + +finish_test +