From: stephan Date: Fri, 2 Dec 2022 18:06:26 +0000 (+0000) Subject: OPFS VFS: translate createSyncAccessHandle() exceptions which appear to be locking... X-Git-Tag: version-3.41.0~325 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=95bc4d67bbc8abe0783605e5f98dc1689d213352;p=thirdparty%2Fsqlite.git OPFS VFS: translate createSyncAccessHandle() exceptions which appear to be locking violations to SQLITE_BUSY. This seems to improve concurrency considerably even with a reduced retry count of 5 (was 6). FossilOrigin-Name: 0d36021d107d3afca190ad61c3380536ad0cc2d493d345d48f9f9c1191741128 --- diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index d8234d5092..e77ff78092 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -263,21 +263,18 @@ const installAsyncProxy = function(self){ } }; GetSyncHandleError.convertRc = (e,rc)=>{ - if(0){ - /* This approach makes the very wild assumption that such a - failure _is_ a locking error. In practice that appears to be - the most common error, by far, but we cannot unambiguously - distinguish that from other errors. - - This approach is highly questionable. - - Note that even if we return SQLITE_IOERR_LOCK from here, - it bubbles up to the client as a plain I/O error. - */ - return (e instanceof GetSyncHandleError - && e.cause.name==='NoModificationAllowedError') - ? state.sq3Codes.SQLITE_IOERR_LOCK - : rc; + if(1){ + return ( + e instanceof GetSyncHandleError + && ((e.cause.name==='NoModificationAllowedError') + /* Inconsistent exception.name from Chrome/ium with the + same exception.message text: */ + || (e.cause.name==='DOMException' + && 0===e.cause.message.indexOf('Access Handles cannot'))) + ) ? ( + /*console.warn("SQLITE_BUSY",e),*/ + state.sq3Codes.SQLITE_BUSY + ) : rc; }else{ return rc; } @@ -298,7 +295,7 @@ const installAsyncProxy = function(self){ if(!fh.syncHandle){ const t = performance.now(); log("Acquiring sync handle for",fh.filenameAbs); - const maxTries = 6, msBase = state.asyncIdleWaitTime * 3; + const maxTries = 5, msBase = state.asyncIdleWaitTime * 2; let i = 1, ms = msBase; for(; true; ms = msBase * ++i){ try { diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 7b0a0b3228..85e65a4aee 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -277,7 +277,7 @@ const installOpfsVfs = function callee(options){ of this value is also used for determining how long to wait on lock contention to free up. */ - state.asyncIdleWaitTime = 100; + state.asyncIdleWaitTime = 150; /** Whether the async counterpart should log exceptions to the serialization channel. That produces a great deal of @@ -636,6 +636,12 @@ const installOpfsVfs = function callee(options){ a[i] = f._chars[ndx]; } return a.join(""); + /* + An alternative impl. with an unpredictable length + but much simpler: + + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(36) + */ }; /** @@ -1159,7 +1165,7 @@ const installOpfsVfs = function callee(options){ "pragma journal_mode=persist;", /* Set a default busy-timeout handler to help OPFS dbs deal with multi-tab/multi-worker contention. */ - "pragma busy_timeout=3000;", + "pragma busy_timeout=5000;", /* This vfs benefits hugely from cache on moderate/large speedtest1 --size 50 and --size 100 workloads. We currently diff --git a/ext/wasm/tests/opfs/concurrency/test.js b/ext/wasm/tests/opfs/concurrency/test.js index 044d343745..b994a8e79f 100644 --- a/ext/wasm/tests/opfs/concurrency/test.js +++ b/ext/wasm/tests/opfs/concurrency/test.js @@ -69,6 +69,7 @@ options.unlockAsap = ( urlArgsHtml.has('unlock-asap') ? +urlArgsHtml.get('unlock-asap') : 0 ) || 0; + options.noUnlink = !!urlArgsHtml.has('no-unlink'); const workers = []; workers.post = (type,...args)=>{ for(const w of workers) w.postMessage({type, payload:args}); @@ -124,7 +125,9 @@ for(let i = 0; i < options.workerCount; ++i){ stdout("Launching worker..."); workers.push(new Worker( - workers.uri+'&workerId='+(i+1)+(i ? '' : '&unlink-db') + workers.uri+'&workerId='+(i+1)+( + (i || options.noUnlink) ? '' : '&unlink-db' + ) )); } // Have to delay onmessage assignment until after the loop diff --git a/manifest b/manifest index a3d352d1d1..ccaa918011 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\ssqlite3_bind\sand\ssqlite3_result\sinterfaces\sfor\sUTF16\sstrings,\sround\nthe\snumber\sof\sbytes\sdown\sto\sthe\snext\seven\snumber,\sto\savoid\screating\sa\sUTF16\nstring\sthat\sis\san\sodd\snumber\sof\sbytes.\n[forum:/forumpost/411199488d065f83|Forum\spost\s411199488d065f83]. -D 2022-12-02T17:52:52.611 +C OPFS\sVFS:\stranslate\screateSyncAccessHandle()\sexceptions\swhich\sappear\sto\sbe\slocking\sviolations\sto\sSQLITE_BUSY.\sThis\sseems\sto\simprove\sconcurrency\sconsiderably\seven\swith\sa\sreduced\sretry\scount\sof\s5\s(was\s6). +D 2022-12-02T18:06:26.286 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -508,9 +508,9 @@ F ext/wasm/api/sqlite3-api-oo1.js c8b6c9ccb64cf93ca990ac689e98963735110aec21f98e F ext/wasm/api/sqlite3-api-prologue.js 42d6b316b542cf8e086f2f272460deb72dff184f1438a3377383cab99b08070b F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 -F ext/wasm/api/sqlite3-opfs-async-proxy.js 9963c78bf6e5ccb5ba28e8597851bd9d980e86803b6d341cc985e586aef10c82 +F ext/wasm/api/sqlite3-opfs-async-proxy.js 132e27f2172411020bb3a35ce5897c6437a960b4d744e7b8bdf3c6e3e32369dd F ext/wasm/api/sqlite3-vfs-helper.js 4ad4faf02e1524bf0296be8452c00b5708dce6faf649468d0377e26a0b299263 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 654f37fd6312d3bb0d067b21ad42f9dcfd629fd34ace892e67e06143a65dc6d0 +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 146fbdac3c2ffa006ad4e95430396496caca0584c70623ae64e6c452a82c0e7f F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasm.c 733bc939f93caef0df0b3ebfea14cbd528da580fdef1a35b1f69c2b3e044c7b7 F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52aff253afbf3350431f5773faf0e4b @@ -557,7 +557,7 @@ F ext/wasm/tester1-worker.html ead6bdcc6cca221deb0dc9855a56f376351dbf2294fd7978c F ext/wasm/tester1.c-pp.html 74aa9b31c75f12490653f814b53c3dd39f40cd3f70d6a53a716f4e8587107399 F ext/wasm/tester1.c-pp.js e73a91eba4b59aaadd98f383c00a5101dbbbc52d937fff3162fc4761986f4a88 F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70 -F ext/wasm/tests/opfs/concurrency/test.js bfc3d7e27b207f0827f12568986b8d516a744529550b449314f5c21c9e9faf4a +F ext/wasm/tests/opfs/concurrency/test.js 9315339ed27849e65890eda924a516562936525a4f3f162fa71aeb489b9dc707 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 F ext/wasm/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd72273503ae7d5 F ext/wasm/wasmfs.make 7ab655788bf0b52dce4538acbd5b11cdbe77edd36a14af5dec6dfe1ec4ab25fc @@ -2065,8 +2065,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 5652154a8c93cf3b1ff6c2e55e94abbe995b0bb625f733461df20e006c2f13f8 -R abeafb6b0b2c2a0d499e07055ea2ac86 -U drh -Z 85652852cafea1303e4df55e9d9dc80a +P b57e3c3db00a6bc6db20c82530479f9eba7e37b731f0da6fe81682e84c7ac916 +R 8232ca838233bb862b578dd17ef993c2 +U stephan +Z a512e857bd2ba2b089c64ccfca3b82d0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3229673c36..3568e89033 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b57e3c3db00a6bc6db20c82530479f9eba7e37b731f0da6fe81682e84c7ac916 \ No newline at end of file +0d36021d107d3afca190ad61c3380536ad0cc2d493d345d48f9f9c1191741128 \ No newline at end of file