Skip to main content

Module journal

Module journal 

Source
Expand description

The journal on disk: one file per attempt the agent started and the master hasn’t acknowledged, so a restarted agent still reports a result it had and stops a task process its previous incarnation left behind (see archive/PROJECT.md, Worker lifecycle).

  • Files: <journal_dir>/<attempt_id>.json, each replaced atomically (a temporary file, fsync, rename, fsync of the directory) before the message it backs is sent: running before Started (and again with the process’s identity once it is spawned), finished before Finished. A file goes when the master acknowledges the result or decides to forget the attempt.

  • On start: temporary files left by a crash are removed, finished results are reported again, and the process groups of attempts that were running are stopped (SIGTERM, then SIGKILL after a grace time); those attempts aren’t reported, so the master ends them lost.

  • Process identity: a process group ID and the start time of its leader (from /proc/<pid>/stat), so a recycled PID isn’t taken for the task. Without /proc the agent warns once and nothing is stopped; once the leader is gone, nothing is stopped.

  • Cleanups: an attempt of a task with a cleanup also keeps <attempt_id>.attempt, what its cleanup needs to run after a restart (the assignment and where its code is), written before Started, and <attempt_id>.handles, its handles, a line each, on disk before the task hears they are registered. Its record is cleaning from the task’s end, with the task’s result: the cleanup runs again from there (see archive/PROJECT.md, Per-task cleanup).

  • One agent per journal: it holds a lock (see Journal::lock).

Its operations block (fsync); the agent runs them off its event loop.

Structs§

Journal
The journal directory.
KeptAttempt
What a task’s cleanup needs to run after an agent restart.
OrphanWaits
How an orphan is waited for.
ProcessIdentity
What identifies a task’s process group across an agent restart.

Enums§

JournalRecord
What the journal knows about an attempt.
Orphan
How stopping an orphaned process group went.

Constants§

LOCK_FILE
The lock file: one agent per journal.

Functions§

process_identity
The identity of the process group led by pid.
stop_orphan
Stops the process group identity names, if its leader still runs: SIGTERM, and SIGKILL if the group hasn’t ended after grace, then waits for it to go (at most 5 s).