Expand description
Shared KV store abstraction for Beyond services.
This crate provides a backend-agnostic interface for key-value storage, with NATS JetStream as the primary implementation.
§Architecture
┌─────────────────────────────────────────────────────────────┐
│ KvReader │ KvWatcher │ KvWriter │
│ (core KV operations) │
├─────────────────────────────────────────────────────────────┤
│ KvStore │
│ (named bucket with reader/watcher/writer) │
├─────────────────────────────────────────────────────────────┤
│ Connection │
│ (lifecycle, store factory, capabilities) │
├─────────────────────────────────────────────────────────────┤
│ NatsConnection │
│ (concrete implementation) │
└─────────────────────────────────────────────────────────────┘Re-exports§
pub use snapshot::AppendLogSnapshot;pub use snapshot::SnapshotStore;
Modules§
- protocol
- Protocol decision kernels — the load-bearing guards of the snapshot
export/import protocol, extracted as pure functions so the PRODUCTION
code and the exhaustive model checker (
tests/model.rs) execute the same logic, not two hand-synchronized copies of it. - snapshot
- Append-only snapshot log for KV state.
Structs§
- Artifact
File - One payload file in an
ExportManifest. - Batch
Config - Batching policy for
watch_applied. - Connection
Capabilities - Capabilities a store connection may support.
- Export
Lease - Coordinates “at most one export per round” across every replica of a fold. See the module docs for the CAS + embedded-expiry mechanism.
- Export
Manifest - Manifest of an exported artifact: what is in it, which backend wrote it, and the cursor its payload is consistent with.
- Export
Request - A request, sent into a running
watch_appliedloop, to export the fold it owns (seeSnapshotStore::export_to). - KvEntry
- A single key-value entry with metadata.
- Lease
Guard - Proof of a won round, returned by
ExportLease::try_acquire. - Lease
Record - The lease key’s value: who holds (or last held) the round, until when, and
— after
LeaseGuard::complete— what was exported. - Nats
Connection - NATS JetStream KV connection.
- Nats
Connection Config - Configuration for NATS connection.
- Store
Config - Configuration for creating a store.
- Version
Token - Opaque version token that abstracts store-specific versioning.
- Watch
Cursor - Opaque position in a watch stream for resuming after disconnect.
Enums§
- Discard
Policy - What a bounded bucket does when it reaches
max_bytes(NATS-specific). - KvError
- Error type for KV operations.
- KvUpdate
- Update event from a watch stream.
- Storage
Type - Storage type for a store.
- Watch
Scope - What to watch: every key, every key under a prefix, or the union of several prefixes.
Constants§
- ARTIFACT_
SCHEMA_ VERSION - Version of the artifact layout itself (
MANIFEST.jsonschema +data/payload convention). Bumped only when the artifact shape changes; the payload format is governed separately byExportManifest::backend_version. - MANIFEST_
FILE - Manifest file name at the artifact root. Written last and fsynced, so its presence (after the atomic rename) means the artifact is complete.
Traits§
- Connection
- Store connection lifecycle and store factory.
- KvPurge
- Purge support - optional, for stores that can reclaim a key’s storage.
- KvReader
- Core read-only KV operations - the minimal interface every store must implement.
- KvStore
- A named KV store (bucket/namespace/database).
- KvTtl
- TTL support - optional, for stores that support key expiration.
- KvWatcher
- Watch capability - optional, not all stores support real-time updates.
- KvWriter
- Write operations - optional, edge proxy is primarily read-only.
Functions§
- nats_
connect - Connect to NATS with various authentication methods.
- watch_
applied - Drive a watch with cursor-after-apply semantics.