Documentation
¶
Overview ¶
Package state owns bitc's on-disk layout (spec 9).
Index ¶
- Constants
- func AccountDir(e *config.Effective) (string, error)
- func AccountDirOnNetworkFS(e *config.Effective) (dir, netfs string, err error)
- func AppendHistory(path string, e Event, red *redact.Set) error
- func Check(root string) error
- func CheckAccountDir(e *config.Effective) error
- func Install16(secret []byte) string
- func InstallSecret(dir string) ([]byte, error)
- func MkdirPrivate(path string) error
- func ReadInstallSecret(dir string) ([]byte, error)
- func Shorten(s string, n int) string
- func StubNetworkFS(under string) (restore func())
- func WriteFileAtomic(path string, b []byte) error
- type Event
- type Layout
- func (l Layout) AdmitLock() string
- func (l Layout) ContainersDir() string
- func (l Layout) GroupUnitLock(g string, j int) string
- func (l Layout) History() string
- func (l Layout) JobDir(wt8, name string) string
- func (l Layout) JobsDir() string
- func (l Layout) NestLock(p string, i, depth int) string
- func (l Layout) PoolDir(p string) string
- func (l Layout) Reservations() string
- func (l Layout) Schema() string
- func (l Layout) SlotLock(p string, i int) string
- func (l Layout) Tickets(p string) string
Constants ¶
const SchemaVersion = 1
SchemaVersion is the state-dir schema this binary writes and understands.
Variables ¶
This section is empty.
Functions ¶
func AccountDir ¶
AccountDir is <passwd home>/.local/state/bitc/account (spec 2, 9). No env, flag or key moves it, so a private BITC_DIR or BITC_CONFIG cannot multiply the cap; only [test] accounting_dir. Like the state dir it is refused (78) on a network filesystem: the launch lock, the ledger and the reservations that hold the spend cap need a reliable flock.
func AccountDirOnNetworkFS ¶ added in v0.1.3
AccountDirOnNetworkFS is AccountDir for sweep, which still has work to do on a network filesystem: it returns the dir and, instead of refusing, the name of the network filesystem ("" for a local one). The caller must then treat the dir as read-only and its locks as untrusted; a dir that does not exist yet is not created there.
func AppendHistory ¶
AppendHistory appends one redacted JSON line with a single O_APPEND write.
func Check ¶ added in v0.1.2
Check runs Open's refusals on an existing state dir without creating or writing anything; a missing dir passes, since the first command creates it 0700.
func CheckAccountDir ¶ added in v0.1.3
CheckAccountDir is AccountDir's filesystem refusal without creating anything. Its callers are config check and status. A missing dir is judged by its nearest existing parent, so a fresh network-filesystem home is refused before the first remote command creates the dir there.
func InstallSecret ¶
InstallSecret returns the 32-byte install secret, creating it once. The file appears atomically (a full temp file linked into place), so no reader sees a partial secret; a file of any other length is an error rather than a key.
func MkdirPrivate ¶
MkdirPrivate creates path and missing parents with 0700 and checks path itself: owned by the user, not group- or world-accessible.
func ReadInstallSecret ¶ added in v0.1.3
ReadInstallSecret is InstallSecret without creating anything: a missing secret is an error.
func Shorten ¶ added in v0.1.6
Shorten cuts s to at most n bytes at a UTF-8 boundary and ends it with the history cut marker, or returns s whole when it is not longer than n.
func StubNetworkFS ¶ added in v0.1.3
func StubNetworkFS(under string) (restore func())
StubNetworkFS makes statfs of a path under `under` (every path if "") report NFS until the returned function is called. For tests in other packages; the seam itself is unexported. It swaps a global without a lock, so a test using it must not run in parallel.
func WriteFileAtomic ¶
WriteFileAtomic writes b to path (0600) through a temp file and rename.
Types ¶
type Event ¶
type Event struct {
TS string `json:"ts"`
Event string `json:"event"` // start | end | starved | fallback | reaped
Pool string `json:"pool"`
Slot int `json:"slot,omitempty"`
Units map[string]int `json:"units,omitempty"` // units held per group (start and end)
Job string `json:"job"`
Pid int `json:"pid"`
Nested bool `json:"nested,omitempty"`
Argv []string `json:"argv"`
ArgvTruncated bool `json:"argv_truncated,omitempty"`
Cwd string `json:"cwd"`
Provider string `json:"provider"`
Resource string `json:"resource,omitempty"`
Sha string `json:"sha,omitempty"`
Head string `json:"head,omitempty"` // git HEAD of the run's work tree at hold start
TreeClean *bool `json:"tree_clean,omitempty"` // git status --porcelain was empty at hold start
WaitMS *int64 `json:"wait_ms,omitempty"`
RunMS *int64 `json:"run_ms,omitempty"`
Exit *int `json:"exit,omitempty"`
Outcome string `json:"outcome,omitempty"`
Reason string `json:"reason,omitempty"`
}
Event is one history.jsonl line (spec 9). Refusals write nothing.
type Layout ¶
type Layout struct{ Root string }
Layout names every path in a state dir. Root is absolute.
func Open ¶
Open creates the state dir (0700) or checks an existing one, then checks SCHEMA. Every refusal is 78 (spec 9).
func (Layout) ContainersDir ¶ added in v0.1.6
ContainersDir holds a containerized run's --cidfile (<ticket>.cid): docker writes the id there once the container exists, which tells a docker failure from the command's own exit 125.