Documentation
¶
Overview ¶
Package spool is the gateway's durable accounting spool: an append-only file per process where every batch of usage records is written, and fsync'd, before it is inserted into the store. A store outage or a crash then loses nothing that reached the spool: the records are inserted when the store is back, or by the next process that starts on the same directory. Inserts are idempotent (keyed by the record ID), so replaying a batch that was already written before a crash bills nothing twice.
A spool file is a sequence of frames:
magic 'L' 'F' | length uint32 BE | CRC-32C of the payload, uint32 BE | payload
whose payload is one JSON-encoded store.Record. After a crash the file is untrusted input: a torn tail (an incomplete last frame) is expected and ignored; anything else that does not check out (bad magic, bad CRC, a length beyond MaxFrame, a payload that is not a record) stops the reading there and marks the file corrupt, kept for an operator instead of deleted.
Index ¶
Constants ¶
const MaxFrame = 64 << 10
MaxFrame bounds one frame's payload: a usage record is a few hundred bytes, tags included.
Variables ¶
var ( // ErrFull is returned by Append when the batch would take the spool // beyond its bound. ErrFull = errors.New("spool: full") )
Functions ¶
Types ¶
type Orphan ¶
type Orphan struct {
Path string
Records []store.Record
Tail Tail
// contains filtered or unexported fields
}
Orphan is a spool file left by a process that is gone.
func Orphans ¶
Orphans returns the spool files of dir that no live process holds (their lock is free), except skip, read and locked for the caller. A file that is not a regular file of this user's making is left alone.
type Spool ¶
type Spool struct {
// contains filtered or unexported fields
}
Spool is one process's spool file.
func Open ¶
Open creates dir (0700) if needed and a new spool file in it (0600), locked for this process.
func (*Spool) Close ¶
Close closes the file, removing it when empty; a file that still holds records stays for the next process to replay.