statekv

package
v0.7.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package statekv implements the host KV capability for durable WASM sandboxes (plans/wasm-runtime.md §4.6).

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("statekv: not found")

ErrNotFound is returned when a key is absent.

View Source
var ErrRateLimited = errors.New("statekv: write rate limit exceeded")

ErrRateLimited is returned when a sandbox exceeds its host-KV write budget. The toolbox handler maps it to HTTP 429 so the guest backs off instead of the daemon absorbing the write.

Functions

func ValidateKey

func ValidateKey(key string) error

ValidateKey rejects empty or oversized keys.

func ValidateValue

func ValidateValue(value []byte) error

ValidateValue caps value size to keep SQLite rows bounded.

Types

type RateLimitedStore

type RateLimitedStore struct {
	// contains filtered or unexported fields
}

RateLimitedStore throttles per-sandbox write operations (Set/Delete) on top of an inner Store. Host-KV writes land synchronously on the single-writer SQLite store (MaxOpenConns=1), so a chatty durable guest can otherwise contend with the CreateSandbox boot path on the same writer (plans/wasm-runtime.md §4.6 + §4.9; CLAUDE.md single-writer rule forbids a second *sql.DB, so we cap the guest-driven write rate instead). Reads pass through unthrottled — they do not hold the write lock long enough to matter and read-heavy guests are common.

func (*RateLimitedStore) Delete

func (s *RateLimitedStore) Delete(ctx context.Context, sandboxID, key string) error

func (*RateLimitedStore) Get

func (s *RateLimitedStore) Get(ctx context.Context, sandboxID, key string) ([]byte, bool, error)

func (*RateLimitedStore) ListKeys

func (s *RateLimitedStore) ListKeys(ctx context.Context, sandboxID string) ([]string, error)

func (*RateLimitedStore) Set

func (s *RateLimitedStore) Set(ctx context.Context, sandboxID, key string, value []byte) error

type SQLiteStore

type SQLiteStore struct {
	// contains filtered or unexported fields
}

SQLiteStore persists KV rows in the wasm_state_kv table.

func NewSQLiteStore

func NewSQLiteStore(st *store.Store) *SQLiteStore

NewSQLiteStore wraps the daemon SQLite store.

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, sandboxID, key string) error

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, sandboxID, key string) ([]byte, bool, error)

func (*SQLiteStore) ListKeys

func (s *SQLiteStore) ListKeys(ctx context.Context, sandboxID string) ([]string, error)

func (*SQLiteStore) Set

func (s *SQLiteStore) Set(ctx context.Context, sandboxID, key string, value []byte) error

type Store

type Store interface {
	Get(ctx context.Context, sandboxID, key string) ([]byte, bool, error)
	Set(ctx context.Context, sandboxID, key string, value []byte) error
	Delete(ctx context.Context, sandboxID, key string) error
	ListKeys(ctx context.Context, sandboxID string) ([]string, error)
}

Store is the durable per-sandbox key-value API.

func NewRateLimitedStore

func NewRateLimitedStore(inner Store, ratePerSec float64, burst int) Store

NewRateLimitedStore wraps inner with a per-sandbox write limiter. A non-positive rate disables limiting and returns inner unchanged so the feature is fully off by default.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL