Documentation
¶
Overview ¶
Package state holds the full replicated cluster state in memory (ADR-0004).
The Store is the Raft FSM's state: plain maps of proto messages keyed by ULID, a handful of secondary indexes on hot paths, one RWMutex, and a watch hub that lets control loops (scheduler, route builder, cert manager) react to changes.
Rules:
- Mutating methods are called ONLY from FSM apply handlers (internal/daemon/raftstore). Everything else reads.
- Read methods return deep clones; callers may mutate results freely.
- Collections are small (thousands of objects): list methods do linear scans with filters unless a path is genuinely hot. Hot-path indexes: tokens by hash, users by email, domains by hostname, assignments by node. Do not add more indexes without a measured need.
Index ¶
- Variables
- type Change
- type Hub
- type Kind
- type Store
- func (s *Store) App(id string) (*zatterav1.App, bool)
- func (s *Store) AppByName(projectID, name string) (*zatterav1.App, bool)
- func (s *Store) AppendAudit(entries []*zatterav1.AuditEntry)
- func (s *Store) AppendEvents(events []*zatterav1.Event)
- func (s *Store) Assignment(id string) (*zatterav1.Assignment, bool)
- func (s *Store) AuditSince(sinceMs int64) []*zatterav1.AuditEntry
- func (s *Store) BackupConfig() (*zatterav1.BackupConfig, bool)
- func (s *Store) Build(id string) (*zatterav1.Build, bool)
- func (s *Store) ClusterKeyMaterial() (*zatterav1.ClusterKeyMaterial, bool)
- func (s *Store) ClusterVersionRange() (min, max string, anyUnknown bool)
- func (s *Store) DeleteAlertRule(id string)
- func (s *Store) DeleteApp(id string)
- func (s *Store) DeleteAssignments(ids []string)
- func (s *Store) DeleteDNSProvider(id string)
- func (s *Store) DeleteDomain(id string)
- func (s *Store) DeleteEnvironment(id string)
- func (s *Store) DeleteKV(key string, expectedVersion int64) error
- func (s *Store) DeleteNode(id string)
- func (s *Store) DeleteNotificationChannel(id string)
- func (s *Store) DeleteProject(id string)
- func (s *Store) DeleteProjectMember(projectID, userID string)
- func (s *Store) DeleteRelease(id string)
- func (s *Store) DeleteToken(id string)
- func (s *Store) DeleteUser(id string)
- func (s *Store) DeleteVolume(id string)
- func (s *Store) DeleteVolumeSnapshot(id string)
- func (s *Store) Deployment(id string) (*zatterav1.Deployment, bool)
- func (s *Store) Domain(id string) (*zatterav1.Domain, bool)
- func (s *Store) DomainByHostname(hostname string) (*zatterav1.Domain, bool)
- func (s *Store) DomainByRoute(hostname, pathPrefix string) (*zatterav1.Domain, bool)
- func (s *Store) DomainsByHostname(hostname string) []*zatterav1.Domain
- func (s *Store) EnvVars(envID string) map[string]*zatterav1.EncryptedValue
- func (s *Store) Environment(id string) (*zatterav1.Environment, bool)
- func (s *Store) EnvironmentByName(appID, name string) (*zatterav1.Environment, bool)
- func (s *Store) EventsSince(sinceMs int64) []*zatterav1.Event
- func (s *Store) Job(id string) (*zatterav1.Job, bool)
- func (s *Store) KV(key string) (value []byte, version int64, expiresAtUnixMs int64, ok bool)
- func (s *Store) ListAlertRules() []*zatterav1.AlertRule
- func (s *Store) ListApps(projectID string) []*zatterav1.App
- func (s *Store) ListAssignments(envID string) []*zatterav1.Assignment
- func (s *Store) ListAssignmentsByNode(nodeID string) []*zatterav1.Assignment
- func (s *Store) ListBackupRecords() []*zatterav1.BackupRecord
- func (s *Store) ListBuilds(appID string) []*zatterav1.Build
- func (s *Store) ListDNSProviders() []*zatterav1.DNSProviderConfig
- func (s *Store) ListDeployments(envID string) []*zatterav1.Deployment
- func (s *Store) ListDomains(projectID string) []*zatterav1.Domain
- func (s *Store) ListEnvironments(projectID, appID string) []*zatterav1.Environment
- func (s *Store) ListEvents(limit int) []*zatterav1.Event
- func (s *Store) ListJobs(projectID, envID string) []*zatterav1.Job
- func (s *Store) ListJoinTokens() []*zatterav1.JoinToken
- func (s *Store) ListKVPrefix(prefix string) []string
- func (s *Store) ListMembershipsOfUser(userID string) []*zatterav1.ProjectMember
- func (s *Store) ListNetworkAllocations() []*internalv1.NetworkAllocation
- func (s *Store) ListNodes() []*zatterav1.Node
- func (s *Store) ListNotificationChannels() []*zatterav1.NotificationChannel
- func (s *Store) ListProjectMembers(projectID string) []*zatterav1.ProjectMember
- func (s *Store) ListProjects() []*zatterav1.Project
- func (s *Store) ListReleases(envID string) []*zatterav1.Release
- func (s *Store) ListServiceVIPs() map[string]string
- func (s *Store) ListTokens(userID string) []*zatterav1.Token
- func (s *Store) ListUsers() []*zatterav1.User
- func (s *Store) ListVolumeSnapshots(volumeID string) []*zatterav1.VolumeSnapshot
- func (s *Store) ListVolumes(projectID string) []*zatterav1.Volume
- func (s *Store) MarkApplied(requestID string, raftIndex uint64) bool
- func (s *Store) NetworkAllocation(projectID, envID, nodeID string) (string, bool)
- func (s *Store) NextReleaseVersion(envID string) uint64
- func (s *Store) Node(id string) (*zatterav1.Node, bool)
- func (s *Store) Org() (*zatterav1.Org, bool)
- func (s *Store) Project(id string) (*zatterav1.Project, bool)
- func (s *Store) ProjectByName(name string) (*zatterav1.Project, bool)
- func (s *Store) ProjectMember(projectID, userID string) (*zatterav1.ProjectMember, bool)
- func (s *Store) PutAlertRule(r *zatterav1.AlertRule)
- func (s *Store) PutApp(a *zatterav1.App)
- func (s *Store) PutAssignment(a *zatterav1.Assignment)
- func (s *Store) PutAssignments(as []*zatterav1.Assignment)
- func (s *Store) PutBackupRecord(r *zatterav1.BackupRecord)
- func (s *Store) PutBuild(b *zatterav1.Build)
- func (s *Store) PutDNSProvider(p *zatterav1.DNSProviderConfig)
- func (s *Store) PutDeployment(d *zatterav1.Deployment)
- func (s *Store) PutDomain(d *zatterav1.Domain)
- func (s *Store) PutEnvironment(e *zatterav1.Environment)
- func (s *Store) PutJob(j *zatterav1.Job)
- func (s *Store) PutJoinToken(t *zatterav1.JoinToken)
- func (s *Store) PutKV(key string, value []byte, expectedVersion int64, expiresAtUnixMs int64) (int64, error)
- func (s *Store) PutNode(n *zatterav1.Node)
- func (s *Store) PutNotificationChannel(c *zatterav1.NotificationChannel)
- func (s *Store) PutProject(p *zatterav1.Project)
- func (s *Store) PutProjectMember(m *zatterav1.ProjectMember)
- func (s *Store) PutRelease(r *zatterav1.Release)
- func (s *Store) PutToken(t *zatterav1.Token)
- func (s *Store) PutUser(u *zatterav1.User)
- func (s *Store) PutVolume(v *zatterav1.Volume)
- func (s *Store) PutVolumeSnapshot(snap *zatterav1.VolumeSnapshot)
- func (s *Store) QueryAudit(filter func(*zatterav1.AuditEntry) bool, limit int) []*zatterav1.AuditEntry
- func (s *Store) QueryEvents(filter func(*zatterav1.Event) bool, limit int) []*zatterav1.Event
- func (s *Store) Release(id string) (*zatterav1.Release, bool)
- func (s *Store) RestoreProto(snap *internalv1.Snapshot)
- func (s *Store) ServiceVIP(envID string) (string, bool)
- func (s *Store) SetAssignmentObserved(nodeID string, observed map[string]*zatterav1.AssignmentObserved)
- func (s *Store) SetBackupConfig(c *zatterav1.BackupConfig)
- func (s *Store) SetClusterKeyMaterial(m *zatterav1.ClusterKeyMaterial)
- func (s *Store) SetEnvVars(envID string, set map[string]*zatterav1.EncryptedValue, unset []string)
- func (s *Store) SetNetworkAllocation(projectID, envID, nodeID, subnetCIDR string)
- func (s *Store) SetOrg(o *zatterav1.Org)
- func (s *Store) SetServiceVIP(envID, vip string)
- func (s *Store) SetVolumeLease(volumeID string, lease *zatterav1.VolumeLease)
- func (s *Store) SnapshotProto(fsmIndex uint64) *internalv1.Snapshot
- func (s *Store) Token(id string) (*zatterav1.Token, bool)
- func (s *Store) TokenByHash(hash string) (*zatterav1.Token, bool)
- func (s *Store) TouchTokens(lastUsed map[string]int64)
- func (s *Store) User(id string) (*zatterav1.User, bool)
- func (s *Store) UserByEmail(email string) (*zatterav1.User, bool)
- func (s *Store) Version() uint64
- func (s *Store) Volume(id string) (*zatterav1.Volume, bool)
- func (s *Store) VolumeByName(projectID, envID, name string) (*zatterav1.Volume, bool)
- func (s *Store) Watch(kinds ...Kind) *Subscription
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ErrKVConflict = fmt.Errorf("state: kv version conflict")
ErrKVConflict is returned when a CAS expectation fails.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub fans out change notifications to subscribers without ever blocking the FSM apply path. Changes are coalesced per subscriber (a set keyed by Kind+ID); the subscriber gets a level-triggered signal and drains the pending set when it is ready. Slow subscribers lose granularity, never correctness — control loops re-read state anyway.
type Kind ¶
type Kind string
Kind identifies a resource collection for watch subscriptions.
const ( KindOrg Kind = "org" KindUser Kind = "user" KindProject Kind = "project" KindProjectMember Kind = "project_member" KindApp Kind = "app" KindEnvironment Kind = "environment" KindEnvVar Kind = "env_var" KindRelease Kind = "release" KindDeployment Kind = "deployment" KindBuild Kind = "build" KindNode Kind = "node" KindJoinToken Kind = "join_token" KindAssignment Kind = "assignment" KindToken Kind = "token" KindDomain Kind = "domain" KindKV Kind = "kv" KindDNSProvider Kind = "dns_provider" KindVolume Kind = "volume" KindVolumeSnapshot Kind = "volume_snapshot" KindBackup Kind = "backup" KindNetworkAlloc Kind = "network_alloc" KindServiceVIP Kind = "service_vip" KindJob Kind = "job" KindAlertRule Kind = "alert_rule" KindNotifyChannel Kind = "notify_channel" KindEvent Kind = "event" KindClusterKey Kind = "cluster_key" )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the in-memory cluster state. Zero value is not usable; call New.
func (*Store) AppendAudit ¶
func (s *Store) AppendAudit(entries []*zatterav1.AuditEntry)
func (*Store) AppendEvents ¶
func (*Store) Assignment ¶
func (s *Store) Assignment(id string) (*zatterav1.Assignment, bool)
func (*Store) AuditSince ¶
func (s *Store) AuditSince(sinceMs int64) []*zatterav1.AuditEntry
AuditSince returns every audit entry created at or after sinceMs, in append order (oldest first). The archiver walks the ring forward from its cursor with this; unlike QueryAudit it is uncapped, because skipping entries would silently lose them from the archive.
func (*Store) BackupConfig ¶
func (s *Store) BackupConfig() (*zatterav1.BackupConfig, bool)
func (*Store) ClusterKeyMaterial ¶
func (s *Store) ClusterKeyMaterial() (*zatterav1.ClusterKeyMaterial, bool)
func (*Store) ClusterVersionRange ¶
ClusterVersionRange returns the oldest and newest comparable binary versions across all nodes, and whether any node's version could not be parsed (T-93). The minimum gates upgrade ordering and version-skew warnings; an unknown version is reported rather than silently treated as old.
func (*Store) DeleteAlertRule ¶
func (*Store) DeleteAssignments ¶
func (*Store) DeleteDNSProvider ¶
func (*Store) DeleteDomain ¶
func (*Store) DeleteEnvironment ¶
func (*Store) DeleteNode ¶
func (*Store) DeleteNotificationChannel ¶
func (*Store) DeleteProject ¶
func (*Store) DeleteProjectMember ¶
func (*Store) DeleteRelease ¶
DeleteRelease removes a release (retention GC, T-38).
func (*Store) DeleteToken ¶
func (*Store) DeleteUser ¶
func (*Store) DeleteVolume ¶
func (*Store) DeleteVolumeSnapshot ¶
func (*Store) Deployment ¶
func (s *Store) Deployment(id string) (*zatterav1.Deployment, bool)
func (*Store) DomainByHostname ¶
DomainByHostname returns ONE domain for a hostname — enough for the ACME on-demand policy ("may this host get a certificate?"), which is per-hostname and indifferent to which path route asked. When a hostname carries several path routes the choice among them is arbitrary, so anything that cares about the specific route must use DomainsByHostname or DomainByRoute (T-104).
func (*Store) DomainByRoute ¶
DomainByRoute looks up the exact (hostname, path prefix) pair — the identity of a route, and what uniqueness is enforced on.
func (*Store) DomainsByHostname ¶
DomainsByHostname returns every domain registered for a hostname, ordered by path prefix (longest first) so callers see the most specific route first.
func (*Store) Environment ¶
func (s *Store) Environment(id string) (*zatterav1.Environment, bool)
func (*Store) EnvironmentByName ¶
func (s *Store) EnvironmentByName(appID, name string) (*zatterav1.Environment, bool)
func (*Store) EventsSince ¶
EventsSince is AuditSince for the event ring.
func (*Store) ListAlertRules ¶
func (*Store) ListAssignments ¶
func (s *Store) ListAssignments(envID string) []*zatterav1.Assignment
ListAssignments filters by environment (or everything when empty).
func (*Store) ListAssignmentsByNode ¶
func (s *Store) ListAssignmentsByNode(nodeID string) []*zatterav1.Assignment
func (*Store) ListBackupRecords ¶
func (s *Store) ListBackupRecords() []*zatterav1.BackupRecord
func (*Store) ListDNSProviders ¶
func (s *Store) ListDNSProviders() []*zatterav1.DNSProviderConfig
func (*Store) ListDeployments ¶
func (s *Store) ListDeployments(envID string) []*zatterav1.Deployment
func (*Store) ListEnvironments ¶
func (s *Store) ListEnvironments(projectID, appID string) []*zatterav1.Environment
ListEnvironments filters by app (or project when appID == "" and projectID != ""); both empty lists everything.
func (*Store) ListJoinTokens ¶
func (*Store) ListKVPrefix ¶
func (*Store) ListMembershipsOfUser ¶
func (s *Store) ListMembershipsOfUser(userID string) []*zatterav1.ProjectMember
ListMembershipsOfUser returns all project memberships of one user.
func (*Store) ListNetworkAllocations ¶
func (s *Store) ListNetworkAllocations() []*internalv1.NetworkAllocation
func (*Store) ListNotificationChannels ¶
func (s *Store) ListNotificationChannels() []*zatterav1.NotificationChannel
func (*Store) ListProjectMembers ¶
func (s *Store) ListProjectMembers(projectID string) []*zatterav1.ProjectMember
func (*Store) ListProjects ¶
func (*Store) ListReleases ¶
ListReleases returns an environment's releases sorted by version descending.
func (*Store) ListServiceVIPs ¶
func (*Store) ListVolumeSnapshots ¶
func (s *Store) ListVolumeSnapshots(volumeID string) []*zatterav1.VolumeSnapshot
func (*Store) MarkApplied ¶
MarkApplied records a request id; returns false if it was already applied.
func (*Store) NetworkAllocation ¶
func (*Store) NextReleaseVersion ¶
NextReleaseVersion returns 1 + the highest release version of the env.
func (*Store) ProjectByName ¶
ProjectByName resolves a project by its unique name.
func (*Store) ProjectMember ¶
func (s *Store) ProjectMember(projectID, userID string) (*zatterav1.ProjectMember, bool)
func (*Store) PutAlertRule ¶
func (*Store) PutAssignment ¶
func (s *Store) PutAssignment(a *zatterav1.Assignment)
func (*Store) PutAssignments ¶
func (s *Store) PutAssignments(as []*zatterav1.Assignment)
PutAssignments applies a batch in one lock acquisition.
func (*Store) PutBackupRecord ¶
func (s *Store) PutBackupRecord(r *zatterav1.BackupRecord)
func (*Store) PutDNSProvider ¶
func (s *Store) PutDNSProvider(p *zatterav1.DNSProviderConfig)
func (*Store) PutDeployment ¶
func (s *Store) PutDeployment(d *zatterav1.Deployment)
func (*Store) PutEnvironment ¶
func (s *Store) PutEnvironment(e *zatterav1.Environment)
func (*Store) PutJoinToken ¶
func (*Store) PutKV ¶
func (s *Store) PutKV(key string, value []byte, expectedVersion int64, expiresAtUnixMs int64) (int64, error)
PutKV stores a key. expectedVersion: -1 unconditional, 0 requires absent, >0 requires the current version to match. Returns the new version.
func (*Store) PutNotificationChannel ¶
func (s *Store) PutNotificationChannel(c *zatterav1.NotificationChannel)
func (*Store) PutProject ¶
func (*Store) PutProjectMember ¶
func (s *Store) PutProjectMember(m *zatterav1.ProjectMember)
func (*Store) PutRelease ¶
func (*Store) PutVolumeSnapshot ¶
func (s *Store) PutVolumeSnapshot(snap *zatterav1.VolumeSnapshot)
func (*Store) QueryAudit ¶
func (s *Store) QueryAudit(filter func(*zatterav1.AuditEntry) bool, limit int) []*zatterav1.AuditEntry
QueryAudit returns the newest entries matching the filter, newest first.
func (*Store) QueryEvents ¶
QueryEvents returns the newest events matching the filter, newest first — the same ordering contract as QueryAudit, so the two read consistently. (ListEvents keeps its append-order tail for the alert engine, which replays events chronologically.)
func (*Store) RestoreProto ¶
func (s *Store) RestoreProto(snap *internalv1.Snapshot)
RestoreProto replaces the entire store content with the snapshot's. Watch subscribers receive a single wildcard notification per kind.
func (*Store) SetAssignmentObserved ¶
func (s *Store) SetAssignmentObserved(nodeID string, observed map[string]*zatterav1.AssignmentObserved)
SetAssignmentObserved merges an observed status batch for one node. Unknown assignment ids are skipped (they may have been deleted since the agent reported).
func (*Store) SetBackupConfig ¶
func (s *Store) SetBackupConfig(c *zatterav1.BackupConfig)
func (*Store) SetClusterKeyMaterial ¶
func (s *Store) SetClusterKeyMaterial(m *zatterav1.ClusterKeyMaterial)
func (*Store) SetEnvVars ¶
SetEnvVars applies a set/unset batch to an environment's variables.
func (*Store) SetNetworkAllocation ¶
func (*Store) SetServiceVIP ¶
func (*Store) SetVolumeLease ¶
func (s *Store) SetVolumeLease(volumeID string, lease *zatterav1.VolumeLease)
func (*Store) SnapshotProto ¶
func (s *Store) SnapshotProto(fsmIndex uint64) *internalv1.Snapshot
SnapshotProto serializes the entire store into a Snapshot message (ADR-0004). Called by the Raft FSM under snapshotting.
func (*Store) TokenByHash ¶
TokenByHash is the auth hot path.
func (*Store) TouchTokens ¶
TouchTokens updates last_used_at in batch (from a periodic flush).
func (*Store) VolumeByName ¶
func (*Store) Watch ¶
func (s *Store) Watch(kinds ...Kind) *Subscription
Watch subscribes to change notifications for the given kinds (all kinds if empty). See Hub for delivery semantics.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription receives coalesced change notifications.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close unsubscribes. Safe to call multiple times.
func (*Subscription) Drain ¶
func (s *Subscription) Drain() []Change
Drain returns and clears the pending change set.
func (*Subscription) Notify ¶
func (s *Subscription) Notify() <-chan struct{}
Notify returns a channel that receives a value whenever there are pending changes. It is level-triggered with capacity 1: after receiving, call Drain to collect what changed, then wait again.