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

wip: HTTP VFS for read only access to a datadir on a web server #364

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

samwillis
Copy link
Collaborator

@samwillis samwillis commented Oct 2, 2024

Export a database from PGlite with dumpDataDir, with this is now includes an index.json as a file listing. Untar to a web server, use the HttpFs vfs, and point it at the dir on the server:

const pg = await PGlite.create({
  fs: new HttpFs("http://localhost/pglite/examples/pgdata", { 
    fetchGranularity: 'file', // 'file' or 'page'
  }),
});

fetchGranularity is self explanatory, when set to "file" it will download the hole file when it is first read, "page" downloads individual file pages using a http range header.

Has support for:

  • Browser: via sync XMLHttpRequest with xhr.responseType = 'arraybuffer', this is only available in a web worker
  • Node: via node workers, it uses a shared array buffer and Atomics to do the request in the worker while blocking the thread where PGlite is running. It currently boots a new worker for each request, we should change this to reuse the worker.

Demo site: https://pglite-httpfs-demo.netlify.app

Screen.Recording.2024-10-03.at.12.25.13.mp4

@samwillis samwillis changed the base branch from main to samwillis/fs-refactor October 2, 2024 18:26
@samwillis samwillis marked this pull request as draft October 2, 2024 18:34
Copy link
Contributor

github-actions bot commented Oct 2, 2024

@thruflo
Copy link
Contributor

thruflo commented Oct 2, 2024

Could this work naturally with S3 / an S3 compatible file store?

@samwillis
Copy link
Collaborator Author

@thruflo yes, for a read path it's trivial. For a write path it would be possible to also make work. But still single connection.

Although this is "read only", it actually maintains an "overlay" of writes on each file. So it's really a snapshot loaded over http, with in-memory writes. It just doesn't write back to the server.

Base automatically changed from samwillis/fs-refactor to main October 8, 2024 18:48
@nestarz
Copy link

nestarz commented Oct 18, 2024

Can we imagine a read/write FS to S3-like storage and in an env where workers (multi-thread) is not allowed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants