Documentation
¶
Overview ¶
Package kvstore is the key/value substrate port (ADR-0019): get/put/delete/list over opaque string keys and []byte values. The service facade (internal/services/kv) supplies the tenant-prefixed key (<namespace>/<binding>/<key>); the driver is namespace-agnostic. V1 ships an in-memory driver; JetStream / database-layer drivers are deferred behind this port.
Index ¶
- func CheckStorePrefix(op, prefix string) error
- func CheckWrite(op string, w Write) error
- func Expired(expiresAt uint64, now time.Time) bool
- func ExpiresAt(now time.Time, ttl time.Duration) uint64
- func NewTimeline() string
- func Version(timeline, key string, n uint64) string
- type Conditional
- type Entry
- type KV
- type Result
- type Sweeper
- type Usager
- type Write
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckStorePrefix ¶ added in v0.10.0
CheckStorePrefix refuses a per-store export prefix (ADR-0209 Decision 7) that is empty, lacks the trailing "/" or starts with the NUL of a driver's reserved keys.
func CheckWrite ¶ added in v0.41.0
CheckWrite refuses a Write a driver cannot store: a negative TTL, a TTL with an expiry, or both conditions at once.
func Expired ¶ added in v0.41.0
Expired reports whether a key with expiry expiresAt no longer exists at now, as Badger decides it.
func ExpiresAt ¶ added in v0.41.0
ExpiresAt is the expiry of a key written at now that lives ttl: the next Unix second at or after now+ttl, so the key lives at least ttl and at most a second longer; 0 for no ttl.
func NewTimeline ¶ added in v0.41.0
func NewTimeline() string
NewTimeline mints a store's timeline: 32 random bytes as 64 lowercase hex characters, which key every version's hash; a store mints one when it has none, as ADR-0202 Decision 3 mints the metastore's.
func Version ¶ added in v0.41.0
Version is the version of write n of key on timeline: the first 16 bytes, as 32 lowercase hex characters, of HMAC-SHA256 over n and key, keyed with the timeline. It shows neither n nor the timeline, and another write, key or timeline gives another version (ADR-0320 Decision 2).
Types ¶
type Conditional ¶ added in v0.41.0
type Conditional interface {
GetEntry(ctx context.Context, key string) (Entry, bool, error)
PutIf(ctx context.Context, key string, value []byte, w Write) (Result, error)
DeleteIf(ctx context.Context, key string, version string) (Result, error)
}
Conditional is a driver capability beyond the KV port: versioned reads, writes that hold only while a condition on the key holds, and keys that expire. An expired key is absent to every read and condition at once; a write that returned Done is seen by every later read.
type Entry ¶ added in v0.41.0
type Entry struct {
Value []byte
// Version names this write of the key, an opaque hash (Version): every write gives the key another, and a restore
// another timeline, so a version from before a restore names nothing after it. Callers compare versions for
// equality only.
Version string
// ExpiresAt is the Unix second from which the key no longer exists; 0 is never.
ExpiresAt uint64
}
Entry is a key's value with its version and its expiry.
type KV ¶
type KV interface {
// Get returns the value for key and whether it exists. A missing key is
// (nil, false, nil) — not an error.
Get(ctx context.Context, key string) (value []byte, found bool, err error)
// Put stores value under key (overwriting any existing value).
Put(ctx context.Context, key string, value []byte) error
// Delete removes key; deleting a missing key is a no-op (no error).
Delete(ctx context.Context, key string) error
// List returns the keys that start with prefix.
List(ctx context.Context, prefix string) (keys []string, err error)
}
KV is the key/value port. Errors are api/fault; every method is ctx-first.
type Result ¶ added in v0.41.0
Result is a conditional write's outcome. Done reports that its condition held and the write was stored. Version is then the key's new version ("" after a delete); otherwise it is the key's current version, "" when it does not exist.
type Sweeper ¶ added in v0.41.0
type Sweeper interface {
Sweep(ctx context.Context, now time.Time, limit int, skip func(key string) bool) (swept []string, more bool, err error)
}
Sweeper is a driver capability beyond the KV port: it takes up to limit keys that expired by now and that skip does not name, deletes each through the driver's own write path while its entry is the one that expired, and returns the deleted keys and whether more were due. A key renewed or rewritten since stays; a skipped one waits for a later sweep.
type Usager ¶ added in v0.33.0
Usager is a driver capability beyond the KV port (ADR-0292): the bytes of the keys and values under prefix, which a KVStore's quota measures.
type Write ¶ added in v0.41.0
type Write struct {
// IfAbsent writes only when the key does not exist; an expired key does not.
IfAbsent bool
// IfVersion, when not "", writes or deletes only when the key exists at this version.
IfVersion string
// TTL, when not 0, makes the key expire once it has lived TTL, rounded up to the second.
TTL time.Duration
// ExpiresAt, when not 0, is the expiry itself, for a copy that keeps a key's own; never with TTL.
ExpiresAt uint64
}
Write is what a conditional write requires and how long its key lives. With neither condition it is a Put that reports the new version.
Directories
¶
| Path | Synopsis |
|---|---|
|
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.
|
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. |
|
Package kvstorecontract is the shared conformance suite for the kvstore.KV port (ADR-0019): Run asserts put/get/overwrite/delete/list/missing-key against any driver.
|
Package kvstorecontract is the shared conformance suite for the kvstore.KV port (ADR-0019): Run asserts put/get/overwrite/delete/list/missing-key against any driver. |
|
Package memory is the in-memory kvstore.KV driver (ADR-0019): a mutex-guarded map, for dev/e2e/tests.
|
Package memory is the in-memory kvstore.KV driver (ADR-0019): a mutex-guarded map, for dev/e2e/tests. |