Switch opfs-sahpool to use deterministic backing-store file names. Delay VFS registration until after the pool's files are all opened. Fail vfs init if the client's OPFS API has an async FileSystemSyncAccessHandle.close() method (indicating that it's outdated).

FossilOrigin-Name: 7c6697ededee9a64962ac6fd78934c6d6e39258b9558a03c1a6c02bf3be1759e
This commit is contained in:
stephan 2023-07-14 23:02:58 +00:00
parent 92bf6fd4f6
commit bee3213145
3 changed files with 32 additions and 24 deletions

View File

@ -130,9 +130,13 @@ const installOpfsVfs = async function(sqlite3){
'cleanup default VFS wrapper', ()=>(dVfs ? dVfs.dispose() : null)
);
const VState = Object.assign(Object.create(null),{
const getFilename = function(ndx){
return 'sahpool-'+('00'+ndx).substr(-3);
}
const SAHPool = Object.assign(Object.create(null),{
/* OPFS dir in which VFS metadata is stored. */
vfsDir: ".sqlite3-sahpool",
vfsDir: ".sqlite3-opfs-sahpool",
dirHandle: undefined,
/* Maps OPFS access handles to their opaque file names. */
mapAH2Name: new Map(),
@ -142,10 +146,20 @@ const installOpfsVfs = async function(sqlite3){
getCapacity: function(){return this.mapAH2Name.size},
getFileCount: function(){return this.mapPath2AH.size},
addCapacity: async function(n){
for(let i = 0; i < n; ++i){
const name = Math.random().toString(36).replace('0.','');
const cap = this.getCapacity();
for(let i = cap; i < cap+n; ++i){
const name = getFilename(i);
const h = await this.dirHandle.getFileHandle(name, {create:true});
const ah = await h.createSyncAccessHandle();
let ah = await h.createSyncAccessHandle();
if(0===i){
/* Ensure that this client has the "all-synchronous"
OPFS API and fail if they don't. */
if(undefined !== ah.close()){
toss("OPFS API is too old for opfs-sahpool:",
"it has an async close() method.");
}
ah = await h.createSyncAccessHandle();
}
this.mapAH2Name.set(ah,name);
this.setAssociatedPath(ah, '', 0);
}
@ -175,8 +189,8 @@ const installOpfsVfs = async function(sqlite3){
await this.acquireAccessHandles();
}
// much more TODO
})/*VState*/;
})/*SAHPool*/;
sqlite3.SAHPool = SAHPool/*only for testing*/;
// Much, much more TODO...
/**
Impls for the sqlite3_io_methods methods. Maintenance reminder:
@ -287,22 +301,16 @@ const installOpfsVfs = async function(sqlite3){
};
}
try{
SAHPool.isReady = SAHPool.reset().then(async ()=>{
if(0===SAHPool.getCapacity()){
await SAHPool.addCapacity(DEFAULT_CAPACITY);
}
log("vfs list:",capi.sqlite3_js_vfs_list());
sqlite3.vfs.installVfs({
io: {struct: opfsIoMethods, methods: ioSyncWrappers},
vfs: {struct: opfsVfs, methods: vfsSyncWrappers}
});
log("vfs list:",capi.sqlite3_js_vfs_list());
}catch(e){
promiseReject(e);
return;
}
VState.isReady = VState.reset().then(async ()=>{
if(0===VState.getCapacity()){
await VState.addCapacity(DEFAULT_CAPACITY);
}
log("opfs-sahpool VFS initialized.");
promiseResolve(sqlite3);
}).catch(promiseReject);

View File

@ -1,5 +1,5 @@
C Integrate\sthe\sopfs-sahpool\sVFS\sinto\sthe\sJS\sbuild\sand\sget\sit\sloading\s(but\sit's\sstill\sfar\sfrom\sfunctional).
D 2023-07-14T21:48:45.896
C Switch\sopfs-sahpool\sto\suse\sdeterministic\sbacking-store\sfile\snames.\sDelay\sVFS\sregistration\suntil\safter\sthe\spool's\sfiles\sare\sall\sopened.\sFail\svfs\sinit\sif\sthe\sclient's\sOPFS\sAPI\shas\san\sasync\sFileSystemSyncAccessHandle.close()\smethod\s(indicating\sthat\sit's\soutdated).
D 2023-07-14T23:02:58.852
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 961bbc3ccc1fa4e91d6519a96e8811ad7ae60173bd969fee7775dacb6eee1da2
F ext/wasm/api/sqlite3-v-helper.js e5c202a9ecde9ef818536d3f5faf26c03a1a9f5192b1ddea8bdabf30d75ef487
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.js ce281cec8035a501ad5c5fd8826a2ed2e4c598833df9b80f49b8806b7d6a84ad
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.js a54fee5e4112dce167bbcddd496f7817846cc269f859237460a835fe693b9c39
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 891f3a18d9ac9b0422b32fd975319dfcd0af5a8ca392f0cce850524e51b49c87
F ext/wasm/api/sqlite3-wasm.c 12a096d8e58a0af0589142bae5a3c27a0c7e19846755a1a37d2c206352fbedda
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 a93de9f2a553a3a4edd1b361dd6f465a1b0b5b51f7bb8ede432067aedcfefda4
R 810cac7ef97d10423572712b3e6ecbc3
P ef96e6b586825a2b3ed011174309cba8ce1031876c86dc59ed87ab9bbc64f57f
R 1c797ce49382346884871d0f3bb17cf9
U stephan
Z 472fa2e9a25e0392397949c3036372fe
Z de96eab25d9db47795591a43ac723ba9
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
ef96e6b586825a2b3ed011174309cba8ce1031876c86dc59ed87ab9bbc64f57f
7c6697ededee9a64962ac6fd78934c6d6e39258b9558a03c1a6c02bf3be1759e