Documentation
¶
Overview ¶
Package owner manages lease-based ownership of the local runtime's resident state. On Join, one instance becomes the owner — it holds the lease and renews it in the background — while others become followers that know who the owner is and (later) where to reach it.
The owner self-fences: if it cannot renew before the lease expires, Lost() fires and the caller MUST stop touching owned state, because another instance may have taken over. This is the in-process, no-daemon, cross-platform owner election described in docs/blueprints/local-runtime-owner-coordination.md.
Index ¶
Constants ¶
const EndpointMetaKey = "endpoint"
EndpointMetaKey is the lease metadata key used to advertise the owner's transport endpoint.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// LeasePath is the lease file; one owner per path (per user + data root).
LeasePath string
// TTL is the lease duration.
TTL time.Duration
// RenewInterval is how often the owner renews; defaults to TTL/3.
RenewInterval time.Duration
// Endpoint, if set, is advertised to followers via the lease record so they
// can reach the owner once it serves a transport (P3). Empty = not serving.
Endpoint string
}
Config controls a Join.
type Owner ¶
type Owner struct {
// contains filtered or unexported fields
}
Owner is the result of a Join: either this instance (RoleOwner) with a running renew loop, or a handle describing the current owner (RoleFollower).
func Join ¶
Join attempts to acquire ownership of the lease at cfg.LeasePath. If the lease is free it returns an Owner in RoleOwner and starts renewing in the background; if a live owner already holds it, it returns RoleFollower with the current holder. ctx bounds the renew loop's lifetime; cancelling it stops renewal (call Release for a clean handover).
func (*Owner) InstanceID ¶
InstanceID is this owner's id, or the current owner's id for a follower.
func (*Owner) Lost ¶
func (o *Owner) Lost() <-chan struct{}
Lost is closed when the owner can no longer renew the lease (taken over or an I/O failure). The caller must stop touching owned state when it fires. It never fires for a follower.