statestore

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyDelimiter       = "||"
	SuffixMetadata     = "metadata"
	SuffixCustomStatus = "customStatus"
	HistoryPrefix      = "history-"
)

Variables

View Source
var ErrUnsupported = errors.New("unsupported state store type")

ErrUnsupported is returned by New when the component type is not one of the four supported backends (state.redis, state.sqlite, state.postgresql/postgres, state.mongodb).

Functions

func AllInstanceMetaPattern

func AllInstanceMetaPattern(namespace string) string

AllInstanceMetaPattern is a KeysLike LIKE pattern matching every instance's metadata key across ALL app-ids in the namespace ("%" matches both the leading app-id segment and the app-id inside the actor type).

func ConnInfo

func ConnInfo(c Component) string

ConnInfo returns a short, human-readable connection summary for a component, suitable for display in the UI. It NEVER includes credentials (passwords or user info). Returns "" when no usable, non-secret metadata is present.

func InstanceKeyPattern

func InstanceKeyPattern(namespace, appID, instanceID string) string

InstanceKeyPattern matches every state key belonging to one instance.

func InstanceMetaPattern

func InstanceMetaPattern(namespace, appID string) string

InstanceMetaPattern is a KeysLike LIKE pattern matching every instance's metadata key for an app ("%" matches the instance-id segment).

func InstancePrefix

func InstancePrefix(namespace, appID, instanceID string) string

InstancePrefix is the "<appId>||<actorType>||<instanceID>||" prefix.

func ParseAppID

func ParseAppID(key string) (string, bool)

ParseAppID returns the app-id segment (segment[0]) of a "||"-joined workflow key. Returns ok=false for a malformed key (fewer than three segments or an empty app-id segment).

func ParseInstanceID

func ParseInstanceID(key string) (string, bool)

ParseInstanceID returns the instance-id segment of a "||"-joined workflow key.

func SeedForTest

func SeedForTest(ctx context.Context, s Store, key string, value []byte) error

SeedForTest is a helper for integration tests that upserts a raw byte value through the public Store interface.

func SetVerbose added in v0.0.8

func SetVerbose(v bool)

SetVerbose lets the backend state stores emit informational logs; wire it to the dashboard's --verbose flag.

func WorkflowActorType

func WorkflowActorType(namespace, appID string) string

WorkflowActorType builds the Dapr workflow actor type for an app.

Types

type Component

type Component struct {
	Name        string               // metadata.name
	Type        string               // spec.type, e.g. "state.redis"
	Version     string               // spec.version
	Metadata    map[string]string    // spec.metadata name->value (inline only)
	SecretRefs  map[string]SecretRef // spec.metadata name->secretKeyRef/envRef (no inline value)
	SecretStore string               // auth.secretStore
	Path        string               // source file path (for display / disambiguation)
}

Component is the parsed subset of a Dapr state-store component YAML we need.

func Detect

func Detect(paths []string) ([]Component, error)

Detect finds state-store components under the given files or directories.

func Translate

func Translate(c Component, hosts HostLookup, paths PathLookup) Component

Translate rewrites c's connection metadata for access from the host: state.redis redisHost, state.postgresql/postgres connection strings (URL or key=value DSN), and state.sqlite file paths. Only exact lookup hits are rewritten — foreign hostnames pass through so a connection failure stays honest. Copy-on-write: c is never mutated; the returned Component carries a fresh Metadata map only when something changed.

type HostLookup

type HostLookup func(host string, port int) (string, bool)

HostLookup resolves a compose-network hostname + port to a host-reachable "host:port". ok=false leaves the original address untouched.

type PathLookup

type PathLookup func(containerPath string) (string, bool)

PathLookup resolves a container-internal file path to a host path.

type Record added in v0.0.18

type Record struct {
	Key       string
	Value     []byte
	ETag      string     // "" when the backend has none for this entry
	TTLExpire *time.Time // nil when the entry has no TTL
	// ContentType is nil for all four supported backends today; it is carried
	// through so it starts working for free if contrib begins populating it.
	ContentType string
}

Record is one state entry with the metadata the four supported backends actually expose. There is deliberately no created/modified timestamp: components-contrib never surfaces one, even for the SQL backends whose tables physically store it (see the design spec).

type RecordReader added in v0.0.18

type RecordReader interface {
	Records(ctx context.Context, keys []string) ([]Record, error)
}

RecordReader is the metadata-preserving bulk read path. ccStore implements it; consumers type-assert for it rather than it being part of Store, mirroring how ccStore.Keys asserts for state.KeysLiker.

type SecretRef

type SecretRef struct {
	// Kind is "secretKeyRef" or "envRef", mirroring secrets.Ref.Kind. The zero
	// value ("") is treated as "secretKeyRef" by every consumer, so existing
	// literals built before envRef support was added keep working unchanged.
	Kind string
	Name string // secretKeyRef.name, or the env var name for envRef
	Key  string // secretKeyRef.key (the key within that secret); unused for envRef
}

SecretRef is a Dapr secretKeyRef or envRef metadata reference.

type Store

type Store interface {
	// Keys lists keys matching a LIKE pattern, with opaque cursor paging.
	Keys(ctx context.Context, pattern string, token string, pageSize int) (keys []string, next string, err error)
	Get(ctx context.Context, key string) ([]byte, error)
	BulkGet(ctx context.Context, keys []string) (map[string][]byte, error)
	Delete(ctx context.Context, key string) error
	// Set upserts a raw byte value at key. Used by integration tests to seed state.
	Set(ctx context.Context, key string, value []byte) error
	Close() error
}

Store is the read + write + delete surface the workflow service needs.

func New

func New(ctx context.Context, c Component) (Store, error)

New builds and initialises a components-contrib state store from a component spec. Supports state.redis, state.sqlite, state.postgresql / state.postgres, and state.mongodb. Returns ErrUnsupported for any other type.

Jump to

Keyboard shortcuts

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