Documentation
¶
Overview ¶
Package badger is the durable kvstore.KV driver (ADR-0066): a pure-Go Badger instance (separate from the metastore's, ADR-0065) with a single-writer group-commit gateway and per-store DropPrefix teardown. It also defines the Backup/CDC extension seams (ADR-0067/0068) — both absent by default, so the base driver writes no change-log and runs no background loop.
Index ¶
Constants ¶
const Reserved = "\x00"
Reserved is the NUL-prefixed namespace for the driver's internal keys (the CDC outbox + its cursors, ADR-0068). NUL cannot occur in a facade tenant key (<namespace>/<binding>/<key>), so List excludes it without ever hiding a real key. The CDC seam writes under this prefix.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open opens (creating if absent) a durable Badger-backed kvstore.KV at dir, starting the single-writer group-commit gateway and the value-log GC. Close drains the gateway, stops GC, and releases the DB.
func RunBackup ¶
RunBackup drives the incremental + re-baseline cadence of a backup from NewBackup until ctx is cancelled (the daemon starts it in a goroutine when DR is enabled). A nil/non-*backup b is a no-op.
func RunCDC ¶
RunCDC drives the tailer until ctx is cancelled (the daemon starts it in a goroutine when CDC is enabled). A failed pass (e.g. a transient sink publish error) is logged and the tailer restarts from the durable cursor after cdcRetryDelay, so delivery resumes with no loss. A nil/non-*cdc c is a no-op.
Types ¶
type Backup ¶
type Backup interface {
Ship(ctx context.Context) (cursor uint64, err error)
Restore(ctx context.Context) error
}
Backup is the OPT-IN DR seam (ADR-0067). nil/absent unless DR is configured.
type BackupConfig ¶
BackupConfig configures the opt-in DR backup (ADR-0067). Zero ChunkBytes ⇒ 64 MiB.
type CDC ¶
type CDC interface {
OnWrite(txn *badger.Txn, key string, op Op) error
Tail(ctx context.Context) error
}
CDC is the OPT-IN change-feed seam (ADR-0068). OnWrite is the write-hook the gateway calls INSIDE the data txn so the change-log entry commits atomically with the data; Tail publishes from a durable cursor.
type CDCConfig ¶
CDCConfig configures the opt-in change-feed (ADR-0068). Subject is the bus subject to publish to (the configured sink); zero Retention ⇒ 24h.
type Option ¶
type Option func(*config)
Option tunes the driver.
func WithBackup ¶
WithBackup wires the opt-in DR seam (ADR-0067). Absent ⇒ no backup.
func WithSyncWrites ¶
WithSyncWrites toggles fsync-on-commit (default true).
func WithValueLogGCInterval ¶
WithValueLogGCInterval sets the value-log GC cadence (default 5m; 0 disables).
type Seams ¶
type Seams struct {
Backup Backup // nil unless kvstore.backup.enabled
CDC CDC // nil unless kvstore.cdc.enabled
}
Seams holds the optional DR + CDC the daemon wires when configured (ADR-0067/0068). A nil field means that seam is off — the base driver then writes no change-log and runs no DR loop.
func OpenWithSeams ¶
func OpenWithSeams( dir string, buildBackup func(*badger.DB) (Backup, error), buildCDC func(*badger.DB) (CDC, error), opts ...Option, ) (kvstore.KV, Seams, error)
OpenWithSeams opens the durable KV driver (ADR-0066) and wires the opt-in DR/CDC seams to the SAME Badger instance. It resolves the bootstrap order the per-seam constructors imply — NewBackup/NewCDC need the *badger.DB that Open creates — by opening the db first, building each seam (when its builder is non-nil) over that db, then starting the gateway with the seams already attached (so CDC's OnWrite fires on the very first write, with no attach-after-start race). With both builders nil it is exactly Open. The seams' background loops (Backup.Ship cadence, CDC.Tail) are started by the caller.
func OpenWithSeamsFor ¶
func OpenWithSeamsFor( dir string, bucket blob.Bucket, bcfg BackupConfig, sink bus.Bus, ccfg CDCConfig, opts ...Option, ) (kvstore.KV, Seams, error)
OpenWithSeamsFor is the daemon-facing opener: it wires the opt-in seams from plain values, hiding the *badger.DB. A non-nil bucket enables DR backup (ADR-0067); a non-nil sink enables CDC (ADR-0068). Start the seams' loops with RunBackup / RunCDC on the returned Seams.