Compare commits

...

1 Commits

Author SHA1 Message Date
stephan d001060225 Refactoring towards being able to distinguish locking-related errors from non-locking errors in OPFS VFS operations. On a branch because it's not yet clear whether this is a misuse of the SQLITE_IOERR_... codes.
FossilOrigin-Name: 646fe2ce871d583f575f392b486bbe59658e49322dc336d79adf2edb2ee64aec
2022-10-30 11:22:45 +00:00
4 changed files with 78 additions and 36 deletions
+19 -11
View File
@@ -316,19 +316,27 @@ const installOpfsVfs = function callee(options){
*/
state.sq3Codes = Object.create(null);
[
'SQLITE_ERROR', 'SQLITE_IOERR',
'SQLITE_NOTFOUND', 'SQLITE_MISUSE',
'SQLITE_IOERR_READ', 'SQLITE_IOERR_SHORT_READ',
'SQLITE_IOERR_WRITE', 'SQLITE_IOERR_FSYNC',
'SQLITE_IOERR_TRUNCATE', 'SQLITE_IOERR_DELETE',
'SQLITE_IOERR_ACCESS', 'SQLITE_IOERR_CLOSE',
'SQLITE_ERROR',
'SQLITE_IOERR',
'SQLITE_IOERR_ACCESS',
'SQLITE_IOERR_CLOSE',
'SQLITE_IOERR_DELETE',
'SQLITE_LOCK_NONE',
'SQLITE_LOCK_SHARED',
'SQLITE_LOCK_RESERVED',
'SQLITE_LOCK_PENDING',
'SQLITE_IOERR_FSYNC',
'SQLITE_IOERR_LOCK',
'SQLITE_IOERR_READ',
'SQLITE_IOERR_SHORT_READ',
'SQLITE_IOERR_TRUNCATE',
'SQLITE_IOERR_UNLOCK',
'SQLITE_IOERR_WRITE',
'SQLITE_LOCK_EXCLUSIVE',
'SQLITE_OPEN_CREATE', 'SQLITE_OPEN_DELETEONCLOSE',
'SQLITE_LOCK_NONE',
'SQLITE_LOCK_PENDING',
'SQLITE_LOCK_RESERVED',
'SQLITE_LOCK_SHARED',
'SQLITE_MISUSE',
'SQLITE_NOTFOUND',
'SQLITE_OPEN_CREATE',
'SQLITE_OPEN_DELETEONCLOSE',
'SQLITE_OPEN_READONLY'
].forEach((k)=>{
if(undefined === (state.sq3Codes[k] = capi[k])){
+48 -17
View File
@@ -135,6 +135,25 @@ const getDirForFilename = async function f(absFilename, createDirs = false){
return [dh, filename];
};
/**
An error class specifically for use with getSyncHandle(), the goal
of which is to eventually be able to distinguish unambiguously
between locking-related failures and other types, noting that we
cannot currently do so because createSyncAccessHandle() does not
define its exceptions in the required level of detail.
*/
class GetSyncHandleError extends Error {
constructor(errorObject, ...msg){
super();
this.error = errorObject;
this.message = [
...msg, ': Original exception ['+errorObject.name+']:',
errorObject.message
].join(' ');
this.name = 'GetSyncHandleError';
}
};
/**
Returns the sync access handle associated with the given file
handle object (which must be a valid handle object, as created by
@@ -154,16 +173,17 @@ const getSyncHandle = async (fh)=>{
let i = 1, ms = msBase;
for(; true; ms = msBase * ++i){
try {
//if(i<3) toss("Just testing.");
//if(1 || i<2) toss("Just testing getSyncHandle() exception handling.");
//TODO? A config option which tells it to throw here
//randomly every now and then, for testing purposes.
fh.syncHandle = await fh.fileHandle.createSyncAccessHandle();
break;
}catch(e){
if(i === maxTries){
toss("Error getting sync handle.",maxTries,
"attempts failed. ",fh.filenameAbs, ":", e.message);
throw e;
throw new GetSyncHandleError(
e, "Error getting sync handle.",maxTries,
"attempts failed.",fh.filenameAbs
);
}
warn("Error getting sync handle. Waiting",ms,
"ms and trying again.",fh.filenameAbs,e);
@@ -199,7 +219,7 @@ const closeSyncHandle = async (fh)=>{
Atomics.notify()'s it.
*/
const storeAndNotify = (opName, value)=>{
log(opName+"() => notify(",state.opIds.rc,",",value,")");
log(opName+"() => notify( rc =",value,")");
Atomics.store(state.sabOPView, state.opIds.rc, value);
Atomics.notify(state.sabOPView, state.opIds.rc);
};
@@ -371,18 +391,20 @@ const vfsAsyncImpls = {
xFileSize: async function(fid/*sqlite3_file pointer*/){
mTimeStart('xFileSize');
const fh = __openFiles[fid];
let sz;
let rc;
wTimeStart('xFileSize');
try{
sz = await (await getSyncHandle(fh)).getSize();
state.s11n.serialize(Number(sz));
sz = 0;
rc = await (await getSyncHandle(fh)).getSize();
state.s11n.serialize(Number(rc));
rc = 0;
}catch(e){
state.s11n.storeException(2,e);
sz = state.sq3Codes.SQLITE_IOERR;
rc = (e instanceof GetSyncHandleError)
? state.sq3Codes.SQLITE_IOERR_LOCK
: state.sq3Codes.SQLITE_IOERR;
}
wTimeEnd();
storeAndNotify('xFileSize', sz);
storeAndNotify('xFileSize', rc);
mTimeEnd();
},
xLock: async function(fid/*sqlite3_file pointer*/,
@@ -395,7 +417,9 @@ const vfsAsyncImpls = {
try { await getSyncHandle(fh) }
catch(e){
state.s11n.storeException(1,e);
rc = state.sq3Codes.SQLITE_IOERR;
rc = (e instanceof GetSyncHandleError)
? state.sq3Codes.SQLITE_IOERR_LOCK
: state.sq3Codes.SQLITE_IOERR;
}
wTimeEnd();
}
@@ -465,7 +489,9 @@ const vfsAsyncImpls = {
if(undefined===nRead) wTimeEnd();
error("xRead() failed",e,fh);
state.s11n.storeException(1,e);
rc = state.sq3Codes.SQLITE_IOERR_READ;
rc = (e instanceof GetSyncHandleError)
? state.sq3Codes.SQLITE_IOERR_LOCK
: state.sq3Codes.SQLITE_IOERR_READ;
}
storeAndNotify('xRead',rc);
mTimeEnd();
@@ -480,6 +506,7 @@ const vfsAsyncImpls = {
await fh.syncHandle.flush();
}catch(e){
state.s11n.storeException(2,e);
rc = state.sq3Codes.SQLITE_IOERR_FSYNC;
}
wTimeEnd();
}
@@ -497,7 +524,9 @@ const vfsAsyncImpls = {
}catch(e){
error("xTruncate():",e,fh);
state.s11n.storeException(2,e);
rc = state.sq3Codes.SQLITE_IOERR_TRUNCATE;
rc = (e instanceof GetSyncHandleError)
? state.sq3Codes.SQLITE_IOERR_LOCK
: state.sq3Codes.SQLITE_IOERR_TRUNCATE;
}
wTimeEnd();
storeAndNotify('xTruncate',rc);
@@ -514,7 +543,7 @@ const vfsAsyncImpls = {
try { await closeSyncHandle(fh) }
catch(e){
state.s11n.storeException(1,e);
rc = state.sq3Codes.SQLITE_IOERR;
rc = state.sq3Codes.SQLITE_IOERR_UNLOCK;
}
wTimeEnd();
}
@@ -536,7 +565,9 @@ const vfsAsyncImpls = {
}catch(e){
error("xWrite():",e,fh);
state.s11n.storeException(1,e);
rc = state.sq3Codes.SQLITE_IOERR_WRITE;
rc = (e instanceof GetSyncHandleError)
? state.sq3Codes.SQLITE_IOERR_LOCK
: state.sq3Codes.SQLITE_IOERR_WRITE;
}
wTimeEnd();
storeAndNotify('xWrite',rc);
@@ -641,7 +672,7 @@ const initS11n = ()=>{
state.s11n.storeException = state.asyncS11nExceptions
? ((priority,e)=>{
if(priority<=state.asyncS11nExceptions){
state.s11n.serialize(e.message);
state.s11n.serialize([e.name,': ',e.message].join(''));
}
})
: ()=>{};
+10 -7
View File
@@ -1,5 +1,5 @@
C Adjust\sautomatic\sOPFS\slocking\sretries\ssuch\sthat\sthey\swill\swait\sup\sto\sa\stotal\sof\s3\sseconds\sspanning\s4\sattempts.
D 2022-10-30T10:24:53.526
C Refactoring\stowards\sbeing\sable\sto\sdistinguish\slocking-related\serrors\sfrom\snon-locking\serrors\sin\sOPFS\sVFS\soperations.\sOn\sa\sbranch\sbecause\sit's\snot\syet\sclear\swhether\sthis\sis\sa\smisuse\sof\sthe\sSQLITE_IOERR_...\scodes.
D 2022-10-30T11:22:45.699
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -501,11 +501,11 @@ F ext/wasm/api/pre-js.js 287e462f969342b032c03900e668099fa1471d852df7a472de5bc34
F ext/wasm/api/sqlite3-api-cleanup.js ecdc69dbfccfe26146f04799fcfd4a6f5790d46e7e3b9b6e9b0491f92ed8ae34
F ext/wasm/api/sqlite3-api-glue.js b87543534821ecfa56fc0d0cd153a115fa974e70d6217964baf6e93ef8d25fb1
F ext/wasm/api/sqlite3-api-oo1.js 612063da9838286310712c5411f97b8b20759b1e31e75a9b25b6381541db79a8
F ext/wasm/api/sqlite3-api-opfs.js c67cbe0b1451ec43bc6b3199e13453e1ca56d718a75c0498253b0d479c336256
F ext/wasm/api/sqlite3-api-opfs.js 6880cc79a4d1b6075942298d9d1ab07e24d81fbd9e5fe6b7c797b86e4b2af596
F ext/wasm/api/sqlite3-api-prologue.js a218dda5e5ced8894f65760131371e4cabd31062af58803af8952cc00ea778d2
F ext/wasm/api/sqlite3-api-worker1.js efdca1b42299d80b54f366d15a8fc5343f3b3e9e3647e5c1fd6f3ee1015e501b
F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3
F ext/wasm/api/sqlite3-opfs-async-proxy.js 29f6f5c314c2956e77573c6ab975c2455a0839721ed44f38004382c2a1463ab5
F ext/wasm/api/sqlite3-opfs-async-proxy.js 08acf5cf128f784375776af23b35de6dbdf65cf50928e1131f2748abeebce12e
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
F ext/wasm/api/sqlite3-wasm.c 14ac9c03f6585332f882703f3427f11ffe8ffe8b6c0e252be2c518f7aac6ab6a
F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52aff253afbf3350431f5773faf0e4b
@@ -2054,8 +2054,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 50f678846a2b3c3d0818f0bae89f2ee86252a2e6a9c7029ebaae3953ca0fa14c
R 1972183d0891a999ac8d66d2a75ace56
P bbce49d81abc491ca666474040a53057e26e99131fea9449de253f88f4415ded
R 2221e9c9fd283b544621efdb3f1e68c6
T *branch * opfs-locking-result-codes
T *sym-opfs-locking-result-codes *
T -sym-trunk * Cancelled\sby\sbranch.
U stephan
Z d56b11be64ada51bbacb5dad8807cd55
Z dbd1acd209f3424e033d21c8b6f257fa
# Remove this line to create a well-formed Fossil manifest.
+1 -1
View File
@@ -1 +1 @@
bbce49d81abc491ca666474040a53057e26e99131fea9449de253f88f4415ded
646fe2ce871d583f575f392b486bbe59658e49322dc336d79adf2edb2ee64aec