memory

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Name = "memory"

Name is the memory adapter's registry name.

Variables

View Source
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).

View Source
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).

View Source
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).

View Source
var ErrNotApplicable = fmt.Errorf("%w: not applicable", model.ErrRejected)

ErrNotApplicable is an environment action the object's state or the shape does not allow.

View Source
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 CallStart

func CallStart(ctx context.Context) (time.Time, bool)

CallStart returns the call-start moment ctx carries, and whether it carries one.

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

func WithCallStart(ctx context.Context, at time.Time) context.Context

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

func WithCrashBetweenSteps(ctx context.Context) context.Context

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

func WithStopAfterSecondStep(ctx context.Context) context.Context

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 New

func New(c Config) (*Backend, error)

New builds a memory Backend from c.

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

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

func (b *Backend) Close() error

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) Env

func (b *Backend) Env() *Env

Env returns the environment of b's ground truth, shared by every view.

func (*Backend) Find

func (b *Backend) Find(ctx context.Context, job model.JobID) (model.Discovery, error)

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

func (b *Backend) Hold(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error

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

func (b *Backend) IdentityWeakened(ctx context.Context, _ model.JobSpec) (string, error)

IdentityWeakened answers Config.IdentityWeakened whatever the spec.

func (*Backend) Inspect

func (b *Backend) Inspect(ctx context.Context, ref model.ObjectRef) (model.ObjectObs, error)

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

func (b *Backend) Open(ctx context.Context, ref model.ObjectRef) error

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

func (b *Backend) Progress(ctx context.Context, ref model.ObjectRef) (model.Progress, error)

Progress reads the beat of ref's current execution, judging staleness on this view's clock.

func (*Backend) Release

func (b *Backend) Release(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error

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

func (b *Backend) Requeue(ctx context.Context, ref model.ObjectRef, m model.CallMeta) error

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

Rules answers each rule's Perform from the configured table, by its action.

func (*Backend) Shape

func (b *Backend) Shape() Shape

Shape returns the shape the adapter behaves like.

func (*Backend) Start

func (b *Backend) Start(ctx context.Context, req model.StartRequest) (model.ObjectRef, error)

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

func (b *Backend) Stop(ctx context.Context, ref model.ObjectRef, reason string) error

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

func (b *Backend) View(readOnly bool) *Backend

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

func (b *Backend) Watch(ctx context.Context, job model.JobID) (<-chan model.ObjectObs, error)

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

func (e *Env) AdminHold(ref model.ObjectRef) error

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

func (e *Env) Beat(ref model.ObjectRef, b appcause.Beat) error

Beat publishes b as the launcher of ref's running execution does, where Progress reads it.

func (*Env) BeatBytes added in v0.3.0

func (e *Env) BeatBytes(ref model.ObjectRef, raw []byte) error

BeatBytes publishes raw as ref's running execution's beat file holds it, malformed or not.

func (*Env) CauseDocument added in v0.3.0

func (e *Env) CauseDocument(ref model.ObjectRef, doc []byte) error

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) Complete

func (e *Env) Complete(ref model.ObjectRef) error

Complete ends a running execution with success.

func (*Env) CreateForeign

func (e *Env) CreateForeign(job model.JobID, comment string) (model.ObjectRef, error)

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) DownNodes

func (e *Env) DownNodes() []string

DownNodes lists the nodes that are down, sorted.

func (*Env) End

func (e *Env) End(ref model.ObjectRef, cause model.Cause) error

End ends a live object with cause, as the scheduler reports it; a pushed-down rule covering the cause restarts it instead.

func (*Env) Fail

func (e *Env) Fail(ref model.ObjectRef, exitCode int) error

Fail ends a running execution with a non-zero exit.

func (*Env) LoseNode

func (e *Env) LoseNode(ref model.ObjectRef) error

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

func (e *Env) LoseNodeEnded(ref model.ObjectRef) error

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

func (e *Env) Object(ref model.ObjectRef) (Truth, bool)

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

func (e *Env) Objects() []Truth

Objects returns the ground truth of every object ever created, in creation order.

func (*Env) Preempt

func (e *Env) Preempt(ref model.ObjectRef) error

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

func (e *Env) Purge(ref model.ObjectRef) error

Purge removes an ended Slurm-shaped object from the view now, as MinJobAge would.

func (*Env) RecoverNode

func (e *Env) RecoverNode(node string)

RecoverNode brings a lost node back.

func (*Env) RequeueExternally

func (e *Env) RequeueExternally(ref model.ObjectRef) error

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

func (e *Env) RestartJobSet(ref model.ObjectRef) error

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

func (e *Env) RestartSilently(ref model.ObjectRef) error

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

func (e *Env) Run(ref model.ObjectRef, nodes ...string) error

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

func (e *Env) SetCessation(c *Cessation)

SetCessation replaces the cessation command's scripted answer; nil means none is configured.

func (*Env) SetHistoryUnreadable added in v0.2.0

func (e *Env) SetHistoryUnreadable(on bool)

SetHistoryUnreadable makes history unreadable, as an accounting outage does, or readable again.

func (*Env) SetRequeueBit

func (e *Env) SetRequeueBit(ref model.ObjectRef, on bool) error

SetRequeueBit is an operator's `scontrol update Requeue=0|1` on a live Slurm job (spec 0005 D4).

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.

func (Execution) Running

func (e Execution) Running() bool

Running reports whether the execution has not ended.

type Shape

type Shape int

Shape is which scheduler the adapter behaves like (spec 0003 D11).

const (
	ShapeSlurm Shape = iota + 1
	ShapeKubeflow
)

The shapes of spec 0003 D11.

func (Shape) MarshalText

func (s Shape) MarshalText() ([]byte, error)

MarshalText encodes the shape by name.

func (Shape) String

func (s Shape) String() string

String returns the shape's name.

func (*Shape) UnmarshalText

func (s *Shape) UnmarshalText(b []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL