journal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package journal records every change to a zone as an ordered sequence of commits.

The journal is not a log kept alongside the data; it is the only way data changes (architecture invariant 4). Four of the product's features read from this single structure rather than from four mechanisms: the audit log, the diff view, rollback, and incremental zone transfer (RFC 1995). A fifth arrives with the cluster, where a commit is what Raft replicates: see docs/adr/0002-journal-as-command-log.md.

Rejections wrap zone.ErrInvalid rather than introducing a second sentinel, so a caller that maps a validation failure onto an HTTP 400 has one rule instead of one per package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	ID     CommitID
	ZoneID zone.ZoneID
	// ZoneName is carried on the commit rather than joined from the zone,
	// because a commit outlives the zone: the last thing that happens to a zone
	// is that someone deletes it, and there would be nothing left to join to.
	ZoneName zone.Name

	// SerialFrom is the zone serial this commit was applied to, and SerialTo
	// the serial it produced.
	SerialFrom zone.Serial
	SerialTo   zone.Serial

	Kind   Kind
	Source Source
	// Actor names who caused the change: an API token's name, a shell user, or
	// empty for the system itself.
	Actor   string
	Comment string

	// RevertsTo is the serial a rollback restored the zone to. It is nil for
	// every other kind: a pointer rather than a zero value, because serial 0
	// is a legal serial and could not be told apart from "not a rollback".
	RevertsTo *zone.Serial

	// Events are the record changes, ordered by Seq with every deletion before
	// every addition. Empty is legal: a commit that changed only the zone's own
	// settings moved no records.
	Events []Event

	CreatedAt time.Time
}

Commit is one atomic change to one zone.

func (Commit) Validate

func (c Commit) Validate() error

Validate reports whether the commit is well formed on its own. It cannot check that the events belong to the zone, or that they apply to the state at SerialFrom; both need more than the commit.

type CommitID

type CommitID string

CommitID identifies a commit. Like the other identifiers it is a ULID, so commits sort by creation time without a second index.

type Event

type Event struct {
	// Seq orders events within a commit, counting from zero.
	Seq int

	Op Op

	Name  zone.Name
	Class zone.Class
	Type  zone.RRType
	TTL   zone.TTL
	RData zone.RData
}

Event is one resource-record change inside a Commit.

An event carries the record's full data in both directions, deletions included. RFC 1995 §2 lists deleted records in full rather than by name, and a rollback that has to put a record back needs the same thing.

Unlike a zone.Record an event may carry an SOA. The SOA is zone metadata rather than a record (data model §4.1), but a change to its parameters still travels through the journal, because that is where the history of the zone lives.

func (Event) String

func (e Event) String() string

String renders the event as one diff line: the record in zonefile order, prefixed by "-" for a deletion and "+" for an addition.

func (Event) Validate

func (e Event) Validate() error

Validate reports whether the event describes a well-formed change.

type Kind

type Kind string

Kind classifies what a commit did. It exists for the audit log and the UI, which want to say "imported" or "rolled back" rather than reciting the events.

const (
	// KindZoneCreate is the first commit of a zone, which brings the zone into
	// existence along with its initial records.
	KindZoneCreate Kind = "zone_create"
	// KindZoneUpdate changed the zone's own settings rather than its records.
	KindZoneUpdate Kind = "zone_update"
	// KindZoneDelete removed the zone.
	KindZoneDelete Kind = "zone_delete"
	// KindEdit is an ordinary record change.
	KindEdit Kind = "edit"
	// KindImport applied a zonefile or a declarative configuration.
	KindImport Kind = "import"
	// KindRollback restored an earlier state of the zone by moving forward to
	// it; see data model §4.6.
	KindRollback Kind = "rollback"
)

func (Kind) Valid

func (k Kind) Valid() bool

Valid reports whether k is one of the defined kinds.

type Op

type Op string

Op is the direction of a single resource-record change.

Two are enough. A modification is a deletion followed by an addition, which is also exactly how incremental zone transfer expresses it (RFC 1995 §2), so a third operation would only add a case every consumer has to unfold again.

const (
	// OpDel removes a resource record.
	OpDel Op = "del"
	// OpAdd adds a resource record.
	OpAdd Op = "add"
)

func (Op) Valid

func (o Op) Valid() bool

Valid reports whether o is one of the defined operations.

type Source

type Source string

Source names the interface a commit arrived through, so the audit log can distinguish a change someone made in the UI from one a config import made.

const (
	// SourceAPI is a change made over the HTTP API, which includes the GUI.
	SourceAPI Source = "api"
	// SourceCLI is a change made with the weg command.
	SourceCLI Source = "cli"
	// SourceImport is a change made by a zonefile or configuration import.
	SourceImport Source = "import"
	// SourceSystem is a change the server made on its own, such as the reverse
	// automation reconciling a zone.
	SourceSystem Source = "system"
)

func (Source) Valid

func (s Source) Valid() bool

Valid reports whether s is one of the defined sources.

Jump to

Keyboard shortcuts

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