]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
OPFS: if an op which needs a lock is called when no lock has been obtained, automatic...
authorstephan <stephan@noemail.net>
Thu, 10 Nov 2022 11:35:10 +0000 (11:35 +0000)
committerstephan <stephan@noemail.net>
Thu, 10 Nov 2022 11:35:10 +0000 (11:35 +0000)
FossilOrigin-Name: 46304ba057707c3b072b6e7bb8c4af774f653aa5814099f0866cd87b2b73abeb

ext/wasm/api/sqlite3-opfs-async-proxy.js
ext/wasm/module-symbols.html
manifest
manifest.uuid

index 09c56ff1df4ecc8518123a837ff18a83e7582cb6..9c0bf4cbef7bf61643a1a56cf59f8505e24c9bce 100644 (file)
@@ -214,6 +214,24 @@ const closeSyncHandle = async (fh)=>{
   }
 };
 
+/**
+   A proxy for closeSyncHandle() which is guaranteed to not throw.
+
+   This function is part of a lock/unlock step in functions which
+   require a sync access handle but may be called without xLock()
+   having been called first. Such calls need to release that
+   handle to avoid locking the file for all of time. This is an
+   _attempt_ at reducing cross-tab contention but it may prove
+   to be more of a problem than a solution and may need to be
+   removed.
+*/
+const closeSyncHandleNoThrow = async (fh)=>{
+  try{await closeSyncHandle(fh)}
+  catch(e){
+    warn("closeSyncHandleNoThrow() ignoring:",e,fh);
+  }
+};
+
 /**
    Stores the given value at state.sabOPView[state.opIds.rc] and then
    Atomics.notify()'s it.
@@ -403,6 +421,7 @@ const vfsAsyncImpls = {
     mTimeStart('xFileSize');
     const fh = __openFiles[fid];
     let rc;
+    const hadLock = !!fh.syncHandle;
     wTimeStart('xFileSize');
     try{
       affirmLocked('xFileSize',fh);
@@ -413,6 +432,7 @@ const vfsAsyncImpls = {
       state.s11n.storeException(2,e);
       rc = state.sq3Codes.SQLITE_IOERR;
     }
+    if(!hadLock) closeSyncHandleNoThrow(fh);
     wTimeEnd();
     storeAndNotify('xFileSize', rc);
     mTimeEnd();
@@ -483,6 +503,7 @@ const vfsAsyncImpls = {
     mTimeStart('xRead');
     let rc = 0, nRead;
     const fh = __openFiles[fid];
+    const hadLock = !!fh.syncHandle;
     try{
       affirmLocked('xRead',fh);
       wTimeStart('xRead');
@@ -501,6 +522,7 @@ const vfsAsyncImpls = {
       state.s11n.storeException(1,e);
       rc = state.sq3Codes.SQLITE_IOERR_READ;
     }
+    if(!hadLock) closeSyncHandleNoThrow(fh);
     storeAndNotify('xRead',rc);
     mTimeEnd();
   },
@@ -525,6 +547,7 @@ const vfsAsyncImpls = {
     mTimeStart('xTruncate');
     let rc = 0;
     const fh = __openFiles[fid];
+    const hadLock = !!fh.syncHandle;
     wTimeStart('xTruncate');
     try{
       affirmLocked('xTruncate',fh);
@@ -535,6 +558,7 @@ const vfsAsyncImpls = {
       state.s11n.storeException(2,e);
       rc = state.sq3Codes.SQLITE_IOERR_TRUNCATE;
     }
+    if(!hadLock) closeSyncHandleNoThrow(fh);
     wTimeEnd();
     storeAndNotify('xTruncate',rc);
     mTimeEnd();
@@ -561,6 +585,7 @@ const vfsAsyncImpls = {
     mTimeStart('xWrite');
     let rc;
     const fh = __openFiles[fid];
+    const hadLock = !!fh.syncHandle;
     wTimeStart('xWrite');
     try{
       affirmLocked('xWrite',fh);
@@ -575,6 +600,7 @@ const vfsAsyncImpls = {
       state.s11n.storeException(1,e);
       rc = state.sq3Codes.SQLITE_IOERR_WRITE;
     }
+    if(!hadLock) closeSyncHandleNoThrow(fh);
     wTimeEnd();
     storeAndNotify('xWrite',rc);
     mTimeEnd();
index bebefffac8305714efef8d52e08388721aa43280..427d2dc8c3d9a670f1364e005e3f413de0edb982 100644 (file)
     <div id='list-compile-options' class='pseudolist wide2'></div>
 
   </div><!-- .initially-hidden -->
-  <script src="jswasm/sqlite3.js">/* This tag MUST be in side the
+  <script src="jswasm/sqlite3.js">/* This tag MUST be inside the
   fossil-doc block so that this part can work without modification in
   the wasm docs repo.  */</script>
   <script>(async function(){
index 36368b60d63c20df0b2ad4af22541a38f54cdcb2..201e266db74dfeb54898a12612ab92ed3bdf0bd7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Better\shandle\san\serror\sin\sthe\sfts5\sintegrity-check\scode.\sdbsqlfuzz\se87c62f9b67ea21aebdc36ab71cab7cc3eda8dc3.
-D 2022-11-09T11:17:57.759
+C OPFS:\sif\san\sop\swhich\sneeds\sa\slock\sis\scalled\swhen\sno\slock\shas\sbeen\sobtained,\sautomatically\slock\sit\sat\sthe\sstart\sof\sthe\sop\sand\sunlock\sit\sat\sthe\send\sof\sthat\sop.\sThis\sis\san\sattempt\sto\salleviate\sthe\scross-tab\scontention\sdescribed\sin\s[forum\spost\s58a377083cd24a|forum:58a377083cd24a]\sbut\sit\sincreases\sspeedtest1\srun\stime\sby\sapproximately\s4x.\sPerhaps\sauto-lock\scan\sbe\scombined\swith\sthe\solder\sidle-time-based\sauto-unlock\sto\sunlock\ssuch\slocks\s(but\snot\sthose\sfrom\sxLock())\sto\simprove\sthis?
+D 2022-11-10T11:35:10.700
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -506,7 +506,7 @@ F ext/wasm/api/sqlite3-api-opfs.js cdcbb57acc66f4569ac9e18f9d13d5a3657d8aae19572
 F ext/wasm/api/sqlite3-api-prologue.js fd526fa017fa2578673ca18158354515c719e719a5d93f2f6d0e43f39170430e
 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 ab7d2888ad9b3dd24bb782bd882fcada2a20cb88eb78c8f36e7bfe708857dbd1
+F ext/wasm/api/sqlite3-opfs-async-proxy.js 721ea9f716749a47b71be618fb33881afa828a46756f32836fc75c3e4bf11b4e
 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
 F ext/wasm/api/sqlite3-wasm.c 778409e00fb25a4d6989be17fc856c84460198fd3b05ba2ef8289e60c50157ca
 F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52aff253afbf3350431f5773faf0e4b
@@ -536,7 +536,7 @@ F ext/wasm/index-dist.html cb0da16cba0f21cda2c25724c5869102d48eb0af04446acd3cd0c
 F ext/wasm/index.html ce6a68a75532b47e3c0adb83381a06d15de8c0ac0331fb7bf31d33f8e7c77dc4
 F ext/wasm/jaccwabyt/jaccwabyt.js 95f573de1826474c9605dda620ee622fcb1673ae74f191eb324c0853aa4dcb66
 F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708f63ba0cf917cb5b68e
-F ext/wasm/module-symbols.html eca884ef4380612145ee550213be57478ee2b9cd9a9c2b27530cc23359c99682
+F ext/wasm/module-symbols.html b8eebafef8e536624bbe5f7a3da40c07a9062b843dfd3161a0bb72cbb6763dc5
 F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06
 F ext/wasm/scratchpad-wasmfs-main.js 4c140457f4d6da9d646a49addd91edb6e9ad1643c6c48e3258b5bce24725dc18
 F ext/wasm/speedtest1-wasmfs.html bc28eb29b69a73864b8d7aae428448f8b7e1de81d8bfb9bba99541322054dbd0
@@ -2055,8 +2055,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 2e70d1e5c9b2c9e068be3ccf8a6062edf7bdde2e46d60ba8ce54eda851af6008
-R 5b3228ef5a47231a8a5df1bba248e63f
-U dan
-Z 85fe5476882fbe08da2a9ca03d046c66
+P ae43e97087a3207a5ca3ffae75fbe7a33c01f4a38ce0d1d7eed8591ae3083617
+R 2fca99324f13ba1d5a012e300d10f561
+T *branch * opfs-lock-without-xlock
+T *sym-opfs-lock-without-xlock *
+T -sym-trunk * Cancelled\sby\sbranch.
+U stephan
+Z f1d3a3f55481503869b687bc0b9f2eae
 # Remove this line to create a well-formed Fossil manifest.
index 125b32b2c548d5e419d250742e5f7f26925e706c..04e72f1427f91e032502cdde8216ea02833c25ae 100644 (file)
@@ -1 +1 @@
-ae43e97087a3207a5ca3ffae75fbe7a33c01f4a38ce0d1d7eed8591ae3083617
\ No newline at end of file
+46304ba057707c3b072b6e7bb8c4af774f653aa5814099f0866cd87b2b73abeb
\ No newline at end of file