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

Partitioned file storage #35

Merged
merged 13 commits into from
Dec 25, 2023
Merged

Partitioned file storage #35

merged 13 commits into from
Dec 25, 2023

Conversation

cute-the-niini
Copy link
Member

The idea is that this will replace all current uses of IndexedDB as a file storage, consequently reducing the amount of blobs the browser needs to move around when iterating over the tables (and also reduce some of the awkward normalisation needs currently employed). This does have the nice effect of making the interference between different cartridges' data a bit less of a pain.

This patch in particular only introduces the partitioned file storage and changes the cartridge data storage to use it. The file storage is based around reference-counted buckets that hold arbitrary numbers of objects, similar to what you would get with cloud object storages (other than the reference-counted part). Being reference-counted, there's a separate GC process that will now reclaim storage space whenever a bucket's reference counter reaches 0. This works similarly for temporary buckets and persistent ones --- a persistent bucket just has references held by a long-lived entity, such as a row in the database, instead of a JS memory reference. For tracking JS references it holds a set of weak references and finalisers to clean up the set.

Cartridge installation is no longer fully-transactional as a result of this, because OPFS is not transactional. Instead, the process first creates a new bucket that holds all of the files in the cartridge, persists it, then attempts to create a database entry for the cartridge metadata (pointing to the persisted bucket). If it fails, the GC will validate that the persistent reference is still in effect next time it runs, and will decrease the counter accordingly if the row that's supposed to point back to the bucket is not in the database, consequently allowing the bucket's resources to be freed.

@cute-the-niini cute-the-niini added enhancement New feature or request c:kernel Changes to the Kate emulator kernel (requires strict audits!) labels Dec 25, 2023
@cute-the-niini cute-the-niini merged commit eb0d70d into main Dec 25, 2023
1 check passed
@cute-the-niini cute-the-niini deleted the patch/file-store branch December 25, 2023 16:21
@cute-the-niini cute-the-niini restored the patch/file-store branch December 25, 2023 16:24
cute-the-niini added a commit that referenced this pull request Dec 25, 2023
The idea is that this will replace all current uses of IndexedDB as a file storage, consequently reducing the amount of blobs the browser needs to move around when iterating over the tables (and also reduce some of the awkward normalisation needs currently employed). This does have the nice effect of making the interference between different cartridges' data a bit less of a pain.

This patch in particular only introduces the partitioned file storage and changes the cartridge data storage to use it. The file storage is based around reference-counted buckets that hold arbitrary numbers of objects, similar to what you would get with cloud object storages (other than the reference-counted part). Being reference-counted, there's a separate GC process that will now reclaim storage space whenever a bucket's reference counter reaches 0. This works similarly for temporary buckets and persistent ones --- a persistent bucket just has references held by a long-lived entity, such as a row in the database, instead of a JS memory reference. For tracking JS references it holds a set of weak references and finalisers to clean up the set.

Cartridge installation is no longer fully-transactional as a result of this, because OPFS is not transactional. Instead, the process first creates a new bucket that holds all of the files in the cartridge, persists it, then attempts to create a database entry for the cartridge metadata (pointing to the persisted bucket). If it fails, the GC will validate that the persistent reference is still in effect next time it runs, and will decrease the counter accordingly if the row that's supposed to point back to the bucket is not in the database, consequently allowing the bucket's resources to be freed.
@cute-the-niini cute-the-niini deleted the patch/file-store branch December 25, 2023 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:kernel Changes to the Kate emulator kernel (requires strict audits!) enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant