Documentation
¶
Overview ¶
Package memory is an in-memory dispatch adapter in two shapes, Slurm and Kubeflow, that implements the whole SPI, including every optional interface but OutputReader (spec 0003 D11). It is the backend the conformance suite is proven against and the one the simulator runs (spec 0005).
Importing it registers it under the name "memory". Its timed behaviour (purge, a lost node ending a job, vanishing evidence) is worked out from the clock inside calls, never by a goroutine of its own, so a synctest bubble's fake clock drives all of it (spec 0005 D2).
Index ¶
- Constants
- Variables
- func CallStart(ctx context.Context) (time.Time, bool)
- func Factory(_ context.Context, cfg dispatch.AdapterConfig) (dispatch.Backend, error)
- func WithCallStart(ctx context.Context, at time.Time) context.Context
- func WithCrashBetweenSteps(ctx context.Context) context.Context
- func WithStopAfterSecondStep(ctx context.Context) context.Context
- type Backend
- func (b *Backend) Capabilities(ctx context.Context, _ *model.JobSpec) (map[model.Capability]model.Support, error)
- func (b *Backend) Ceased(ctx context.Context, ref model.ObjectRef, last model.ExecutionObs) (model.CessationEvidence, error)
- func (b *Backend) Close() error
- func (b *Backend) Compile(ctx context.Context, spec model.JobSpec, policy model.RecoveryPolicy, ...) (model.NativeOffer, error)
- func (b *Backend) Declarations() model.Declarations
- func (b *Backend) Env() *Env
- func (b *Backend) Find(ctx context.Context, job model.JobID) (model.Discovery, error)
- func (b *Backend) FindMany(ctx context.Context, jobs []model.JobID, states ...model.ObjectState) (map[model.JobID]model.Discovery, error)
- func (b *Backend) Hold(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error
- func (b *Backend) IdentityWeakened(ctx context.Context, _ model.JobSpec) (string, error)
- func (b *Backend) Inspect(ctx context.Context, ref model.ObjectRef) (model.ObjectObs, error)
- func (b *Backend) Native(ctx context.Context, _ model.JobSpec, policy model.RecoveryPolicy) ([]model.Support, error)
- func (b *Backend) Open(ctx context.Context, ref model.ObjectRef) error
- func (b *Backend) Progress(ctx context.Context, ref model.ObjectRef) (model.Progress, error)
- func (b *Backend) Release(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error
- func (b *Backend) Requeue(ctx context.Context, ref model.ObjectRef, m model.CallMeta) error
- func (b *Backend) RestoreRequeueBit(ctx context.Context, ref model.ObjectRef, m model.CallMeta) error
- func (b *Backend) Rules(ctx context.Context, _ model.JobSpec, policy model.RecoveryPolicy) ([]model.RuleSupport, error)
- func (b *Backend) Shape() Shape
- func (b *Backend) Start(ctx context.Context, req model.StartRequest) (model.ObjectRef, error)
- func (b *Backend) Stop(ctx context.Context, ref model.ObjectRef, reason string) error
- func (b *Backend) StopJob(ctx context.Context, job model.JobID, reason string) (model.StopReport, error)
- func (b *Backend) View(readOnly bool) *Backend
- func (b *Backend) Watch(ctx context.Context, job model.JobID) (<-chan model.ObjectObs, error)
- type Cessation
- type Config
- type Env
- func (e *Env) AdminHold(ref model.ObjectRef) error
- func (e *Env) Beat(ref model.ObjectRef, b appcause.Beat) error
- func (e *Env) BeatBytes(ref model.ObjectRef, raw []byte) error
- func (e *Env) CauseDocument(ref model.ObjectRef, doc []byte) error
- func (e *Env) Complete(ref model.ObjectRef) error
- func (e *Env) CreateForeign(job model.JobID, comment string) (model.ObjectRef, error)
- func (e *Env) DownNodes() []string
- func (e *Env) End(ref model.ObjectRef, cause model.Cause) error
- func (e *Env) Fail(ref model.ObjectRef, exitCode int) error
- func (e *Env) LoseNode(ref model.ObjectRef) error
- func (e *Env) LoseNodeEnded(ref model.ObjectRef) error
- func (e *Env) Object(ref model.ObjectRef) (Truth, bool)
- func (e *Env) Objects() []Truth
- func (e *Env) Preempt(ref model.ObjectRef) error
- func (e *Env) Purge(ref model.ObjectRef) error
- func (e *Env) RecoverNode(node string)
- func (e *Env) RequeueExternally(ref model.ObjectRef) error
- func (e *Env) RestartJobSet(ref model.ObjectRef) error
- func (e *Env) RestartSilently(ref model.ObjectRef) error
- func (e *Env) Run(ref model.ObjectRef, nodes ...string) error
- func (e *Env) SetCessation(c *Cessation)
- func (e *Env) SetHistoryUnreadable(on bool)
- func (e *Env) SetRequeueBit(ref model.ObjectRef, on bool) error
- type Execution
- type Shape
- type Site
- type Truth
Constants ¶
const Name = "memory"
Name is the memory adapter's registry name.
Variables ¶
var ErrCrashed = fmt.Errorf("%w: the caller crashed between the requeue's steps", model.ErrOutcomeUnknown)
ErrCrashed is a Requeue that a crash ended after its first step, leaving Requeue=1 set (spec 0003 D10).
var ErrExpired = fmt.Errorf("%w: the call started past its deadline", model.ErrRejected)
ErrExpired is a deadline-carrying call whose command started past its deadline; it did nothing (spec 0003 D9).
var ErrFinished = fmt.Errorf("%w: Job has already finished", model.ErrRejected)
ErrFinished is Open on an object that ended without being opened: a fence, never success (spec 0003 D1).
var ErrNotApplicable = fmt.Errorf("%w: not applicable", model.ErrRejected)
ErrNotApplicable is an environment action the object's state or the shape does not allow.
var ErrStaleHold = fmt.Errorf("%w: the hold instance named is not the one in force", model.ErrRejected)
ErrStaleHold is a Release naming an instance other than the one in force (spec 0003 D9).
Functions ¶
func Factory ¶
Factory builds a memory Backend from an AdapterConfig whose Settings is decoded strictly (ParseSettings). Each call has its own ground truth; to share one, use New and View.
func WithCallStart ¶
WithCallStart returns a context telling the adapter when a deadline-carrying call's command started on the scheduler's host. The simulator's fault layer sets it, because a call it delays lands later than it started (spec 0005 D4); without it the call starts at time.Now().
func WithCrashBetweenSteps ¶
WithCrashBetweenSteps returns a context under which a Requeue stops after setting Requeue=1, as a crash of its caller would: the conformance suite's CrashBetweenSteps fault.
func WithStopAfterSecondStep ¶
WithStopAfterSecondStep returns a context under which a Requeue stops after `scontrol requeue`, before Requeue=0: the job is requeued with its bit left set, and the result is ErrOutcomeUnknown, as go/dispatch-slurm reports a bit left set (spec 0005 D4).
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is the in-memory dispatch.Backend. It implements Holder, Requeuer, NativePolicyCompiler, Watcher, CessationSignal, IdentityWeakener, MultiFinder and ProgressReader (spec 0003 D1, D11).
func (*Backend) Capabilities ¶
func (b *Backend) Capabilities(ctx context.Context, _ *model.JobSpec) (map[model.Capability]model.Support, error)
Capabilities answers from the configured table.
func (*Backend) Ceased ¶
func (b *Backend) Ceased(ctx context.Context, ref model.ObjectRef, last model.ExecutionObs) (model.CessationEvidence, error)
Ceased answers from the scripted cessation command, its only source (spec 0003 D12). A failing or hanging command is an error, never evidence; with none configured it is ErrUnsupported; an execution with no nodes or no start is answered not ceased. It works read-only.
func (*Backend) Close ¶
Close ends this view's watch streams; later calls on it fail. Other views are unaffected.
func (*Backend) Compile ¶
func (b *Backend) Compile(ctx context.Context, spec model.JobSpec, policy model.RecoveryPolicy, remaining model.Budgets) (model.NativeOffer, error)
Compile offers every rule the native table says Yes to, each with the budget remaining names, never the rule's original allowance, so a resubmission cannot reset what was spent (spec 0003 D3).
func (*Backend) Declarations ¶
func (b *Backend) Declarations() model.Declarations
Declarations are fixed at construction (spec 0003 D13). The adapter implements Watcher, so PolledLoss declares only history: with History and a purge, an unbounded end and the execution count's window (spec 0003 D13, amended 2026-10-27). A Slurm-shaped requeue lands at once, so its rise shows within the call bound; a Kubeflow-shaped one has no requeue and no settle bound.
func (*Backend) Find ¶
Find returns every visible object of job. Slurm matches the name byte for byte; Kubernetes by label, where a deleted object is indistinguishable from one never created (spec 0003 D6).
func (*Backend) FindMany ¶
func (b *Backend) FindMany(ctx context.Context, jobs []model.JobID, states ...model.ObjectState) (map[model.JobID]model.Discovery, error)
FindMany is Find for many jobs under one lock, as one squeue call with every name would answer them; with states named it keeps only objects in those states.
func (*Backend) Hold ¶
Hold places hold instance m.Instance. On Slurm it is a far-future start time, refused on an object that is no longer pending; on Kubeflow it deactivates the Workload, ending a running execution with cause Held (spec 0003 D9).
func (*Backend) IdentityWeakened ¶
IdentityWeakened answers Config.IdentityWeakened whatever the spec.
func (*Backend) Inspect ¶
Inspect observes one object. A purged one is read from history where the world keeps it, and is ErrUnreachable while history is unreadable; otherwise, and for a deleted one, ErrNotFound.
func (*Backend) Native ¶
func (b *Backend) Native(ctx context.Context, _ model.JobSpec, policy model.RecoveryPolicy) ([]model.Support, error)
Native answers, per rule, the configured native table by the rule's action.
func (*Backend) Open ¶
Open lifts the gate. It is idempotent on a live object past its gate, refuses an admin hold it does not own, and leaves a hold in place (spec 0003 D1, D5, D9).
func (*Backend) Progress ¶ added in v0.3.0
Progress reads the beat of ref's current execution, judging staleness on this view's clock.
func (*Backend) Release ¶
Release lifts the hold only if the instance in force is m.Instance; any other is stale and refused (spec 0003 D9).
func (*Backend) Requeue ¶
Requeue is Slurm's three steps, Requeue=1, requeue, Requeue=0, the last restored even when the requeue fails. It revives a finished or cancelled object to Pending, ungated, with its restart count raised (spec 0003 D10); a pending one refuses it.
func (*Backend) RestoreRequeueBit ¶
func (b *Backend) RestoreRequeueBit(ctx context.Context, ref model.ObjectRef, m model.CallMeta) error
RestoreRequeueBit clears a requeue bit left set outside Requeue. It is a deadline-carrying call like Requeue; an ended object refuses the update (spec 0003 D10).
func (*Backend) Rules ¶
func (b *Backend) Rules(ctx context.Context, _ model.JobSpec, policy model.RecoveryPolicy) ([]model.RuleSupport, error)
Rules answers each rule's Perform from the configured table, by its action.
func (*Backend) Start ¶
Start creates the object with its gate closed (spec 0003 D5), then reads it back and refuses one a site plugin changed.
func (*Backend) Stop ¶
Stop cancels this one object, never another of the same name; an object already ended or gone is success (spec 0003 D1).
func (*Backend) StopJob ¶
func (b *Backend) StopJob(ctx context.Context, job model.JobID, reason string) (model.StopReport, error)
StopJob cancels every object of the job by name, then verifies with the same view Find uses; an ended object on a node that is down is unproven (spec 0003 D6).
func (*Backend) View ¶
View returns another Backend over the same ground truth, read-only or not, as a second process opening the same cluster would see it.
func (*Backend) Watch ¶
Watch streams every observation of job's objects, starting with each visible object's current one. The channel is buffered and fed from inside the calls that change ground truth; a full buffer, a done context or Close closes it, a disconnect the subscriber recovers from by resubscribing (spec 0003 D11).
type Cessation ¶
type Cessation struct {
// Ceased is the command's exit 0; false is its exit 1.
Ceased bool `json:"ceased"`
// Detail is the command's output, returned verbatim.
Detail string `json:"detail,omitempty"`
// Fail makes the command fail (any other exit), so Ceased returns an error, never evidence.
Fail bool `json:"fail,omitempty"`
// Hang makes the command overrun its timeout, which is an error too.
Hang bool `json:"hang,omitempty"`
}
Cessation is the scripted answer of the site's cessation command (spec 0003 D12).
type Config ¶
type Config struct {
Shape Shape
// Name is the registry name refs carry; Name by default.
Name string
ReadOnly bool
// Namespace is the Kubernetes namespace of Kubeflow-shaped object ids.
Namespace string
// FirstJobID and MaxJobID bound Slurm job ids, which wrap (spec 0003 D1).
FirstJobID, MaxJobID int
// MinJobAge is how long an ended object stays visible before it is purged; zero never purges.
MinJobAge time.Duration
// History keeps a Slurm-shaped object's end readable through Inspect after its purge, as
// accounting does (spec 0003 D6, D7, amended 2026-10-27).
History bool
// CallBound is Declarations.CallBound: when a started hold-family or requeue call has landed.
CallBound time.Duration
// NodeLossWindow is Declarations.NodeLossWindow (spec 0003 D2).
NodeLossWindow time.Duration
// SlurmdTimeout is how long a Slurm job on a lost node still reports Running.
SlurmdTimeout time.Duration
// EvidenceWindow is how long Kubeflow pod evidence stays readable after the fact.
EvidenceWindow time.Duration
// WatchBuffer is each subscriber's channel capacity; a full buffer is a disconnect.
WatchBuffer int
// AutoRun starts a runnable object at the next call, for harnesses with no environment actor.
AutoRun bool
// Capabilities, Rules and Native override the shape's tables.
Capabilities map[model.Capability]model.Support
Rules map[model.Action]model.Support
Native map[model.Action]model.Support
// IdentityWeakened is IdentityWeakened's answer for every spec; empty keeps identity intact.
IdentityWeakened string
// Cessation is the cessation command's answer; nil means no command is configured.
Cessation *Cessation
Site *Site
}
Config is the memory adapter's configuration. The zero value of every field but Shape takes the shape's default.
func ParseSettings ¶
func ParseSettings(raw json.RawMessage, readOnly bool) (Config, error)
ParseSettings decodes an AdapterConfig.Settings section, refusing unknown fields at every level.
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env drives and reads the ground truth behind a Backend: the scheduler's own actions, for the simulator's environment actor, and the truth its invariant checks compare against (spec 0005 D4 to D6). Every change happens inside one of its calls, which never block.
func (*Env) AdminHold ¶
AdminHold puts a Slurm administrator's hold on a pending object: JobHeldAdmin, which Open never lifts (spec 0003 D5).
func (*Env) Beat ¶ added in v0.3.0
Beat publishes b as the launcher of ref's running execution does, where Progress reads it.
func (*Env) BeatBytes ¶ added in v0.3.0
BeatBytes publishes raw as ref's running execution's beat file holds it, malformed or not.
func (*Env) CauseDocument ¶ added in v0.3.0
CauseDocument puts doc where the adapter reads ref's running execution's cause document. When the execution ends, the scheduler's cause is refined by appcause.Refine (spec 0003 D2).
func (*Env) CreateForeign ¶
CreateForeign creates an ungated object with job's exact name and a comment that does not parse, as a site plugin rewriting ours would leave (spec 0003 D2).
func (*Env) End ¶
End ends a live object with cause, as the scheduler reports it; a pushed-down rule covering the cause restarts it instead.
func (*Env) LoseNode ¶
LoseNode loses the first node of a running execution. Slurm ends the job NODE_FAIL, after SlurmdTimeout when one is configured, or requeues it on its own authority when its requeue bit is set; Kubeflow wedges it Running with cause NodeLost, and it never ends on its own (spec 0003 D2, 0005 D4).
func (*Env) LoseNodeEnded ¶ added in v0.5.0
LoseNodeEnded is LoseNode on a Kubeflow-shaped object whose adapter proves the execution over, as a Slurm adapter does when the node running the batch script was replaced: the wedge reports the execution's end while the object still reads Running (spec 0001 D4, amended 2026-11-02).
func (*Env) Object ¶
Object returns the ground truth of the object ref names, as created or as reported after a requeue, purged and deleted ones included.
func (*Env) Objects ¶
Objects returns the ground truth of every object ever created, in creation order.
func (*Env) Preempt ¶
Preempt preempts a running execution. On Slurm the object ends Preempted under --no-requeue, but a requeue bit left set makes Slurm requeue it instead, on its own authority (spec 0003 D10). On Kubeflow the Workload is evicted: the object goes back to pending with its restart counter left alone.
func (*Env) Purge ¶ added in v0.2.0
Purge removes an ended Slurm-shaped object from the view now, as MinJobAge would.
func (*Env) RecoverNode ¶
RecoverNode brings a lost node back.
func (*Env) RequeueExternally ¶
RequeueExternally requeues an object on someone else's authority, setting the requeue bit first as an operator must, and leaving it set: the bit a supervisor restores (spec 0003 D10). A Kubeflow-shaped backend has no external requeue.
func (*Env) RestartJobSet ¶
RestartJobSet restarts a running Kubeflow execution as a JobSet's failure policy does: the execution ends, the next starts on the same nodes, the restart count rises, and the cause is Requeued with Scheduler provenance, as go/dispatch-kubeflow reports it (spec 0005 D4).
func (*Env) RestartSilently ¶
RestartSilently restarts a Kubeflow execution's ranks in the kubelet, which nothing above the pod shows: the execution, its token and its epoch are unchanged (spec 0003 D2).
func (*Env) Run ¶
Run starts a runnable object on nodes (node1..nodeN for the spec's node count when none are given). A gated, held or admin-held object is not runnable: the gate means no execution before Open.
func (*Env) SetCessation ¶
SetCessation replaces the cessation command's scripted answer; nil means none is configured.
func (*Env) SetHistoryUnreadable ¶ added in v0.2.0
SetHistoryUnreadable makes history unreadable, as an accounting outage does, or readable again.
type Execution ¶
type Execution struct {
Token string
Restart int
Epoch uint64
Nodes []string
Started time.Time
Ended time.Time
Cause model.Cause
SilentRestarts int
Env map[string]string
}
Execution is one run of an object, by ground truth. Env holds the DISPATCH_* variables every rank of it sees (spec 0003 D8); it is nil for a foreign object, whose submission is not ours.
type Shape ¶
type Shape int
Shape is which scheduler the adapter behaves like (spec 0003 D11).
func (Shape) MarshalText ¶
MarshalText encodes the shape by name.
func (*Shape) UnmarshalText ¶
UnmarshalText decodes a shape name, refusing one it does not know.
type Site ¶
type Site struct {
RewriteComment string `json:"rewriteComment,omitempty"`
SetRequeue bool `json:"setRequeue,omitempty"`
}
Site is what a site's job_submit plugin or cli_filter does to a submission, so the read-back refusal can be exercised (spec 0003 D5).
type Truth ¶
type Truth struct {
// Ref is the object's ref as created, the one dispatch holds; a Slurm requeue moves on the
// submit time Inspect reports (spec 0003 D1).
Ref model.ObjectRef
// Submit is the submit time Inspect reports now.
Submit time.Time
Job model.JobID
Name string
Comment string
Generation int
Submission int
Attempt int
Foreign bool
State model.ObjectState
Cause model.Cause
AdminHeld bool
Opened bool
HoldInstance uint32
// HeldBy, HeldUntil and HoldReason are the Kubeflow annotations written beside the hold in
// force; zero on Slurm, and once the hold is lifted.
HeldBy model.Actor
HeldUntil time.Time
HoldReason string
// StartTime is a Slurm object's requested start time, which encodes its hold.
StartTime time.Time
RequeueBit bool
Restart int
Executions []Execution
Created time.Time
Ended time.Time
Purged bool
Deleted bool
}
Truth is one object's ground truth, for the simulator's environment actor and invariant checks. Unlike Inspect it never loses evidence and includes purged and deleted objects.