Documentation
¶
Overview ¶
Package store implements per-(org, namespace) SQLite shards with optional consensus replication.
Layout on disk:
<rootDir>/<orgID>/<namespace>.db — one SQLite file per namespace <rootDir>/_/<namespace>.db — orgID == "" (embedded/dev)
Schema (single table; key/value blob):
CREATE TABLE kv( key TEXT PRIMARY KEY, value BLOB NOT NULL, upd INTEGER NOT NULL );
Replication:
A Replicator may be attached via WithReplicator. Every put/del is wrapped in a replication.Frame and Propose'd before the local apply commits. On Accept the frame is also dispatched to peers via the driver-internal Subscribe path.
Index ¶
- Constants
- Variables
- func CopyFile(dst, src string) (int64, error)
- func IsCrossNamespacePrefix(prefix string) bool
- func NsFromKey(key string) (kind, ns, rest string, ok bool)
- func SplitPrefix(prefix string) (kind, ns, suffix string)
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) Get(ctx context.Context, org, ns string) (*Shard, error)
- func (m *Manager) ListShards(ctx context.Context, org string) ([]*Shard, error)
- func (m *Manager) OpenShardCount() int
- func (m *Manager) Replicator() replication.Replicator
- func (m *Manager) RootDir() string
- func (m *Manager) ShardPath(org, ns string) string
- func (m *Manager) WithReplicator(r replication.Replicator)
- type Shard
- func (s *Shard) Checkpoint() error
- func (s *Shard) Close() error
- func (s *Shard) Del(ctx context.Context, key string) error
- func (s *Shard) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (s *Shard) List(ctx context.Context, prefix string, fn func(key string, value []byte) error) error
- func (s *Shard) Namespace() string
- func (s *Shard) Org() string
- func (s *Shard) Path() string
- func (s *Shard) Put(ctx context.Context, key string, value []byte) error
Constants ¶
const SentinelOrg = "_"
SentinelOrg is the on-disk directory name for the empty org slot. We avoid using "" so the path stays well-formed.
Variables ¶
var CrossNamespaceKinds = map[string]bool{ "ns": true, "nx": true, }
CrossNamespaceKinds lists the kinds whose List(prefix) operations must enumerate every shard under the org. Anything else routes to a single shard.
var ErrClosed = errors.New("store: manager closed")
ErrClosed is returned when a method runs after Close.
var IdleEvictAfter = 10 * time.Minute
IdleEvictAfter sets how long an open shard may sit unused before the manager closes it. Mutable for tests.
Functions ¶
func IsCrossNamespacePrefix ¶
IsCrossNamespacePrefix reports whether prefix is a bare kind/ scan that must fan out across shards.
func NsFromKey ¶
nsFromKey parses the canonical key layout to derive the namespace segment. Returns ("", false) for keys that are themselves the namespace registry (`ns/<name>`); the caller treats those specially.
Layout reference:
ns/<name> wf/<ns>/<workflowId>/<runId> wfh/<ns>/<workflowId>/<runId>/<eventId> sc/<ns>/<scheduleId> bt/<ns>/<batchId> dp/<ns>/<deploymentName> nx/<ns>/<endpointName> id/<ns>/<email> sa/<ns>/<attrName> idem/<ns>/<workflowId>/<requestId>
func SplitPrefix ¶
SplitPrefix returns (kind, ns, suffix) for a list prefix. ns may be empty when IsCrossNamespacePrefix(prefix) is true.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the on-disk shard layout and the open-shard cache.
func New ¶
New opens the manager rooted at rootDir. The directory is created on demand; errors are returned only for unrecoverable IO problems.
func (*Manager) Get ¶
Get returns the open shard for (org, ns), creating it on disk if needed. The returned Shard is safe for concurrent use.
func (*Manager) ListShards ¶
ListShards enumerates every namespace shard under org. Used by cross-namespace operations like ListNamespaces().
func (*Manager) OpenShardCount ¶
OpenShardCount reports the number of resident shards (for /v1/tasks/cluster).
func (*Manager) Replicator ¶
func (m *Manager) Replicator() replication.Replicator
Replicator returns the currently-installed driver, or nil.
func (*Manager) WithReplicator ¶
func (m *Manager) WithReplicator(r replication.Replicator)
WithReplicator installs r as the consensus driver for every shard opened from now on, and re-installs it on already-open shards.
type Shard ¶
type Shard struct {
// contains filtered or unexported fields
}
Shard owns one SQLite file. WAL mode + foreign keys + 5s busy timeout. One writer; readers share the cache. Replicator hooks fire from put/del before local commit so the cluster sees the mutation first.
func (*Shard) Checkpoint ¶
Checkpoint forces a WAL truncation without releasing the connection. Used by the migration tool to make the on-disk file fully self-contained before copy.
func (*Shard) List ¶
func (s *Shard) List(ctx context.Context, prefix string, fn func(key string, value []byte) error) error
List walks every kv row whose key starts with prefix in lexicographic order.