Skip to main content

Module disk_environment_store

Module disk_environment_store 

Source
Expand description

§Production disk EnvironmentStore

Backing store used by the real server binary. Persists to a fjall keyspace for metadata and a two-level directory tree (256² slots, ≈16 M bundles before any single directory grows past ~64 K entries) for the bundle bodies. Writes go through a temp-file + rename dance so a mid-write crash never leaves a torn bundle, and feedback-update batches are atomic at the fjall level.

Library choice rationale:

  • fjall over redb (redb compacts synchronously and blocks writes during it, which we can’t afford on a single-node server) and over sled (stalled upstream; its v1.0 rewrite hasn’t landed).
  • postcard for metadata serialisation — compact, fast, stable format, no schema on disk.

Feedback entries are stored under composite keys (location_id, post_id, feedback_type) so range iteration can walk all feedback for a given bundle location during decimation in a single sequential scan.

Structs§

DiskEnvironmentFactory
DiskEnvironmentStore
DiskEnvironmentStore implements the EnvironmentStore trait for production use. PostBundles are stored as files in a directory tree, while config, metadata, feedback, and post-expiry metainformation are stored in a key-value database. A lot of time was spent comparing the different available databases. Given the nature of hashiverse, it makes sense that some sort of key-value (KV) database is used. For simplicity of building and maintenance, we decided to use a pure-Rust implementation. This narrowed teh field down to redb, sled, and fjall. We would have liked to use redb, because of its self-reported performance with individual writes and random range reads - both things that hashiverse does a lot of. Unfortunately it requires occasional compaction of the ever-growing files on disk, something that needs downtime and 2x disk space to do. This essentially killed it for us. Next was sled, which autocompacts and seemed the next most performant, but there seems to be little improvement and support for it - it’s own github repo says use this as beta software only, and work on its v1.0 release seems to have stalled. That leaves fjall - seemingly third place in performance, but gauging by its github activity, is ever improving and is highly supported. It also does autocompaction.
PostBundleFeedbackKey
PostBundleFeedbackValue