]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Minor internal cleanups in the opfs-sahpool VFS. opfs-sahpool
authorstephan <stephan@noemail.net>
Fri, 21 Jul 2023 10:51:35 +0000 (10:51 +0000)
committerstephan <stephan@noemail.net>
Fri, 21 Jul 2023 10:51:35 +0000 (10:51 +0000)
FossilOrigin-Name: 74ad31e2908af8225b7aa527dbcd1877423d58163e365317a78453b31e322ea3

ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
manifest
manifest.uuid

index 8a129d60f2d5767db115bfa6a9525412a93ef0ac..28524b613c8596389fc13fb24defd88bcebff755 100644 (file)
@@ -144,11 +144,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     xClose: function(pFile){
       const pool = getPoolForPFile(pFile);
       pool.storeErr();
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       if(file) {
         try{
           pool.log(`xClose ${file.path}`);
-          pool.mapSFileToOFile(pFile, false);
+          pool.mapS3FileToOFile(pFile, false);
           file.sah.flush();
           if(file.flags & capi.SQLITE_OPEN_DELETEONCLOSE){
             pool.deletePath(file.path);
@@ -169,7 +169,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     xFileSize: function(pFile,pSz64){
       const pool = getPoolForPFile(pFile);
       pool.log(`xFileSize`);
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       const size = file.sah.getSize() - HEADER_OFFSET_DATA;
       //log(`xFileSize ${file.path} ${size}`);
       wasm.poke64(pSz64, BigInt(size));
@@ -179,14 +179,14 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       const pool = getPoolForPFile(pFile);
       pool.log(`xLock ${lockType}`);
       pool.storeErr();
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       file.lockType = lockType;
       return 0;
     },
     xRead: function(pFile,pDest,n,offset64){
       const pool = getPoolForPFile(pFile);
       pool.storeErr();
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       pool.log(`xRead ${file.path} ${n} @ ${offset64}`);
       try {
         const nRead = file.sah.read(
@@ -210,7 +210,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       const pool = getPoolForPFile(pFile);
       pool.log(`xSync ${flags}`);
       pool.storeErr();
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       //log(`xSync ${file.path} ${flags}`);
       try{
         file.sah.flush();
@@ -224,7 +224,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       const pool = getPoolForPFile(pFile);
       pool.log(`xTruncate ${sz64}`);
       pool.storeErr();
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       //log(`xTruncate ${file.path} ${iSize}`);
       try{
         file.sah.truncate(HEADER_OFFSET_DATA + Number(sz64));
@@ -237,14 +237,14 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     xUnlock: function(pFile,lockType){
       const pool = getPoolForPFile(pFile);
       pool.log('xUnlock');
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       file.lockType = lockType;
       return 0;
     },
     xWrite: function(pFile,pSrc,n,offset64){
       const pool = getPoolForPFile(pFile);
       pool.storeErr();
-      const file = pool.getOFileForSFile(pFile);
+      const file = pool.getOFileForS3File(pFile);
       pool.log(`xWrite ${file.path} ${n} ${offset64}`);
       try{
         const nBytes = file.sah.write(
@@ -356,7 +356,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
         // Subsequent I/O methods are only passed the sqlite3_file
         // pointer, so map the relevant info we need to that pointer.
         const file = {path, flags, sah};
-        pool.mapSFileToOFile(pFile, file);
+        pool.mapS3FileToOFile(pFile, file);
         file.lockType = capi.SQLITE_LOCK_NONE;
         const sq3File = new capi.sqlite3_file(pFile);
         sq3File.$pMethods = opfsIoMethods.pointer;
@@ -374,11 +374,17 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
      Creates and initializes an sqlite3_vfs instance for an
      OpfsSAHPool. The argument is the VFS's name (JS string).
 
+     Throws if the VFS name is already registered or if something
+     goes terribly wrong via sqlite3.vfs.installVfs().
+
      Maintenance reminder: the only detail about the returned object
      which is specific to any given OpfsSAHPool instance is the $zName
      member. All other state is identical.
   */
   const createOpfsVfs = function(vfsName){
+    if( sqlite3.capi.sqlite3_vfs_find(vfsName)){
+      toss3("VFS name is already registered:", vfsName);
+    }
     const opfsVfs = new capi.sqlite3_vfs();
     /* We fetch the default VFS so that we can inherit some
        methods from it. */
@@ -444,7 +450,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     /* Set of currently-unused SAHs. */
     #availableSAH = new Set();
     /* Maps (sqlite3_file*) to xOpen's file objects. */
-    #mapSqlite3FileToFile = new Map();
+    #mapS3FileToOFile_ = new Map();
+
+    /* Maps SAH to an abstract File Object which contains
+       various metadata about that handle. */
+    //#mapSAHToMeta = new Map();
 
     /** Buffer used by [sg]etAssociatedPath(). */
     #apBody = new Uint8Array(HEADER_CORPUS_SIZE);
@@ -460,9 +470,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     constructor(options = Object.create(null)){
       this.#verbosity = options.verbosity ?? optionDefaults.verbosity;
       this.vfsName = options.name || optionDefaults.name;
-      if( sqlite3.capi.sqlite3_vfs_find(this.vfsName)){
-        toss3("VFS name is already registered:", this.vfsName);
-      }
       this.#cVfs = createOpfsVfs(this.vfsName);
       setPoolForVfs(this.#cVfs.pointer, this);
       this.vfsDir = options.directory || ("."+this.vfsName);
@@ -494,6 +501,17 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     /* Current number of in-use files from pool. */
     getFileCount(){return this.#mapFilenameToSAH.size}
 
+//    #createFileObject(sah,clientName,opaqueName){
+//      const f = Object.assign(Object.create(null),{
+//        clientName, opaqueName
+//      });
+//      this.#mapSAHToMeta.set(sah, f);
+//      return f;
+//    }
+//    #unmapFileObject(sah){
+//      this.#mapSAHToMeta.delete(sah);
+//    }
+
     /**
        Adds n files to the pool's capacity. This change is
        persistent across settings. Returns a Promise which resolves
@@ -506,6 +524,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
         const ah = await h.createSyncAccessHandle();
         this.#mapSAHToName.set(ah,name);
         this.setAssociatedPath(ah, '', 0);
+        //this.#createFileObject(ah,undefined,name);
       }
       return this.getCapacity();
     }
@@ -522,6 +541,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
           break;
         }
         const name = this.#mapSAHToName.get(ah);
+        //this.#unmapFileObject(ah);
         ah.close();
         await this.#dhOpaque.removeEntry(name);
         this.#mapSAHToName.delete(ah);
@@ -762,19 +782,19 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
        Given an (sqlite3_file*), returns the mapped
        xOpen file object.
     */
-    getOFileForSFile(ptr){
-      return this.#mapSqlite3FileToFile.get(ptr);
+    getOFileForS3File(pFile){
+      return this.#mapS3FileToOFile_.get(pFile);
     }
     /**
        Maps or unmaps (if file is falsy) the given (sqlite3_file*)
        to an xOpen file object and to this pool object.
     */
-    mapSFileToOFile(pFile,file){
+    mapS3FileToOFile(pFile,file){
       if(file){
-        this.#mapSqlite3FileToFile.set(pFile, file);
+        this.#mapS3FileToOFile_.set(pFile, file);
         setPoolForPFile(pFile, this);
       }else{
-        this.#mapSqlite3FileToFile.delete(pFile);
+        this.#mapS3FileToOFile_.delete(pFile);
         setPoolForPFile(pFile, false);
       }
     }
index 2ae10ae23991c5622dc496095c8c92e9b5136d51..a0994da2999a3f50bc7bfa123b57b1c7c89fb8a1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Internal\scleanups\sin\sthe\sasync\spart\sof\sthe\sJS\slibrary\sbootstrap\sphase.
-D 2023-07-21T09:10:42.614
+C Minor\sinternal\scleanups\sin\sthe\sopfs-sahpool\sVFS.
+D 2023-07-21T10:51:35.142
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -502,7 +502,7 @@ F ext/wasm/api/sqlite3-api-worker1.js 9f32af64df1a031071912eea7a201557fe39b17386
 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89
 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379
 F ext/wasm/api/sqlite3-v-helper.js 7daa0eab0a513a25b05e9abae7b5beaaa39209b3ed12f86aeae9ef8d2719ed25
-F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js d9abf3cde87aea55ea901e80f70e55b36055e8e5120ed47321af35afb9facdaa
+F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js bb99a931388966a032f635a0cc9cd72685e067f21b95b2a58a660c055020b739
 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js e7a690e0e78ff4d563f2eca468f91db69f001ff4b79c6d2304cbb6f62dca437d
 F ext/wasm/api/sqlite3-wasm.c 8867f1d41c112fb4a2cfe22ff224eccaf309fcdea266cee0ec554f85db72ef0f
 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bc06df0d599e625bde6a10a394e326dc68da9ff07fa5404354580f81566e591f
@@ -2044,8 +2044,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 21a2ca9fc46bf746874579897872e2a45cb07f278abb670dd22b122f7d6a9a6c
-R 29a8f4f8ea37e0c15f874df4805828de
+P b6d57ab63793241a500ea527c5b3216c54b3ff1972d3adbbf42a9a53bfec0aa1
+R 04390a13b454e3d10f0ad00241913292
 U stephan
-Z 8b913efdb9ce5e9239da5b5f12183785
+Z 911ec9b641009d60f6f5bfe849c03052
 # Remove this line to create a well-formed Fossil manifest.
index d10306e8a0782188af8f217f682edd98ac7254b6..7fd82b96880d4934b5d0c48b95e073ab10242278 100644 (file)
@@ -1 +1 @@
-b6d57ab63793241a500ea527c5b3216c54b3ff1972d3adbbf42a9a53bfec0aa1
\ No newline at end of file
+74ad31e2908af8225b7aa527dbcd1877423d58163e365317a78453b31e322ea3
\ No newline at end of file