Documentation
¶
Overview ¶
Package scriva is the embedded façade over the ScrivaDB storage engine. It is the ergonomic, zero-server entry point for programs that want to compile ScrivaDB in-process and host several collections — each with its own durability and compaction settings — from a single data directory.
It is a thin convenience layer over engine.DB: Open returns a handle, and Collection/MustCollection lazily open-or-create a named collection under per-collection options. Anything the façade does not expose is reachable via Engine.
Embedded durability default (OPS-1) ¶
Unlike the raw engine — whose default is SyncModeNone (fastest, but a crash can lose recently acknowledged writes) — a DB opened through scriva.Open defaults every collection to SyncModeInterval at a 1s cadence. This trades a bounded (~1s) durability window for throughput: a crash can lose at most the last interval's writes, while the append-only, temp-then-rename segment format already rules out torn/partial records. It is the right default for a local, single-writer daemon that wants crash-safety without paying an fsync on every write.
Write paths that genuinely need per-write durability (a spend/ledger collection, say) can opt back into SyncModeAlways per collection with WithCollectionSyncMode(engine.SyncModeAlways) — an explicit escape hatch that fsyncs before every write is acknowledged. Every other engine default (segment size, compaction cadence, watch buffer) is left untouched unless overridden.
Index ¶
- type CollectionOption
- func WithCollectionCompactInterval(d time.Duration) CollectionOption
- func WithCollectionSegmentMaxSize(n int64) CollectionOption
- func WithCollectionSyncInterval(d time.Duration) CollectionOption
- func WithCollectionSyncMode(m engine.SyncMode) CollectionOption
- func WithCollectionWatchBufferSize(n int) CollectionOption
- func WithMaxBytes(n uint64) CollectionOption
- func WithMaxRecords(n uint64) CollectionOption
- func WithUniqueIndex(fields ...string) CollectionOption
- type DB
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CollectionOption ¶
type CollectionOption func(*collectionOptions)
CollectionOption overrides the DB-wide defaults for a single collection and/or declares unique indexes to ensure when the collection is opened.
func WithCollectionCompactInterval ¶
func WithCollectionCompactInterval(d time.Duration) CollectionOption
WithCollectionCompactInterval overrides the compaction cadence for this collection.
func WithCollectionSegmentMaxSize ¶
func WithCollectionSegmentMaxSize(n int64) CollectionOption
WithCollectionSegmentMaxSize overrides the segment rotation size for this collection.
func WithCollectionSyncInterval ¶
func WithCollectionSyncInterval(d time.Duration) CollectionOption
WithCollectionSyncInterval overrides the flush cadence for this collection.
func WithCollectionSyncMode ¶
func WithCollectionSyncMode(m engine.SyncMode) CollectionOption
WithCollectionSyncMode overrides the durability policy for this collection only. The headline use is WithCollectionSyncMode(engine.SyncModeAlways) for a write path (a spend/ledger collection) that needs an fsync on every write, while the rest of the store keeps the interval default.
func WithCollectionWatchBufferSize ¶
func WithCollectionWatchBufferSize(n int) CollectionOption
WithCollectionWatchBufferSize overrides the Watch buffer size for this collection.
func WithMaxBytes ¶
func WithMaxBytes(n uint64) CollectionOption
WithMaxBytes caps this collection's on-disk footprint at n bytes (S4, the summed size of its segment files): once the budget is reached, a write that would create a new record is refused with engine.ErrResourceExhausted. Like WithMaxRecords it gates only new-record creation, so a tenant at its limit can still update or delete to recover. Zero (the default) leaves it unlimited.
func WithMaxRecords ¶
func WithMaxRecords(n uint64) CollectionOption
WithMaxRecords caps this collection at n live records (S4): an insert, keyed insert, inserting upsert, batch, or transaction that would create a record beyond the cap is refused with engine.ErrResourceExhausted, before anything is written. An in-place update or a delete is never refused. Zero (the default) leaves the record count unlimited.
func WithUniqueIndex ¶
func WithUniqueIndex(fields ...string) CollectionOption
WithUniqueIndex ensures a unique secondary index on each named field when the collection is opened (via engine.Collection.EnsureUniqueIndex). Subsequent inserts or updates that would map a field's value to a different live record are rejected with engine.ErrDuplicateKey. Fields already indexed are left as they are.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is an embedded FileDB handle: a set of named collections rooted at one data directory, opened in-process with no server. It is safe for concurrent use.
func Open ¶
Open opens (or creates) an embedded database rooted at dir. Existing collections on disk are discovered automatically. Every collection defaults to SyncModeInterval at a 1s cadence (see the package doc for the OPS-1 rationale); pass Options to change the DB-wide defaults.
func (*DB) Collection ¶
func (db *DB) Collection(name string, opts ...CollectionOption) (*engine.Collection, error)
Collection opens (or creates) the named collection, applying the DB-wide defaults overlaid with any CollectionOption. The first call for a given name wins: later calls return the same handle and ignore their options, so the per-collection config is fixed at first open. Use it once per collection at startup.
func (*DB) Engine ¶
Engine returns the underlying engine.DB for operations the façade does not wrap (ListCollections, DropCollection, …). Collections opened directly on the returned handle bypass the façade's caching and per-collection option layer.
func (*DB) MustCollection ¶
func (db *DB) MustCollection(name string, opts ...CollectionOption) *engine.Collection
MustCollection is Collection that panics on error. It is a convenience for package/struct initialization, where a store's fixed set of collections is opened once and a failure is fatal.
type Option ¶
type Option func(*engine.CollectionConfig)
Option configures the DB-wide defaults applied to every collection opened through the façade. Options mutate the base engine.CollectionConfig that is also handed to the engine when it pre-opens existing collections, so they take effect uniformly.
func WithCompactInterval ¶
WithCompactInterval sets the background compaction cadence.
func WithSegmentMaxSize ¶
WithSegmentMaxSize sets the maximum active-segment size before rotation.
func WithSyncInterval ¶
WithSyncInterval sets the flush cadence used under SyncModeInterval. The façade default is 1s.
func WithSyncMode ¶
WithSyncMode overrides the default durability policy for every collection. The façade default is engine.SyncModeInterval; pass engine.SyncModeAlways for strict per-write fsync or engine.SyncModeNone to match the raw engine.
func WithWatchBufferSize ¶
WithWatchBufferSize sets the per-subscriber Watch channel buffer.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
scriva
command
|
|
|
scriva-cli
command
|
|
|
Package engine implements the core FileDB storage engine.
|
Package engine implements the core FileDB storage engine. |
|
examples
|
|
|
watch
command
Command watch is a self-contained example of consuming FileDB's change feed entirely in-process — no server, no gRPC, no network.
|
Command watch is a self-contained example of consuming FileDB's change feed entirely in-process — no server, no gRPC, no network. |
|
internal
|
|
|
auth
Package auth provides gRPC interceptors for API key authentication with per-key scoping (read vs read-write), an optional per-key collection allow-list (S3), and hot-reloadable key sets for rotation.
|
Package auth provides gRPC interceptors for API key authentication with per-key scoping (read vs read-write), an optional per-key collection allow-list (S3), and hot-reloadable key sets for rotation. |
|
envkey
Package envkey resolves the API key from the environment, preferring the current SCRIVA_API_KEY variable while still honoring the legacy FILEDB_API_KEY name for one release cycle.
|
Package envkey resolves the API key from the environment, preferring the current SCRIVA_API_KEY variable while still honoring the legacy FILEDB_API_KEY name for one release cycle. |
|
metrics
Package metrics provides Prometheus instrumentation for ScrivaDB.
|
Package metrics provides Prometheus instrumentation for ScrivaDB. |
|
pb/proto
Package proto is a reverse proxy.
|
Package proto is a reverse proxy. |
|
Package query implements filter evaluation for FileDB scan operations.
|
Package query implements filter evaluation for FileDB scan operations. |
|
Package store handles low-level NDJSON encoding and decoding for FileDB segment entries.
|
Package store handles low-level NDJSON encoding and decoding for FileDB segment entries. |