]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Move the OPFS VFS bits back into api/sqlite3-api-opfs.js. Refactor the OPFS VFS init...
authorstephan <stephan@noemail.net>
Sun, 18 Sep 2022 03:05:55 +0000 (03:05 +0000)
committerstephan <stephan@noemail.net>
Sun, 18 Sep 2022 03:05:55 +0000 (03:05 +0000)
FossilOrigin-Name: b2abf60dbfa6648f671a3932cb65feb28d05a0d5b7f792351d14f9c13d9798c5

ext/wasm/index.html
ext/wasm/sqlite3-opfs-async-proxy.js
ext/wasm/test-opfs-vfs.html [moved from ext/wasm/x-sync-async.html with 91% similarity]
ext/wasm/test-opfs-vfs.js [moved from ext/wasm/x-sync-async.js with 59% similarity]
manifest
manifest.uuid

index 562bb9b5efe4cff9b8c0c400c523c4486962ec8c..fc0c33e4325a4ca9837e04bc9801f5f386dfed71 100644 (file)
           worker due to an Emscripten limitation.</li>
         <li><a href='scratchpad-opfs-worker.html'>scratchpad-opfs-worker</a>:
           experimenting with OPFS from a Worker thread (without WASMFS).</li>
-        <li><a href='x-sync-async.html?opfs-sanity-check&opfs-verbose'>x-sync-async</a> is an
+        <li><a href='test-opfs-vfs.html'>test-opfs-vfs</a>
+          (<a href='test-opfs-vfs.html?opfs-sanity-check&opfs-verbose'>same
+          with verbose output and sanity-checking tests</a>) is an
           experiment in implementing a syncronous sqlite3 VFS proxy
-          for a fully synchronous backend interface (namely OPFS), using SharedArrayBuffer
-          and the Atomics APIs to regulate communication between the synchronous
-          interface and the async impl.
+          for a fully asynchronous backend interface (namely OPFS),
+          using SharedArrayBuffer and the Atomics APIs to regulate
+          communication between the synchronous interface and the
+          async impl.
         </li>
         <!--li><a href='x.html'></a></li-->
       </ul>
