Documentation
¶
Overview ¶
Package leasekeeper keeps a Runtime Protocol lease alive while a worker executes a workload, and stops the execution when the lease can no longer be renewed.
Without periodic renewal, a workload running longer than the lease TTL (e.g. a sandboxed container or a slow tool script) lets the lease expire: the recovery controller fences the run and starts a replacement attempt while the original worker is still executing side effects — a fencing split-brain. The keeper renews the lease at TTL/3 intervals with the CAS lease version from each response, so the renewal chain never goes stale, and it cancels the execution context as soon as renewal fails (fence broken) or the kernel requests cancellation (acknowledged once, so the kernel can finalize it).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper renews the lease on a background goroutine. The execution context returned by Start is cancelled when the lease cannot be renewed or when the kernel requests cancellation; workers must treat a cancelled execution context as "stop now".
func Start ¶
func Start(parent context.Context, opts Options, initialLeaseVersion, initialAttemptVersion int64) (*Keeper, context.Context)
Start begins renewing the lease and returns the keeper plus the execution context derived from parent. initialLeaseVersion is the lease resource version the worker most recently observed (e.g. from its pre-execution heartbeat); the keeper CAS-chains every renewal on the version each heartbeat returns.
func (*Keeper) Cancelled ¶
Cancelled reports whether the kernel requested cancellation while the keeper was running (the cancellation was acknowledged).
func (*Keeper) FenceError ¶
FenceError reports why the lease could not be renewed, if it failed.
type Options ¶
type Options struct {
// Client is the fenced Runtime Protocol client.
Client runtimev1.RuntimeControlServiceClient
// Identity is the fenced AttemptIdentity of the assignment.
Identity *runtimev1.AttemptIdentity
// AttemptID is the attempt ID string used to derive idempotency keys.
AttemptID string
// HeartbeatTTL is the lease TTL the worker requests on every renewal.
HeartbeatTTL time.Duration
// RPCTimeout bounds each individual renewal RPC.
RPCTimeout time.Duration
}
Options configures one keeper run.