From aabb710293ed7f3b38a9f342f2c58215e46f8769 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 21 Aug 2023 18:25:41 +0000 Subject: [PATCH] Fix problems related to structured-exception-handling on this branch. FossilOrigin-Name: d3d77e35ea39df9e22032a7e1af5b7f38d53a4d43bc46afe36e342cdcfd17528 --- ext/fts5/test/fts5secure3.test | 7 +++ manifest | 18 +++--- manifest.uuid | 2 +- src/wal.c | 105 +++++++++++++++++++-------------- test/concurrent.test | 1 + test/wal2recover2.test | 2 +- 6 files changed, 80 insertions(+), 55 deletions(-) diff --git a/ext/fts5/test/fts5secure3.test b/ext/fts5/test/fts5secure3.test index bc56e08200..4dc5e47744 100644 --- a/ext/fts5/test/fts5secure3.test +++ b/ext/fts5/test/fts5secure3.test @@ -108,6 +108,13 @@ proc newdoc {} { } db func newdoc newdoc +proc random {} { + set res [expr { int(rand() * 0x7FFFFFFFFFFFFFFF) }] + if { int(rand() * 2) } { set res [expr $res*-1] } + return $res +} +db func random random + do_execsql_test 3.0 { CREATE VIRTUAL TABLE fff USING fts5(y); INSERT INTO fff(fff, rank) VALUES('pgsz', 64); diff --git a/manifest b/manifest index ea8acb35c0..ef64aba6d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\slatest\swal2\schanges,\sincluding\ssupport\sfor\shandling\sof\sstructured-exceptions\sin\sMSVC\sbuilds,\swith\sthis\sbranch. -D 2023-08-11T19:36:24.769 +C Fix\sproblems\srelated\sto\sstructured-exception-handling\son\sthis\sbranch. +D 2023-08-21T18:25:41.874 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -201,7 +201,7 @@ F ext/fts5/test/fts5rowid.test b8790ec170a8dc1942a15aef3db926a5f3061b1ff17101300 F ext/fts5/test/fts5savepoint.test fc02929f238d02a22df4172625704e029f7c1e0e92e332d654375690f8e6e43f F ext/fts5/test/fts5secure.test 214a561519d1b1817f146efd1057e2a97cc896e75c2accc77157d874154bda64 F ext/fts5/test/fts5secure2.test 2e961d7eef939f294c56b5d895cac7f1c3a60b934ee2cfd5e5e620bdf1ba6bbc -F ext/fts5/test/fts5secure3.test c7e1080a6912f2a3ac68f2e05b88b72a99de38543509b2bbf427cac5c9c1c610 +F ext/fts5/test/fts5secure3.test 12bc9ffa5dbd5a0951c6fe73bbf53b1c6507217589d7c8f5d4637a4fbb534401 F ext/fts5/test/fts5secure4.test 0d10a80590c07891478700af7793b232962042677432b9846cf7fc8337b67c97 F ext/fts5/test/fts5secure5.test c07a68ced5951567ac116c22f2d2aafae497e47fe9fcb6a335c22f9c7a4f2c3a F ext/fts5/test/fts5secure6.test 7a959d834be6725c641b3c3b38ef86570ea671216ad803e054e4fdff33a72ce2 @@ -733,7 +733,7 @@ F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf8 F src/vdbevtab.c 57fa8f56478e5b5cb558cb425e7878515e0a105c54f96f1d1bbf4b9433529254 F src/vtab.c 1ecf8c3745d29275688d583e12822fa984d421e0286b5ef50c137bc3bf6d7a64 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 -F src/wal.c 8408687b696e4bb36d4312d2b71b6467c064681315c6c9f05cd823c3839cf676 +F src/wal.c 56eedfe60c278d0ee53f8a91b513ab40020773a1e83e29ec7ccc6a000ad5bd28 F src/wal.h dcb0533caecf286be1c87b683e1282f3ca29fa5c00eb798e9226ce377a687cf4 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2 F src/where.c b8917792f1e0dbfa28fb29e6cd3d560060d69667be0ba4c491cbc772363264f5 @@ -897,7 +897,7 @@ F test/columncount.test 6fe99c2f35738b0129357a1cf3fa483f76140f4cd8a89014c88c33c8 F test/commitstatus.test d5a871506ce5944a29afb7e65ce47ca7f76cadc1d09775022830258fdd6168a1 F test/concfault.test 500f17c3fcfe7705114422bcc6ddd3c740001a43 F test/concfault2.test 34b3fd258836aa305475d00e804c7450ade92f0de0bf9fa620e701446669bb12 -F test/concurrent.test a0248ec6e3e79a5948453649cf86b5b359175cba55ea636b15426d6f0fa6c3da +F test/concurrent.test fb624ddac9b008f347685911f90b6b5a022fd0a3f884c0ffef8056bc440e5d76 F test/concurrent2.test 847cd11edc82229a95e1eaf88b55c974430b0f669cefd67a453d274e3480981c F test/concurrent3.test 82923fc2ea7321144b4448f98ea38aa316ddceef9020a392c5f6dea536506434 F test/concurrent4.test e0b12cd467137e50259df3b4f837507e82aaa07c35941c88664dc8ed1d089c44 @@ -1857,7 +1857,7 @@ F test/wal2fault.test 2e8e60cacd5bcd451618aeffd05f676894d17202d3e2986e288d36e2c5 F test/wal2lock.test 0ef98d72dc6bcf7711dedd684760488400d9a9a6eec0dc5d3822060437793552 F test/wal2openclose.test 2b26be723ea7f4263c8d5d70b37efd1c359561a0526e39466c45fe8e6478daee F test/wal2recover.test 28b3fa0acb4e8725211a02803cd51116cd048841a876224f244af78039ba34fa -F test/wal2recover2.test e506e1d22125b1b115ecc4de44b04f3d4830719c3f8577fcb52cb3cfe12307b9 +F test/wal2recover2.test 2224dce37731db3a110161d516a1fc56aa38f6ac797aa1b50b983a0960b5d609 F test/wal2recover3.test 4a91689e165a38bc401736e6518188c2b0ff4fa1566d1810b8867536db128177 F test/wal2rewrite.test 6ca6f631ffcf871240beab5f02608913fd075c6d0d31310b026c8383c65c9f9c F test/wal2rollback.test 23adc4a099b23f6aaea8b04fdca1c35861d887dd80f8be7da2d5273eb777e428 @@ -2088,8 +2088,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 ca422d00d7843ee72a1ae20753ba512896d6f6d2b1218523323946bf66f3c758 00bfae9ffafd71dfd0bbdbdc174e4ed7d7a850b385416f83be36a4f4a55d1873 -R f50941a07ea5ece4d4d7d1785830ae41 +P 331f2f3e5db9b6139be984f1b959cd0d51563adaa68452aa2f42741c69bc6319 +R 8cf5124efb077972dc4592e59c017049 U dan -Z 8a22f21379a7b432c426975e82b8bfd5 +Z 86179e20e1202dcde51614a70e1512c5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6ca4459d36..acba96d09a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -331f2f3e5db9b6139be984f1b959cd0d51563adaa68452aa2f42741c69bc6319 \ No newline at end of file +d3d77e35ea39df9e22032a7e1af5b7f38d53a4d43bc46afe36e342cdcfd17528 \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 8bafab4c69..62cd16d350 100644 --- a/src/wal.c +++ b/src/wal.c @@ -4427,7 +4427,6 @@ static int walUpgradeReadlock(Wal *pWal){ #ifndef SQLITE_OMIT_CONCURRENT - /* ** A concurrent transaction has conflicted with external frame iExternal. ** Transform this value to the one required by SQLITE_COMMIT_CONFLICT_FRAME - @@ -4443,37 +4442,12 @@ static u32 walConflictFrame(Wal *pWal, u32 iExternal){ return iRet; } - - -/* -** This function is only ever called when committing a "BEGIN CONCURRENT" -** transaction. It may be assumed that no frames have been written to -** the wal file. The second parameter is a pointer to the in-memory -** representation of page 1 of the database (which may or may not be -** dirty). The third is a bitvec with a bit set for each page in the -** database file that was read by the current concurrent transaction. -** -** This function performs three tasks: -** -** 1) It obtains the WRITER lock on the wal file, -** -** 2) It checks that there are no conflicts between the current -** transaction and any transactions committed to the wal file since -** it was opened, and -** -** 3) It ejects any non-dirty pages from the page-cache that have been -** written by another client since the CONCURRENT transaction was started -** (so as to avoid ending up with an inconsistent cache after the -** current transaction is committed). -** -** If no error occurs and the caller may proceed with committing the -** transaction, SQLITE_OK is returned. SQLITE_BUSY is returned if the WRITER -** lock cannot be obtained. Or, if the WRITER lock can be obtained but there -** are conflicts with a committed transaction, SQLITE_BUSY_SNAPSHOT. Finally, -** if an error (i.e. an OOM condition or IO error), an SQLite error code -** is returned. +/* +** This function does the work of sqlite3WalLockForCommit(). The difference +** between this function and sqlite3WalLockForCommit() is that the latter +** encloses everything in a SEH_TRY {} block. */ -int sqlite3WalLockForCommit( +static int walLockForCommit( Wal *pWal, PgHdr *pPg1, Bitvec *pAllRead, @@ -4626,6 +4600,47 @@ int sqlite3WalLockForCommit( return rc; } +/* +** This function is only ever called when committing a "BEGIN CONCURRENT" +** transaction. It may be assumed that no frames have been written to +** the wal file. The second parameter is a pointer to the in-memory +** representation of page 1 of the database (which may or may not be +** dirty). The third is a bitvec with a bit set for each page in the +** database file that was read by the current concurrent transaction. +** +** This function performs three tasks: +** +** 1) It obtains the WRITER lock on the wal file, +** +** 2) It checks that there are no conflicts between the current +** transaction and any transactions committed to the wal file since +** it was opened, and +** +** 3) It ejects any non-dirty pages from the page-cache that have been +** written by another client since the CONCURRENT transaction was started +** (so as to avoid ending up with an inconsistent cache after the +** current transaction is committed). +** +** If no error occurs and the caller may proceed with committing the +** transaction, SQLITE_OK is returned. SQLITE_BUSY is returned if the WRITER +** lock cannot be obtained. Or, if the WRITER lock can be obtained but there +** are conflicts with a committed transaction, SQLITE_BUSY_SNAPSHOT. Finally, +** if an error (i.e. an OOM condition or IO error), an SQLite error code +** is returned. +*/ +int sqlite3WalLockForCommit( + Wal *pWal, + PgHdr *pPg1, + Bitvec *pAllRead, + Pgno *piConflict +){ + int rc = SQLITE_OK; + SEH_TRY { + rc = walLockForCommit(pWal, pPg1, pAllRead, piConflict); + } SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; ) + return rc; +} + /* !defined(SQLITE_OMIT_CONCURRENT) ** ** This function is called as part of committing an CONCURRENT transaction. @@ -4643,19 +4658,21 @@ int sqlite3WalUpgradeSnapshot(Wal *pWal){ int rc = SQLITE_OK; assert( pWal->writeLock ); - assert( pWal->szPage==pWal->hdr.szPage ); - memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr)); - assert( pWal->szPage==pWal->hdr.szPage || pWal->szPage==0 ); - pWal->szPage = pWal->hdr.szPage; - - /* If this client has its read-lock on slot aReadmark[0] and the entire - ** wal has not been checkpointed, switch it to a different slot. Otherwise - ** any reads performed between now and committing the transaction will - ** read from the old snapshot - not the one just upgraded to. */ - if( pWal->readLock==0 && pWal->hdr.mxFrame!=walCkptInfo(pWal)->nBackfill ){ - assert( isWalMode2(pWal)==0 ); - rc = walUpgradeReadlock(pWal); - } + SEH_TRY { + assert( pWal->szPage==pWal->hdr.szPage ); + memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr)); + assert( pWal->szPage==pWal->hdr.szPage || pWal->szPage==0 ); + pWal->szPage = pWal->hdr.szPage; + + /* If this client has its read-lock on slot aReadmark[0] and the entire + ** wal has not been checkpointed, switch it to a different slot. Otherwise + ** any reads performed between now and committing the transaction will + ** read from the old snapshot - not the one just upgraded to. */ + if( pWal->readLock==0 && pWal->hdr.mxFrame!=walCkptInfo(pWal)->nBackfill ){ + assert( isWalMode2(pWal)==0 ); + rc = walUpgradeReadlock(pWal); + } + } SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; ) return rc; } #endif /* SQLITE_OMIT_CONCURRENT */ diff --git a/test/concurrent.test b/test/concurrent.test index ad1e15d71c..ba01ee7753 100644 --- a/test/concurrent.test +++ b/test/concurrent.test @@ -163,6 +163,7 @@ do_execsql_test 1.7.1.x { {CREATE INDEX yyi1 ON yy(a)} {CREATE TABLE zz(a, b)} } +db2 close #------------------------------------------------------------------------- # If an auto-vacuum database is written within an CONCURRENT transaction, it diff --git a/test/wal2recover2.test b/test/wal2recover2.test index 140e690e6c..cd99e71dd8 100644 --- a/test/wal2recover2.test +++ b/test/wal2recover2.test @@ -262,7 +262,7 @@ do_test 1.8.6 { forcecopy test.db-wal2 test.db2-wal2 sqlite3 db2 test.db2 catchsql { SELECT * FROM sqlite_master } db2 -} {1 {malformed database schema (?)}} +} {1 {database disk image is malformed}} db2 close #------------------------------------------------------------------------- -- 2.47.2