Documentation
¶
Overview ¶
Package coord coordinates dockhand processes that share one database (docs/design-v3.md §11): sessions, fenced leases, one serve leader with standbys, and the event journal observers tail.
Every process that runs or watches work opens a Session. A session's death is known directly, since every process is on one Mac: a PID that no longer exists, or that names a process started at another time, is a dead session at once. A heartbeat covers a process that is alive but hung. It is judged only by a coordinator that has itself been awake, so a laptop waking from sleep does not declare every peer dead.
A lease on a resource names its session and a generation. Taking a lease from a dead holder raises the generation, and every write made under a lease checks it first, so a holder that was paused and resumes cannot write on a claim it lost. External calls it makes after resuming are guarded by the providers' idempotency and reconciliation, not by leases.
Index ¶
- Constants
- Variables
- type Coordinator
- type HeldError
- type Liveness
- type Process
- type Session
- func (s *Session) Acquire(ctx context.Context, resource string) (model.Lease, error)
- func (s *Session) AcquireIn(tx store.Tx, resource string) (model.Lease, error)
- func (s *Session) Beat(ctx context.Context) error
- func (s *Session) Emit(tx store.Tx, event model.Event) (int64, error)
- func (s *Session) End(ctx context.Context) error
- func (s *Session) Fenced(ctx context.Context, lease model.Lease, fn func(store.Tx) error) error
- func (s *Session) Holder(ctx context.Context, resource string) (*model.Session, error)
- func (s *Session) Holders(r store.Reader, resources ...string) (map[string]*model.Session, error)
- func (s *Session) ID() model.SessionID
- func (s *Session) Judge(other model.Session) (Verdict, error)
- func (s *Session) KeepAlive(ctx context.Context)
- func (s *Session) Lead(ctx context.Context) (model.Lease, error)
- func (s *Session) Record() model.Session
- func (s *Session) Release(ctx context.Context, lease model.Lease) error
- func (s *Session) TakeIfUnattended(ctx context.Context, resource string) (lease model.Lease, holder *model.Session, err error)
- type System
- type Verdict
Constants ¶
const DefaultHeartbeat = 5 * time.Second
DefaultHeartbeat is how often a session records that it is alive, which the store's migration guard watches for, to tell a process working on the database from one working on the original of a copy.
const DefaultHungAfter = 2 * time.Minute
DefaultHungAfter is how long a live process may go without a heartbeat before another dockhand may take over its work, and so how recent a heartbeat says a process is working: the one window, which the store's migration guard takes (the architecture review of 5897a82, R3-19).
const LeaderResource = "leader"
LeaderResource is the lease a repository's leading serve holds.
Variables ¶
var ErrHeld = errors.New("held by another session")
ErrHeld reports a lease another live session holds.
Functions ¶
This section is empty.
Types ¶
type Coordinator ¶
type Coordinator struct {
Store store.Store
Repository model.RepositoryID
// Liveness defaults to what the operating system reports.
Liveness Liveness
// Now defaults to time.Now.
Now func() time.Time
// Heartbeat is how often a session records that it is alive;
// DefaultHeartbeat when zero.
Heartbeat time.Duration
// HungAfter is how long a live process may go without a heartbeat
// before its leases may be taken; two minutes by default.
HungAfter time.Duration
}
Coordinator binds coordination to one repository in one store.
func (*Coordinator) Start ¶
func (c *Coordinator) Start(ctx context.Context, kind model.SessionKind, version string) (*Session, error)
Start opens a session for the running process.
type Liveness ¶
Process, Liveness, Self, and System are procid's: a process by its PID and start time, which a provider's prefix ownership records too.
type Process ¶
Process, Liveness, Self, and System are procid's: a process by its PID and start time, which a provider's prefix ownership records too.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is this process's session.
func (*Session) Acquire ¶
Acquire takes the lease on a resource, from its holder when that holder is dead, and refuses with a HeldError when a live session holds it.
func (*Session) AcquireIn ¶ added in v0.8.0
AcquireIn is Acquire in the caller's transaction, so taking a lease and what decides it are one: a check's slot (the engine's reserve).
func (*Session) Emit ¶
Emit appends an event from this session within a transaction, stamping its session and time.
func (*Session) End ¶
End closes the session cleanly. Leases it still holds become free to take, since an ended session is dead to every judge.
It stops the heartbeat whichever started first, and returns only once a running one has returned, so the caller may close the store after it (#252).
func (*Session) Fenced ¶
Fenced runs fn in a write transaction only while the lease is still current; a lost lease returns store.ErrStale and writes nothing.
func (*Session) Holder ¶
Holder reports the live session holding a resource, without taking it: nil when no one holds it, or its holder is dead.
func (*Session) Holders ¶ added in v0.4.0
Holders are the live sessions holding resources, read in the caller's transaction, so a list of runs and their holders is one consistent read rather than a View each (SQL-O4); a resource no live session holds has no entry. The liveness judgment is Judge's, as Holder's.
func (*Session) Judge ¶
Judge decides whether another session is dead: ended, its process gone or replaced, or, when this session is awake to see it, silent for longer than HungAfter.
func (*Session) KeepAlive ¶
KeepAlive beats until ctx is done. A beat that fails is tried again at the next, rather than ending the heartbeat: one write that waited past the store's timeouts once stopped it for good, and two minutes later another session could judge this process hung and take its leases, serve's lead among them (the limits sweep, 2026-10-01). A run of failures is said once, as is the beat that ends it. It ends with the session: bump's check ended its session while the process went on to submit, and the next beat, refused for an ended session, was said as a heartbeat lost (field testing, 2026-10-02).
func (*Session) Lead ¶
Lead takes the repository's leadership, or reports the live leader it stands by for.
func (*Session) TakeIfUnattended ¶
func (s *Session) TakeIfUnattended(ctx context.Context, resource string) (lease model.Lease, holder *model.Session, err error)
TakeIfUnattended takes a resource's lease only when no live session holds it, reporting who does otherwise. This is how a control is applied by whoever can: a cancel whose run has a live holder is left to that holder, and one whose holder is dead is applied by the canceller.