Documentation
¶
Overview ¶
Package statekv implements the host KV capability for durable WASM sandboxes (plans/wasm-runtime.md §4.6).
Index ¶
- Variables
- func ValidateKey(key string) error
- func ValidateValue(value []byte) error
- type RateLimitedStore
- func (s *RateLimitedStore) Delete(ctx context.Context, sandboxID, key string) error
- func (s *RateLimitedStore) Get(ctx context.Context, sandboxID, key string) ([]byte, bool, error)
- func (s *RateLimitedStore) ListKeys(ctx context.Context, sandboxID string) ([]string, error)
- func (s *RateLimitedStore) Set(ctx context.Context, sandboxID, key string, value []byte) error
- type SQLiteStore
- func (s *SQLiteStore) Delete(ctx context.Context, sandboxID, key string) error
- func (s *SQLiteStore) Get(ctx context.Context, sandboxID, key string) ([]byte, bool, error)
- func (s *SQLiteStore) ListKeys(ctx context.Context, sandboxID string) ([]string, error)
- func (s *SQLiteStore) Set(ctx context.Context, sandboxID, key string, value []byte) error
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("statekv: not found")
ErrNotFound is returned when a key is absent.
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 ValidateValue ¶
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
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
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.