Documentation
¶
Overview ¶
Package lockstep is an actor runtime for Go whose actor code runs unchanged on the local engine of New and on a seeded simulation in tests (package lockstep/sim), where a failing seed replays exactly.
The local engine runs every actor turn on one goroutine, so actors interleave but never run in parallel; effects started with Do run on separate goroutines.
Index ¶
- Constants
- Variables
- func NewReply[R any](from Sender, opts ...AskOption) (ReplyTo[R], *Reply[R])
- func Pipe[R, M any](ctx *Context[M], r *Reply[R], to func(R, error) M)
- func Send[M any](from Sender, to PID[M], msg M) error
- func SendContext[M any](ctx context.Context, from Sender, to PID[M], msg M) error
- func Stop(from Sender, addr Address) error
- func Unwatch[M any](ctx *Context[M], addr Address)
- func Watch[M any](ctx *Context[M], addr Address) error
- type Actor
- type ActorEstimate
- type Address
- type AskOption
- type ChildFailed
- type Context
- func (c *Context[M]) After(d time.Duration, msg M) TimerID
- func (c *Context[M]) CancelEffect(id EffectID) bool
- func (c *Context[M]) CancelTimer(id TimerID) bool
- func (c *Context[M]) Every(d time.Duration, msg M) TimerID
- func (c *Context[M]) Fail(err error)
- func (c *Context[M]) Logf(format string, args ...any)
- func (c *Context[M]) Now() time.Time
- func (c *Context[M]) Own(r io.Closer)
- func (c *Context[M]) Parent() Address
- func (c *Context[M]) Rand() *rand.Rand
- func (c *Context[M]) Self() PID[M]
- func (c *Context[M]) Stop()
- func (c *Context[M]) SubscribeOverload()
- func (c *Context[M]) UnsubscribeOverload()
- type Directive
- type Effect
- type EffectID
- type EffectOption
- type MailboxPolicy
- type MemSizer
- type Option
- func WithAdmission(high, low uint64) Option
- func WithDefaultMailbox(capacity int, policy MailboxPolicy) Option
- func WithGoroutineWarning(bound int) Option
- func WithGuardianStrategy(s Strategy) Option
- func WithMaxActors(n int) Option
- func WithMemoryEstimates() Option
- func WithNodeName(name string) Option
- func WithWatchdog(d time.Duration) Option
- type OverloadReason
- type Overloaded
- type PID
- type PanicError
- type Reply
- type ReplyTo
- type Sender
- type Signal
- type SignalReceiver
- type Sizer
- type SpawnOption
- type Spawner
- type Starter
- type StopKind
- type StopReason
- type Stopper
- type Strategy
- type System
- type Terminated
- type TimerID
Constants ¶
const DefaultEffectTimeout = 30 * time.Second
DefaultEffectTimeout is the timeout of an effect started without WithEffectTimeout.
const DefaultGoroutineWarning = 10_000
DefaultGoroutineWarning is the goroutine count above which a production System logs a warning.
const DefaultMaxActors = 1_000_000
DefaultMaxActors is the actor cap of a System built without WithMaxActors.
const DefaultWatchdogTimeout = 5 * time.Second
DefaultWatchdogTimeout is the stuck-turn timeout of a production System without WithWatchdog.
Variables ¶
var ( ErrStopped = errors.New("lockstep: stopped") ErrNameTaken = errors.New("lockstep: name taken") ErrWrongType = errors.New("lockstep: wrong message type") ErrNotFound = errors.New("lockstep: not found") ErrInvalidOption = errors.New("lockstep: invalid option") ErrInvalidName = errors.New("lockstep: invalid name") ErrNotLocal = errors.New("lockstep: address not local") )
Errors of package lockstep (ACT §4, §7).
var ( ErrTimeout = errors.New("lockstep: timeout") ErrTerminated = errors.New("lockstep: actor terminated") ErrAwaitInActor = errors.New("lockstep: blocking wait inside an actor") )
Errors of sending and asking (MSG §4.1, §7).
var ( Normal = StopReason{Kind: StopNormal} ParentStopping = StopReason{Kind: StopParentStopping} Shutdown = StopReason{Kind: StopShutdown} // NoActor is the reason of a Terminated for an address that was not alive when it was watched // (Erlang's noproc). It never reaches Stopped. NoActor = StopReason{Kind: StopNoActor} )
var ErrActorCap = errors.New("lockstep: actor cap reached")
ErrActorCap is the sentinel of architecture §22.1, repeated for its text. ErrOverloaded, its companion, is declared with the engine's errors (ENG-120).
var ErrMailboxFull = errors.New("lockstep: mailbox full")
ErrMailboxFull is the error of a message that a full mailbox refuses (MBX-090). A refusal returns fmt.Errorf("%w: %s", ErrMailboxFull, address), so errors.Is matches it and the text names the target.
var ErrNoEffectHandler = errors.New("lockstep: no effect handler")
ErrNoEffectHandler is the error that fails a simulation seed when an actor starts an effect and the simulation has no handler for the effect's name. The failure wraps it, so errors.Is(err, ErrNoEffectHandler) holds, and its text names the effect and the actor.
var ErrOverloaded = engine.ErrOverloaded
ErrOverloaded is returned when an engine refuses work. It is the same value as engine.ErrOverloaded, so errors.Is(err, ErrOverloaded) holds for errors from any engine (ENG-120).
Functions ¶
func NewReply ¶
NewReply creates an ask without a target: a pending reply on from's system with Ask's timeout and exactly-once resolution, and the ReplyTo that answers it. The caller builds and sends the request itself with Send (cluster.Ask does, VAC). An error from that Send (for example ErrMailboxFull) does not resolve the reply; the caller resolves it, for example with rt.Fail(from, err), as cluster.Ask does. A request that a DropNewest or DropOldest mailbox drops is not reported, so the reply resolves at its timeout (MSG-390). An invalid option value returns the zero ReplyTo and a reply resolved with an error wrapping ErrInvalidOption. NewReply panics if from is nil, an option is nil, or from is a Context outside its turn.
func Pipe ¶
Pipe delivers the resolution of r to the actor of ctx as one of its own messages: when r resolves, to(value, err) is called during a turn of the same incarnation and its result is passed to Receive in that turn. If the incarnation has ended by then, nothing is delivered. Pipe panics if ctx, r or to is nil, if ctx is outside its turn, or if r was created on another system.
func Send ¶
Send delivers msg to the actor to. It returns nil when msg was enqueued, became a dead letter, or was accepted by the transport for another node. Errors: ErrNotFound for the zero PID, ErrStopped when the sender's system is stopped, the target mailbox's policy error (ErrMailboxFull, MBX), the admission error (ErrOverloaded, OVL), and a synchronous transport error, wrapped (MSG-110). Send panics if from is nil or is a Context outside its turn.
func SendContext ¶
SendContext is Send, except that when from is a *System, the target's policy is BlockSender and the message cannot be enqueued yet, it waits until the message is enqueued or ctx ends, and then returns ctx.Err(). Called from an actor's turn it never waits: BlockSender acts as FailSend. Send with a *System sender is SendContext with context.Background().
func Stop ¶
Stop asks the actor at addr to stop with reason Normal and returns without waiting. A parent may stop its child this way; any Sender may stop any local actor. A path address stops the actor registered at its path. Errors: ErrNotFound if addr is not alive or names a guardian, ErrNotLocal for another node's address in every phase (there is no remote stop). Stop panics if from is nil.
func Unwatch ¶
Unwatch cancels Watch. After it returns, the incarnation receives no Terminated for addr.
func Watch ¶
Watch asks for a Terminated signal (SUP) when the actor at addr stops for good. If addr is not alive, the signal is delivered with reason NoActor (SUP). A path address (PIDAt) watches the actor registered at its path at the time of the call. From Phase 3 an address on another node is watched through remoting (ACT-602). Errors: ErrNotFound for the zero address and guardian addresses; ErrNotLocal for another node's address in Phase 1 and 2, and from Phase 3 on a system without a transport; ErrStopped when the calling actor is stopping or restarting (inside a restart's Stopped too); a wrapped transport error (Phase 3).
Types ¶
type Actor ¶
type Actor[M any] interface { // Receive handles one user message. It runs during a turn and must not block. Receive(ctx *Context[M], msg M) }
Actor is implemented by actor values. M is the actor's message type.
type ActorEstimate ¶
ActorEstimate is the memory estimate of one live actor.
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address is the untyped address of one actor: node, path and uid. It is comparable; two addresses are equal when all three parts are equal. The zero Address names no actor.
type AskOption ¶
type AskOption func(*askConfig)
AskOption configures one Ask.
func WithTimeout ¶
WithTimeout sets the ask's timeout. The default is 5 s. It never panics: Ask and NewReply resolve the reply with an error wrapping ErrInvalidOption when d <= 0 (MSG-700).
type ChildFailed ¶
type ChildFailed struct {
Child Address
Err error
Directive Directive // the directive applied; 0 when Cleanup is true
Cleanup bool // the failure happened in Stopped; no directive was applied
}
ChildFailed reports a child's failure after the supervisor's strategy has handled it.
type Context ¶
type Context[M any] struct { // contains filtered or unexported fields }
Context is an incarnation's handle to the runtime. The runtime passes the same *Context to every turn of one incarnation and a new one to the next incarnation. Self and Parent may be called at any time; every other method panics when called outside a turn of its incarnation. Every method panics on a nil *Context.
func (*Context[M]) After ¶
After delivers msg to the actor itself once, d from now on the engine clock. A negative d is treated as 0. The timer is cancelled if the incarnation ends first. Called from Stopped it schedules nothing and returns 0.
func (*Context[M]) CancelEffect ¶
CancelEffect cancels the pending effect id of this incarnation and reports whether it was pending; done is then never called for it. It returns false for 0, for an ID of another incarnation, and for an effect that already has an outcome.
func (*Context[M]) CancelTimer ¶
CancelTimer stops timer id. It reports whether the timer was active. Once it returns, the actor receives no message from that timer, even one already in the mailbox.
func (*Context[M]) Every ¶
Every delivers msg to the actor itself every d, starting d from now, until the timer is cancelled or the incarnation ends. While a previous message of the timer is still in the mailbox, a firing delivers nothing. It panics if d <= 0. Called from Stopped it schedules nothing and returns 0.
func (*Context[M]) Fail ¶
Fail marks the actor failed with err when the current handler returns. Only the first call per handler counts. It panics if err is nil.
func (*Context[M]) Logf ¶
Logf formats a log line for this actor (ACT-130). It formats with fmt.Sprintf and records lockstep.log when the tracer is enabled. On engines whose goroutines may block (the local and production engines) it also logs the line at slog.LevelInfo through slog.Default() with the attributes node, path and uid (lowercase hex); on the simulation engine the line reaches only the trace.
func (*Context[M]) Now ¶
Now returns the engine clock: wall time in production, the node's local clock in simulation, where faultline's clock drift and jumps apply.
func (*Context[M]) Own ¶
Own registers r to be closed after the incarnation's Stopped hook returns. Resources are closed in reverse registration order. It panics if r is nil.
func (*Context[M]) Parent ¶
Parent returns the parent's address: the user guardian's for actors spawned from a System.
func (*Context[M]) Rand ¶
Rand returns the random source of the current incarnation. Every call in one incarnation returns the same *rand.Rand; a restart gets a new one. Use it only inside the actor's handlers.
func (*Context[M]) Self ¶
Self returns the actor's PID. It is the same for every incarnation of the actor.
func (*Context[M]) Stop ¶
func (c *Context[M]) Stop()
Stop stops the actor with reason Normal when the current handler returns. No further user message is processed by this incarnation.
func (*Context[M]) SubscribeOverload ¶
func (c *Context[M]) SubscribeOverload()
SubscribeOverload subscribes the current incarnation to Overloaded signals. Subscribing again has no effect. If the System is shedding, an Overloaded{Active: true} signal is queued at once.
func (*Context[M]) UnsubscribeOverload ¶
func (c *Context[M]) UnsubscribeOverload()
UnsubscribeOverload cancels the subscription of the current incarnation.
type Effect ¶
type Effect[T any] interface { // Name returns the effect's stable name: 1 to 64 characters from [A-Za-z0-9._-], starting // with a letter or a digit. Simulation finds the effect's handler by this name, and traces // show it. Names starting with "lockstep." are reserved for lockstep's built-in effects. Name() string // Run performs the operation and returns its result. The local engine (Phase 1) and the // production engine call it on one of their effect workers; simulation never calls it. Run // should return soon after ctx is done, which happens when the effect times out or is // cancelled. Run(ctx context.Context) (T, error) }
Effect is an operation that waits: a network call, file I/O, a database query, CPU work over a budget. An actor starts it with Do and gets its outcome back as a message.
type EffectID ¶
type EffectID uint64
EffectID identifies one Do call within a System. IDs start at 1 and increase by one per Do call that starts an effect. 0 means that no effect was started.
func Do ¶
func Do[T, M any](ctx *Context[M], e Effect[T], done func(T, error) M, opts ...EffectOption) EffectID
Do starts effect e for the actor of ctx and returns its ID. When the effect's outcome is delivered, a later turn of the actor calls done with the result, or with the zero T and ErrTimeout or ErrOverloaded, and passes done's return value to Receive. done runs on the actor's turn, never concurrently with Receive. If the incarnation ends or CancelEffect cancels the effect first, done is never called.
Do panics if e is nil, e.Name() is invalid, done is nil, or an option is invalid.
type EffectOption ¶
type EffectOption func(*effectConfig)
EffectOption configures one Do call.
func WithEffectTimeout ¶
func WithEffectTimeout(d time.Duration) EffectOption
WithEffectTimeout sets the effect's timeout, measured on the engine's clock from the Do call. Do panics if d is not positive.
type MailboxPolicy ¶
type MailboxPolicy uint8
MailboxPolicy selects what happens when a message is sent to a full mailbox. A mailbox is full when it holds as many sent messages as its capacity. Timer messages, piped replies and effect results are never refused and never count toward capacity.
const ( // FailSend refuses the message: Send returns an error wrapping ErrMailboxFull. The default. FailSend MailboxPolicy = iota // DropNewest drops the message being sent and records the drop. Send returns nil. DropNewest // DropOldest drops the oldest sent message in the mailbox, records the drop and enqueues the // new one. Send returns nil. DropOldest // BlockSender makes an outside sender (a *System) wait until the mailbox has room and the // System admits messages again (OVL), or until its context ends. For a sender inside an actor, and // on engines that cannot make a caller wait (simulation), it behaves as FailSend. BlockSender )
func (MailboxPolicy) String ¶
func (p MailboxPolicy) String() string
String returns "fail-send", "drop-newest", "drop-oldest", "block-sender", or "MailboxPolicy(<n>)" for other values. Records, logs and metrics use these spellings (OBS-145).
type MemSizer ¶
type MemSizer interface{ MemSize() int }
MemSizer is implemented by actors that report the size of their state in bytes.
type Option ¶
type Option func(*systemConfig)
Option configures New. Options are applied in argument order; a later option overrides an earlier one for the same setting. Option values are validated by New, not by the option constructors: no option constructor panics (R44).
func WithAdmission ¶
WithAdmission sets absolute admission thresholds in bytes: admission stops when the live heap reaches high and resumes when it falls to low. WithAdmission(0, 0) turns admission off even when a Go memory limit is set. Any other pair needs 0 < low < high, or New panics with an error wrapping ErrInvalidOption. Simulation ignores it; its byte budgets are sim.Options.Budget.
func WithDefaultMailbox ¶
func WithDefaultMailbox(capacity int, policy MailboxPolicy) Option
WithDefaultMailbox sets the capacity and policy of every actor spawned in the system without WithMailbox. Without it the default is 1024 and FailSend. It never panics: an invalid capacity or policy makes New panic with an error wrapping ErrInvalidOption (ACT).
func WithGoroutineWarning ¶
WithGoroutineWarning sets the goroutine count that triggers a warning. 0 turns the warning off (the count is still exported). A bound < 0 makes New panic with an error wrapping ErrInvalidOption. Simulation ignores it.
func WithGuardianStrategy ¶
WithGuardianStrategy sets the user guardian's strategy for top-level actors. Without it, the strategy is OneForOne(nil). New panics with an error wrapping ErrInvalidOption if s is invalid (SUP-370).
func WithMaxActors ¶
WithMaxActors sets the maximum number of live actors of the System to n. n/100 of them (at least 1 when n >= 2) are reserved for restart rebuilds and system actors. An n < 1 makes New panic with an error wrapping ErrInvalidOption.
func WithMemoryEstimates ¶
func WithMemoryEstimates() Option
WithMemoryEstimates turns on per-actor memory estimates (Sizer, MemSizer, System.Estimates).
func WithNodeName ¶
WithNodeName sets the system's node name. The name must be 1-64 bytes from [A-Za-z0-9._-], starting with a letter or digit (the faultline node-name rule). WithNodeName never panics; New panics with an error wrapping ErrInvalidOption on an invalid name. The default is "local". It is ignored on a system built on an engine (simulation), which takes the engine's node name.
func WithWatchdog ¶
WithWatchdog sets the stuck-turn timeout. 0 turns the watchdog off. A d < 0 makes New panic with an error wrapping ErrInvalidOption. Simulation ignores it.
type OverloadReason ¶
type OverloadReason uint8
OverloadReason is the source of an admission change. Its values equal those of engine.AdmissionSource.
const ( OverloadMemory OverloadReason = iota + 1 // production live heap OverloadBudget // simulation count budget (sim.Options.Budget) OverloadPressure // simulation memory-pressure fault )
func (OverloadReason) String ¶
func (r OverloadReason) String() string
String returns "memory", "budget", "pressure", or "OverloadReason(<n>)".
type Overloaded ¶
type Overloaded struct {
Active bool // true: admission stopped; false: admission resumed
Reason OverloadReason // the source whose change caused this transition
Live uint64 // measured bytes at the change (OverloadBudget: the estimate); 0 for OverloadPressure
High uint64 // thresholds in force (OverloadBudget: the byte budget and its resume mark); 0 for OverloadPressure
Low uint64
}
Overloaded is the signal sent to subscribed actors when their System starts or stops shedding. It implements Signal.
type PID ¶
type PID[M any] struct { // contains filtered or unexported fields }
PID is the typed address of an actor whose message type is M. It is comparable and contains only its Address. The zero PID names no actor.
func Lookup ¶
Lookup returns the PID of the actor registered at path on sys, if it was spawned with exactly message type M. It finds an actor whose stop has begun and none whose stop has completed. It returns ErrInvalidName if path is not well-formed, ErrNotFound if no actor is registered there (the guardians /user and /system are not), and ErrWrongType if the actor's message type is not M. Lookup panics if sys is nil.
func PIDAt ¶
PIDAt returns a PID with uid 0 that addresses whichever actor is registered at path on node when the PID is used, locally and through remoting (Phase 3). A message to it when no actor of type M is registered at path goes to dead letters on that node. path has the form Lookup accepts. PIDAt panics if node is not a valid node name or path is malformed.
func Spawn ¶
func Spawn[M any](parent Spawner, name string, factory func() Actor[M], opts ...SpawnOption) (PID[M], error)
Spawn creates a child of parent named name and returns its PID. name "" asks for a generated name "$<n>". factory is called at every start and restart, never by Spawn itself.
Errors: ErrInvalidName, ErrInvalidOption, ErrStopped, ErrNameTaken, ErrActorCap and ErrOverloaded (OVL), each wrapped as in §7. Spawn panics if parent, factory or an option is nil. A spawn refused for any of these reasons registers nothing and takes no generated name.
type PanicError ¶
type PanicError struct {
Value any // the value passed to panic
Stack []byte // runtime/debug.Stack() at recovery; never recorded in traces
}
PanicError is the error of a failure caused by a panic. errors.Unwrap returns Value when it is an error.
func (*PanicError) Error ¶
func (e *PanicError) Error() string
Error returns "lockstep: panic: " followed by a description of Value (SUP-145).
func (*PanicError) Unwrap ¶
func (e *PanicError) Unwrap() error
Unwrap returns Value if it is an error, otherwise nil.
type Reply ¶
type Reply[R any] struct { // contains filtered or unexported fields }
Reply is the typed future of one ask.
func Ask ¶
Ask sends the message build returns to the actor to and returns the future of its answer. build receives the ask's ReplyTo and is called once, synchronously, before Ask returns, unless the ask fails before sending (MSG-300). With a *System sender outside any actor's turn, a full BlockSender mailbox on a blocking engine makes Ask wait until the request is enqueued or the ask resolves, at its timeout at the latest (MSG-330). An invalid option value resolves the reply with an error wrapping ErrInvalidOption. Ask panics if from or build is nil, an option is nil, or from is a Context outside its turn.
func (*Reply[R]) Await ¶
Await waits for the ask to resolve and returns its value or error. If ctx ends first it returns the zero R and ctx.Err(), and the ask stays pending. Called during a turn it returns ErrAwaitInActor at once. In simulation Await never waits and never drives the run: on a pending reply it fails the seed and returns an error wrapping ErrAwaitInActor, from a turn or from the test body (test bodies use sim.Ask). Await may be called any number of times from any goroutine; every call that sees the resolution returns the same result.
type ReplyTo ¶
type ReplyTo[R any] struct { // contains filtered or unexported fields }
ReplyTo is the address an answer goes to. Ask creates it and passes it to build; the message carries it to whoever answers. It is a comparable value without pointers, so messages that hold it stay safe. The zero ReplyTo answers nothing.
type Sender ¶
type Sender interface {
// contains filtered or unexported methods
}
Sender is the origin of a send, an ask, a reply or a stop. It is implemented only by *System and *Context[X] for any X.
type Signal ¶
type Signal interface {
// contains filtered or unexported methods
}
Signal is a notification from lockstep itself, delivered through SignalReceiver[M].Signal and never as an M. It is implemented only by Terminated and ChildFailed (SUP), Overloaded (OVL) and, from Phase 3, NodeDown and NodeUp (CLU).
type SignalReceiver ¶
SignalReceiver is implemented by actors that receive lockstep's notifications (MSG-810). An actor without it ignores signals; its supervisor strategy still handles its children's failures (SUP-150 to SUP-230).
type Sizer ¶
type Sizer interface{ Size() int }
Sizer is implemented by messages that report their size in bytes for memory estimates.
type SpawnOption ¶
type SpawnOption func(*spawnConfig)
SpawnOption configures one Spawn. WithMailbox (MBX), WithStrategy (SUP) and the throughput hint (SCH) are SpawnOptions.
func WithMailbox ¶
func WithMailbox(capacity int, policy MailboxPolicy) SpawnOption
WithMailbox sets the spawned actor's mailbox capacity and full-mailbox policy. It never panics: if capacity < 1 or policy is not one of the four constants, Spawn returns an error wrapping ErrInvalidOption (ACT).
func WithStrategy ¶
func WithStrategy(s Strategy) SpawnOption
WithStrategy sets the strategy for the children of the spawned actor. Without it, the strategy is OneForOne(nil). Spawn returns an error wrapping ErrInvalidOption if s is invalid (SUP-370).
type Spawner ¶
type Spawner interface {
// contains filtered or unexported methods
}
Spawner is a parent for Spawn. It is implemented only by *System (the user guardian is the parent) and *Context[X] for any X (that actor is the parent).
type Starter ¶
Starter is implemented by actors that need a hook when an incarnation starts. Started runs after the factory and before the first message of the incarnation (SUP-030).
type StopKind ¶
type StopKind uint8
StopKind classifies a StopReason.
const ( StopNormal StopKind = iota + 1 // Stop(from, addr) or ctx.Stop StopFailed // the supervisor's directive was to stop a failed actor StopParentStopping // the parent is stopping or restarting StopShutdown // System.Shutdown StopRestarting // the incarnation ends for a restart; only Stopped sees it StopNoActor // Terminated only: the watched address was not alive )
type StopReason ¶
StopReason tells why an incarnation ended, or, in Terminated, why a watched actor is gone. Err is non-nil exactly for StopFailed and StopRestarting.
func Failed ¶
func Failed(err error) StopReason
Failed returns a StopFailed reason carrying err: the reason of an actor stopped by its supervisor after failing with err, and of a Terminated whose watched actor was lost for a reason another package reports, such as cluster.ErrNodeDown or REM's ErrPeerRestarted. It panics if err is nil.
func Restarting ¶
func Restarting(err error) StopReason
Restarting returns the reason Stopped receives when the incarnation ends for a restart caused by err. It panics if err is nil.
func (StopReason) String ¶
func (r StopReason) String() string
String returns Kind.String(), followed by ": " and Err.Error() when Err is non-nil.
type Stopper ¶
type Stopper[M any] interface { Stopped(ctx *Context[M], reason StopReason) }
Stopper is implemented by actors that release resources. Stopped runs exactly once per incarnation: when the actor stops, before every restart, and after a failure, but not when a simulated node crashes. Children have already stopped when it runs (SUP-100).
type Strategy ¶
type Strategy struct {
// Decider maps a child's failure to a directive. nil means DirectiveRestart for every error.
Decider func(err error) Directive
// MaxRestarts is how many restarts are allowed within Window; one more becomes
// DirectiveEscalate. 0 allows none.
MaxRestarts int
// Window is the sliding period over which restarts are counted, on the engine clock.
Window time.Duration
// MinBackoff is the delay before the first restart in the window; it doubles for each further
// restart in the window, up to MaxBackoff. 0 restarts without delay.
MinBackoff time.Duration
MaxBackoff time.Duration
// contains filtered or unexported fields
}
Strategy is a supervision strategy for the children of one actor. Build it with OneForOne or AllForOne and adjust the exported fields; a zero Strategy is invalid.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System is one runtime instance. All of its exported functions and methods are safe for concurrent use when *System is the Spawner or Sender.
func New ¶
New builds a system on the local engine (Phase 1) or the production engine (Phase 2, SCH), creates its two guardians and returns it. It panics with an error wrapping ErrInvalidOption if an option is nil or invalid.
func (*System) Estimates ¶
func (s *System) Estimates(n int) []ActorEstimate
Estimates returns up to n live actors with the largest estimates, largest first, ties in byte order of Addr.String(). It returns nil when n <= 0 or estimates are off.
func (*System) Incarnation ¶
Incarnation returns the epoch the system started with: the faultline node incarnation in simulation, a random value otherwise. It is never 0 and does not change for the system's life, even when uid allocation moves to a new epoch (ACT-040).
func (*System) Node ¶
Node returns the system's node name: the node part of every address it allocates.
func (*System) Shutdown ¶
Shutdown stops every actor, user actors first, then system actors, and waits until every Stopped hook has returned. It returns nil when the system is stopped, or ctx.Err() if ctx ends first; shutdown then continues and a later call waits again. Called during a turn (an actor may shut down its own system) or on an engine that cannot block, such as the simulation engine, it starts the shutdown and returns nil at once without waiting (ACT-060).
type Terminated ¶
type Terminated struct {
Addr Address
Reason StopReason
}
Terminated reports that a watched actor stopped for good, or that the watched address was not alive (Reason NoActor). Reason is the actor's final stop reason, NoActor, or a Failed reason set by REM or CLU for an actor lost with its node or connection.
Source Files
¶
- actor.go
- address.go
- admission.go
- ask.go
- asktable.go
- cell.go
- context.go
- discard.go
- doc.go
- effect.go
- envelope.go
- errors.go
- estimates.go
- group.go
- guard.go
- guardian.go
- hold.go
- hooks.go
- host.go
- lifecycle.go
- log.go
- lookup.go
- mailbox.go
- names.go
- options.go
- overload.go
- overloaded.go
- pipe.go
- rand.go
- reply.go
- restart.go
- send.go
- signal.go
- signals_sup.go
- spawn.go
- stop.go
- stopreason.go
- strategy.go
- supervision.go
- supervisor.go
- system.go
- timers.go
- turn.go
- uid.go
- watch.go
Directories
¶
| Path | Synopsis |
|---|---|
|
analysis
module
|
|
|
internal
|
|
|
dettest
Package dettest is lockstep's determinism lint, import-boundary check, exported-API snapshot generator, run-twice switch and golden-hash file format.
|
Package dettest is lockstep's determinism lint, import-boundary check, exported-API snapshot generator, run-twice switch and golden-hash file format. |
|
engine
Package engine is the seam between the lockstep runtime and the engines that run it (architecture §12, RFC-0001).
|
Package engine is the seam between the lockstep runtime and the engines that run it (architecture §12, RFC-0001). |
|
engine/enginetest
Package enginetest is a deterministic manual engine and a recording tracer for unit tests of the runtime.
|
Package enginetest is a deterministic manual engine and a recording tracer for unit tests of the runtime. |
|
engine/local
Package local is the single-goroutine engine behind lockstep.New in Phase 1 (architecture §12.3): one loop goroutine runs every turn, timer function and effect completion.
|
Package local is the single-goroutine engine behind lockstep.New in Phase 1 (architecture §12.3): one loop goroutine runs every turn, timer function and effect completion. |
|
hooks
Package hooks connects packages that must not import each other.
|
Package hooks connects packages that must not import each other. |
|
mailbox
Package mailbox holds the two queues of an actor: the bounded user Queue with its full-mailbox policy, and the unbounded SystemQueue for lifecycle commands and signals (MBX-030 to MBX-080).
|
Package mailbox holds the two queues of an actor: the bounded user Queue with its full-mailbox policy, and the unbounded SystemQueue for lifecycle commands and signals (MBX-030 to MBX-080). |
|
overload
Package overload holds the parts of overload protection every engine shares: the actor cap, the admission gate and the hysteresis switch (OVL §4.2).
|
Package overload holds the parts of overload protection every engine shares: the actor cap, the admission gate and the hysteresis switch (OVL §4.2). |
|
registry
Package registry holds a system's actor names, child lists, generated-name counters and watch tables (ACT-500).
|
Package registry holds a system's actor names, child lists, generated-name counters and watch tables (ACT-500). |
|
supervise
Package supervise holds the pure logic of actor lifecycle and supervision: the cell state machine, directives, restart limits, sliding-window restart intensity and capped exponential backoff (SUP-010, SUP-180, SUP-270, SUP-280, SUP-370).
|
Package supervise holds the pure logic of actor lifecycle and supervision: the cell state machine, directives, restart limits, sliding-window restart intensity and capped exponential backoff (SUP-010, SUP-180, SUP-270, SUP-280, SUP-370). |
|
toys
Package toys holds the toy actor systems of the golden suite: small actors with fixed behavior whose simulation runs have the same trace on every machine (DET-200).
|
Package toys holds the toy actor systems of the golden suite: small actors with fixed behavior whose simulation runs have the same trace on every machine (DET-200). |
|
Package sim runs lockstep actor systems as seeded faultline simulations inside go test.
|
Package sim runs lockstep actor systems as seeded faultline simulations inside go test. |