Documentation
¶
Overview ¶
Package replicas is how code anywhere in Studio (core or Enterprise) cooperates with the other control-plane replicas sharing its database, without being handed the cluster machinery:
- IsLeader: whether this replica should run singleton background work (aggregations, alerts, syncs, reports, cleanups). One replica holds the leader lease at a time (pkg/cluster.Leadership).
- OnLeading: run something when this replica becomes the leader, such as start-up work that was skipped because another replica (or this one's dead predecessor) still held the lease.
- Signal / OnSignal: tell every other replica that some in-memory state derived from the database is stale ("budgets", "governed_metadata", ...). The replica that changed the data refreshes its own state itself; the signal reaches the others through the cluster event log, at least once, within about a second.
Studio runs one instance per process, so this is process-wide. Until pkg/studio connects a backend (and in tests), this process is the only replica: IsLeader is true and signals go nowhere.
Index ¶
Constants ¶
const ( // SignalBudgets: budget limits, periods or the team-budget switch // changed; every replica clears its budget caches. SignalBudgets = "budgets" // SignalGovernedMetadata: metadata schemas or vocabularies changed; // every replica drops its resolved-schema cache (Enterprise). SignalGovernedMetadata = "governed_metadata" )
Signal names shared across packages.
Variables ¶
This section is empty.
Functions ¶
func BecameLeader ¶
func BecameLeader()
BecameLeader runs the OnLeading handlers (called by the backend when this replica gains the leader lease).
func Deliver ¶
func Deliver(name string)
Deliver runs the handlers for a signal received from another replica (called by the backend).
func IsLeader ¶
func IsLeader() bool
IsLeader reports whether this replica runs singleton background work.
func OnLeading ¶
func OnLeading(fn func()) (remove func())
OnLeading registers fn to run each time this replica becomes the leader. Leader-only work that checks IsLeader on a timer uses it to catch up at once instead of waiting a whole interval: a replica restarted after a crash may only get the lease a moment after its start-up run was skipped. Register before checking IsLeader, so no change falls between the two. fn runs on the lease's goroutine: it must be quick (wake a loop). The returned function removes it.
func OnSignal ¶
func OnSignal(name string, fn func()) (remove func())
OnSignal registers fn to run when another replica signals name. fn runs on the cluster log's reader goroutine: it must be quick (clear a cache, trigger a background reload). The returned function removes it.