Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I implement file locking in a VFS? #5

Closed
rhashimoto opened this issue May 8, 2021 · 0 comments
Closed

How do I implement file locking in a VFS? #5

rhashimoto opened this issue May 8, 2021 · 0 comments
Labels
faq

Comments

@rhashimoto
Copy link
Owner

@rhashimoto rhashimoto commented May 8, 2021

The example IndexedDB virtual filesystem implementation checks and sets an isLocked flag in IndexedDB and just returns a SQLITE_BUSY error when attempting to lock a file that is already locked (instead of waiting to obtain the lock). [this is no longer how it works] While this might work for some applications, it has some drawbacks:

  • A retry-on-busy approach is prone to starvation.
  • The lock can be orphaned if the lock holder exits without releasing it.
    • Ideally a lock expires automatically with the holder lifetime, which is not the case when the lock is stored in IndexedDB.
    • Orphaned locks typically require user-initiated clearing.

Here are some alternative mechanisms for synchronization on the web platform:

  • Web Locks API
    • Looks great.
    • Doesn't directly support upgradeable locks, i.e. from shared to exclusive.
    • Not supported on Safari (but in the Technology Preview release as of 12/20/21).
    • Example use as a VFS mix-in is here.
  • Atomics
    • Workers in same cluster only (i.e. not between browser tabs).
    • Allows synchronous blocking, so it can work with the synchronous SQLite build (which is smaller and faster).
    • Not supported on Safari (but in preview behind a flag). [Supported now]
    • Severe restrictions on including content from other origins.
  • Service Worker
@rhashimoto rhashimoto added the faq label May 8, 2021
@rhashimoto rhashimoto closed this May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq
Projects
None yet
Development

No branches or pull requests

1 participant