index 58498e006b7873e7b01f5ba32dd191a03c2ed000..00b4025569626d4573b9b3da774374558ab137dd 100644 (file)
@@ -260,7 +260,7 @@ const vfsAsyncImpls = {
     const fh = __openFiles[fid];
     try{
       const aRead = new Uint8Array(fh.sab, 0, n);
-      const nRead = fh.accessHandle.read(aRead, {at: offset});
+      const nRead = fh.accessHandle.read(aRead, {at: Number(offset)});
       if(nRead < n){/* Zero-fill remaining bytes */
         new Uint8Array(fh.sab).fill(0, nRead, n);
         rc = state.sq3Codes.SQLITE_IOERR_SHORT_READ;
@@ -302,7 +302,8 @@ const vfsAsyncImpls = {
     const fh = __openFiles[fid];
     try{
       affirmNotRO('xWrite', fh);
-      const nOut = fh.accessHandle.write(new Uint8Array(fh.sab, 0, n), {at: offset});
+      const nOut = fh.accessHandle.write(new Uint8Array(fh.sab, 0, n),
+                                         {at: Number(offset)});
       rc = (nOut===n) ? 0 : state.sq3Codes.SQLITE_IOERR_WRITE;
     }catch(e){
       error("xWrite():",e,fh);
similarity index 91%
rename from ext/wasm/x-sync-async.html
rename to ext/wasm/test-opfs-vfs.html
index b83d93378c8afdef182abc2b707190f4db20fbd0..6e470ecc889c907256e0a16aab0929f0346d9518 100644 (file)
@@ -17,6 +17,6 @@
     </div>
     <div id='test-output'>
     </div>
-    <script>new Worker("x-sync-async.js"+self.location.search);</script>
+    <script>new Worker("test-opfs-vfs.js"+self.location.search);</script>
   </body>
 </html>
similarity index 59%
rename from ext/wasm/x-sync-async.js
rename to ext/wasm/test-opfs-vfs.js
index b25f5a2681ac1c04f05cc0e28a27b5fa8384f3ee..fd71c9cdcfb7ac7b320dcbec95ffe82051dc95ae 100644 (file)
 const tryOpfsVfs = function(sqlite3){
   const toss = function(...args){throw new Error(args.join(' '))};
   const logPrefix = "OPFS tester:";
-  const log = (...args)=>{
-    console.log(logPrefix,...args);
-  };
-  const warn =  (...args)=>{
-    console.warn(logPrefix,...args);
-  };
-  const error =  (...args)=>{
-    console.error(logPrefix,...args);
-  };
+  const log = (...args)=>console.log(logPrefix,...args);
+  const warn =  (...args)=>console.warn(logPrefix,...args);
+  const error =  (...args)=>console.error(logPrefix,...args);
   log("tryOpfsVfs()");
   const capi = sqlite3.capi;
   const pVfs = capi.sqlite3_vfs_find("opfs") || toss("Unexpectedly missing 'opfs' VFS.");
-  const oVfs = capi.sqlite3_vfs.instanceForPointer(pVfs);
+  const oVfs = capi.sqlite3_vfs.instanceForPointer(pVfs) || toss("Unexpected instanceForPointer() result.");;
   log("OPFS VFS:",pVfs, oVfs);
+
+  const dbFile = "my-persistent.db";
+  const db = new sqlite3.oo1.DB(dbFile, "c", "opfs");
+  log("db file:",db.filename);
+  try{
+    let n = db.selectValue("select count(*) from sqlite_schema");
+    if(n){
+      log("Persistent data found. sqlite_schema entry count =",n);
+    }
+    db.transaction((db)=>{
+      db.exec({
+        sql:[
+          "create table if not exists t(a);",
+          "insert into t(a) values(?),(?),(?);",
+        ],
+        bind: [performance.now() | 0,
+               (performance.now() |0) / 2,
+               (performance.now() |0) / 4]
+      });
+    });
+    log("count(*) from t =",db.selectValue("select count(*) from t"));
+  }finally{
+    db.close();
+  }
+
   log("Done!");
 }/*tryOpfsVfs()*/;
 
@@ -48,6 +67,5 @@ self.sqlite3InitModule().then((EmscriptenModule)=>{
     .then((sqlite3)=>tryOpfsVfs(sqlite3))
     .catch((e)=>{
       console.error("Error initializing OPFS VFS:",e);
-      throw e;
     });
 });
index 98c1a9df8602ee4e7d7133caf1290e63bab3b945..ab3e8572f14e83a7865b6751abc7b580947ffced 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Move\sthe\sOPFS\sVFS\sbits\sback\sinto\sapi/sqlite3-api-opfs.js.\sRefactor\sthe\sOPFS\sVFS\sinit\sprocess\sto\suse\sa\sPromise-returning\sfunction\swhich\sthe\sclient\smust\scall,\sas\sthat\seliminates\sany\suncertainty\sabout\swhen\sthe\sVFS\s(necessarily\sactivated\sasynchronously)\sactually\sbecomes\savailable\sto\sthe\sclient.
-D 2022-09-18T02:35:30.998
+C Move\sthe\sOPFS\sVFS\sbits\sback\sinto\sapi/sqlite3-api-opfs.js.\sRefactor\sthe\sOPFS\sVFS\sinit\sprocess\sto\suse\sa\sPromise-returning\sfunction\swhich\sthe\sclient\smust\scall,\sas\sthat\seliminates\sany\suncertainty\sabout\swhen\sthe\sVFS\s(necessarily\sactivated\sasynchronously)\sactually\sbecomes\savailable\sto\sthe\sclient.\sRename\sx-sync-async.*\sto\stest-opfs-vfs.*\sMilestone:\sfirst\ssuccessful\stest\sof\sOPFS\swithout\sWASMFS.
+D 2022-09-18T03:05:55.278
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -502,7 +502,7 @@ F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d695
 F ext/wasm/fiddle/fiddle-worker.js bccf46045be8824752876f3eec01c223be0616ccac184bffd0024cfe7a3262b8
 F ext/wasm/fiddle/fiddle.html 550c5aafce40bd218de9bf26192749f69f9b10bc379423ecd2e162bcef885c08
 F ext/wasm/fiddle/fiddle.js 4ffcfc9a235beebaddec689a549e9e0dfad6dca5c1f0b41f03468d7e76480686
-F ext/wasm/index.html b8a47afa96d0c7ac3081c6d469e1fd7be6b87c64b94e4fb62e26984a1564cac4
+F ext/wasm/index.html 492eb6c9023c9cda391c61702a28bd18e6c986ca2588ec3f384275bb77275285
 F ext/wasm/jaccwabyt/jaccwabyt.js 0d7f32817456a0f3937fcfd934afeb32154ca33580ab264dab6c285e6dbbd215
 F ext/wasm/jaccwabyt/jaccwabyt.md 447cc02b598f7792edaa8ae6853a7847b8178a18ed356afacbdbf312b2588106
 F ext/wasm/jaccwabyt/jaccwabyt_test.c 39e4b865a33548f943e2eb9dd0dc8d619a80de05d5300668e9960fff30d0d36f
@@ -523,9 +523,11 @@ F ext/wasm/speedtest1.html fbb8e4d1639028443f3687a683be660beca6927920545cf6b1fdf
 F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x
 F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
-F ext/wasm/sqlite3-opfs-async-proxy.js ef012be0a77d3e34dc699de2e430b6d26a58c69dbebdd75248d8f41540996c71
+F ext/wasm/sqlite3-opfs-async-proxy.js 456bef1253fd4732f133b601a4450b7f8461e67af6e8d30bf8a239ad775c77a2
 F ext/wasm/sqlite3-worker1-promiser.js 92b8da5f38439ffec459a8215775d30fa498bc0f1ab929ff341fc3dd479660b9
 F ext/wasm/sqlite3-worker1.js 0c1e7626304543969c3846573e080c082bf43bcaa47e87d416458af84f340a9e
+F ext/wasm/test-opfs-vfs.html 3e11c875c28f041891deeea6b2375121845ee1269cac6747df957ec0c7d4d37a w ext/wasm/x-sync-async.html
+F ext/wasm/test-opfs-vfs.js bf70cd553a443b4eda63b577787ef73144f879fa062a20a73bb44e3242c81a15 w ext/wasm/x-sync-async.js
 F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893
 F ext/wasm/testing-worker1-promiser.js 63448fddfd3b8c89ff667d17c8b31c6c2259dd4647ebbbd28f3a921c48e924da
 F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae
@@ -533,8 +535,6 @@ F ext/wasm/testing1.js 7cd8ab255c238b030d928755ae8e91e7d90a12f2ae601b1b8f7827aaa
 F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3
 F ext/wasm/testing2.js 25584bcc30f19673ce13a6f301f89f8820a59dfe044e0c4f2913941f4097fe3c
 F ext/wasm/wasmfs.make 21a5cf297954a689e0dc2a95299ae158f681cae5e90c10b99d986097815fd42d
-F ext/wasm/x-sync-async.html d85cb9b1ab398ef5a20ce64a689ce4bf9a347ffe69edd46c2d3dc57b869a8925
-F ext/wasm/x-sync-async.js 95142516c0e467480fb87e71d7aab5b8ecee07fe7bd4babb5f5aa9b5b6ace4d0
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
 F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
@@ -2030,8 +2030,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 a0e93ed20b2463606a63b03ce8ca41ec1fb22886db5c5c898ace86ba24636f70
-R 088ef11f22396ef93f0589b73a5e4797
+P 1c660970d0f62bcfd6e698a72b050d99972a1e39f45a5ac24194a190f8f78ab3
+R 039a2cd7ec4da87358ad6184da91bc68
 U stephan
-Z 0f7cc3e7ea750e2836a1d35bc86649c9
+Z 58e9ce410c47c756bc153984b857c4cf
 # Remove this line to create a well-formed Fossil manifest.
index 955e61f29c2ba7bac06fa5e6165f4cc3b35f6271..d80c68d21c71138a7bfad5c8fa726e0efec289e6 100644 (file)
@@ -1 +1 @@
-1c660970d0f62bcfd6e698a72b050d99972a1e39f45a5ac24194a190f8f78ab3
\ No newline at end of file
+b2abf60dbfa6648f671a3932cb65feb28d05a0d5b7f792351d14f9c13d9798c5
\ No newline at end of file