khonsulabs / bonsaidb

A developer-friendly document database that grows with you, written in Rust
https://bonsaidb.io/
Apache License 2.0
1.01k stars 37 forks source link

Implement large file storage #238

Closed ecton closed 2 years ago

ecton commented 2 years ago

Closes #222

The goal of this pull request is to offer a general purpose approach to storing files within BonsaiDb. I also see this as a simpler playground for me to experiment with how to handle API permissions than the jobs pull request.

After pondering how to make this as useful as possible while keeping it fairly simple, here's the approach I've decided to take:

This is a new crate, bonsaidb-files. Internally it defines two collections: File and Block. The File collection contains all the information to build a virtual filesystem: Name, Path, Metadata.

The public facing API exposes a File type that accepts a generic parameter: a FileConfig implementation. This trait allows customizing the collection names and the BLOCK_SIZE.

When appending data to a file, the data is broken into chunks with a maximum size of BLOCK_SIZE. The current implementation uses 64kb as the block size.

The file contents can be queried, at which point a Contents type is returned. Internally, this type has a list of all of the block IDs and their lengths.

The Contents type will implement:

Behind the scenes, the Contents type supports requesting blocks in chunks from the database. This defaults to 10, but can be customized.

Operations planned to be supported:

Other Todos:

Ideas maybe worth exploring: