staging

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 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 staging implements the stage_locally path delivery: copying job inputs to worker-local scratch before a task runs and outputs back afterward. Each path is copied by an operator-configured sync command or, without one, by the built-in copy. The scratch destination paths are returned as path-map rules so the other deliveries advertise them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EffectiveScratchBase added in v0.3.0

func EffectiveScratchBase(scratchDir string) string

EffectiveScratchBase returns the scratch directory staging uses: scratchDir verbatim if set, otherwise the platform TEMP-based default. Exported so cmd/sqi-worker's boot-time isolation ancestor check (see isolation.ValidateTraversable) validates the path StageIn uses instead of duplicating this default.

Types

type Option added in v0.3.0

type Option func(*Stager)

Option configures a Stager at construction. See WithIsolationCapable.

func WithIsolationCapable added in v0.3.0

func WithIsolationCapable(capable bool) Option

WithIsolationCapable sets, once at worker boot, whether this worker can run tasks as another user at all. The caller passes the same root check cmd/sqi-worker's effectiveSessionRoot uses. It is a per-worker setting, not "did this assignment carry a credential": scratchBase and scratchBase/jobID are shared by every attempt of every job, including isolated and non-isolated queues on one worker, so deciding per assignment would let whichever task first creates the base fix its mode for every later attempt. A non-isolated task creating the base at 0750 would make every later isolated task fail ValidateTraversable against a base it cannot widen. A capable worker creates both directories at 0711; any other keeps 0750, which is also the mode when this option is not passed.

type Stager

type Stager struct {
	// contains filtered or unexported fields
}

Stager copies staged paths with an operator-configured sync command, or with the built-in copy when sync_command is empty or `builtin`.

func New

func New(scratchBase, syncCommand string, defaults bool, logger *slog.Logger, opts ...Option) *Stager

New returns a Stager. scratchBase/syncCommand come from worker config; defaults enables the built-in copy + TEMP scratch when staging is otherwise unconfigured. Pass WithIsolationCapable so a worker capable of run-as-user isolation creates its shared scratch ancestors traversable; without it they are created 0750.

func (*Stager) Cleanup

func (s *Stager) Cleanup(scratchDir string)

Cleanup removes the scratch directory, logging (not returning) any error.

func (*Stager) Configured

func (s *Stager) Configured() bool

Configured reports whether staging can proceed: explicitly configured (scratch + shell command), or the built-in copy is available (defaults on, or the `builtin` sentinel was set explicitly).

func (*Stager) StageIn

func (s *Stager) StageIn(ctx context.Context, jobID, attemptID string, entries []protocol.StageEntry, cred *isolation.Credential) ([]protocol.PathMapRule, string, error)

StageIn prepares a per-attempt scratch directory for every staged entry and returns one path-map rule per entry (original path -> scratch path) plus the scratch directory. IN/INOUT inputs are copied into scratch; OUT entries only get their scratch destination created (the task writes the output there, and Stager.StageOut copies it back afterward). The rule for an OUT entry lets the other deliveries redirect the task's OUTPUT paths into scratch; without it the task writes to the real path and copy-out fails on a missing scratch file. On any failure the partial scratch directory is removed.

cred is the run-as-user credential for the task that will read and write these paths, or nil when the assignment carries no isolation. Staging always runs as the worker (the sync command is operator-configured, not job code; internal/worker/session and internal/worker/executor are the launch sites that carry a credential), so everything it writes is owned by the worker. When cred is non-nil, StageIn hands the per-attempt scratch directory to cred (isolation.ChownRecursive) so the isolated task can read its staged inputs and write into its staged output directories.

The scratch base (s.effectiveScratch()) and scratchBase/jobID are shared by every attempt of every job and every run-as-user identity, so their mode (s.ancestorMode) is fixed at construction (see WithIsolationCapable) and they are never chowned: chowning them to one identity would give it nothing (search permission does not need ownership) and break every other identity's access. os.MkdirAll does not change the mode of a directory that already exists, so a pre-existing scratch_dir with a narrower mode is reported by isolation.ValidateTraversable (at boot when isolation.required is set, otherwise per assignment below) instead of being widened. Both ancestors must be traversable because Go's forkAndExecInChild sets the process credentials before chdir; otherwise the isolated task cannot reach its staged inputs even though scratchDir itself is chowned to it.

func (*Stager) StageOut

func (s *Stager) StageOut(ctx context.Context, scratchDir string, entries []protocol.StageEntry) error

StageOut copies every OUT/INOUT entry from scratch back to its original path. It iterates the full entries slice with its original index so the per-index subdirectory (<scratchDir>/<i>/<basename>) matches what prepareEntries created.

Every source is opened through one os.Root at scratchDir, so the kernel enforces containment and refuses reparse points at open time (see openStageOutSource). The check runs before both the built-in copy and an operator-configured sync_command, the one place it can cover both: whether a sync_command dereferences symlinks depends on that command ("rsync -a" preserves them; "rsync -aL" or plain "cp" follow them).

os.OpenRoot(scratchDir) is itself a lookup by path, and on Windows it follows a reparse point at scratchDir. Ownership protects it instead: replacing scratchDir means creating an entry in its parent, the per-job directory StageIn creates as the worker, which is never chowned (POSIX) or ACL'd (Windows) to the task; only the per-attempt leaf below it is handed over by ChownRecursive. A task therefore cannot substitute the root every lookup in this loop is anchored to.

Jump to

Keyboard shortcuts

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