Documentation
¶
Overview ¶
Package revision defines the persisted configuration revision model and the Store boundary. A revision holds one complete, normalized configuration payload; content is immutable once written and only the state and publish time change. At most one revision is published at a time.
Index ¶
- Constants
- Variables
- func BasedOn(ctx context.Context, store Getter, rev Revision) (int64, error)
- func Hash(payload []byte) string
- func ValidateHistory(revs []Revision) error
- type Draft
- type Getter
- type MemoryStore
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) Create(_ context.Context, d Draft) (Revision, error)
- func (m *MemoryStore) Discard(_ context.Context, id int64) (Revision, error)
- func (m *MemoryStore) Get(_ context.Context, id int64) (Revision, error)
- func (m *MemoryStore) ImportHistory(_ context.Context, revs []Revision) error
- func (m *MemoryStore) List(_ context.Context, limit int) ([]Revision, error)
- func (m *MemoryStore) Publish(_ context.Context, id, expectedCurrent int64, _ Meta) (Revision, error)
- func (m *MemoryStore) Published(_ context.Context) (Revision, error)
- func (m *MemoryStore) Rollback(_ context.Context, expectedCurrent, target int64, meta Meta) (Revision, error)
- func (m *MemoryStore) Sequence(context.Context) (int64, error)
- type Meta
- type Revision
- type State
- type Store
Constants ¶
const HashPrefix = "sha256:"
HashPrefix prefixes every content hash.
Variables ¶
var ( ErrNotFound = errors.New("revision: not found") ErrNoPublished = errors.New("revision: no published revision") ErrConflict = errors.New("revision: published revision changed concurrently") ErrInvalidState = errors.New("revision: invalid state transition") ErrHashMismatch = errors.New("revision: content hash mismatch") ErrNoRollback = errors.New("revision: no earlier published revision to roll back to") ErrNotEmpty = errors.New("revision: store is not empty") )
Store errors.
Functions ¶
func BasedOn ¶ added in v0.1.13
BasedOn is the published revision rev builds on: rev itself when it was published, else the nearest ancestor that was (a draft may build on another draft, discarded or not); 0 when none was.
func ValidateHistory ¶
ValidateHistory checks revisions for ImportHistory: unique positive IDs, known states, matching hashes, and at most one published revision.
Types ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-process Store. It is the reference implementation of the state machine and backs tests; it does not persist across restarts.
func NewMemoryStore ¶
func NewMemoryStore(now func() time.Time) *MemoryStore
NewMemoryStore returns an empty MemoryStore. A nil now uses time.Now.
func (*MemoryStore) ImportHistory ¶
func (m *MemoryStore) ImportHistory(_ context.Context, revs []Revision) error
ImportHistory implements Store.
func (*MemoryStore) Publish ¶
func (m *MemoryStore) Publish(_ context.Context, id, expectedCurrent int64, _ Meta) (Revision, error)
Publish implements Store.
func (*MemoryStore) Published ¶
func (m *MemoryStore) Published(_ context.Context) (Revision, error)
Published implements Store.
type Revision ¶
type Revision struct {
ID int64
ParentID int64
ContentHash string
Payload []byte
State State
Author string
Comment string
CreatedAt time.Time
PublishedAt time.Time
}
Revision is one persisted configuration revision. ParentID 0 means none; a zero PublishedAt means the revision has never been published.
func RollbackTarget ¶
RollbackTarget selects the rollback target among revs for the published revision current: an explicit target must exist and not be a draft; otherwise the newest superseded revision whose content differs is chosen.
type State ¶
type State string
State is a revision lifecycle state.
const ( StateDraft State = "draft" StatePublished State = "published" StateSuperseded State = "superseded" StateRolledBack State = "rolled-back" // StateDiscarded is a draft an administrator decided not to publish. StateDiscarded State = "discarded" )
Revision states.
func (State) Unpublished ¶ added in v0.1.13
Unpublished reports whether a revision in state s was never published: a draft, or one discarded. What a draft builds on is its nearest ancestor that was published.
type Store ¶
type Store interface {
// Create writes a new draft and returns it with its ID and hash.
Create(ctx context.Context, d Draft) (Revision, error)
// Get returns one revision with its payload.
Get(ctx context.Context, id int64) (Revision, error)
// List returns revision summaries, newest first; limit <= 0 means all.
List(ctx context.Context, limit int) ([]Revision, error)
// Published returns the published revision, or ErrNoPublished.
Published(ctx context.Context) (Revision, error)
// Publish publishes draft id. expectedCurrent is the caller's view of the
// published ID (0 for none); a mismatch fails with ErrConflict.
Publish(ctx context.Context, id, expectedCurrent int64, m Meta) (Revision, error)
// Rollback marks the published revision rolled-back and publishes a new
// revision copying target's payload. Target 0 selects the newest
// superseded revision whose content differs from the published one.
Rollback(ctx context.Context, expectedCurrent, target int64, m Meta) (Revision, error)
// Discard marks draft id discarded: it stays in the history and is never
// published. A revision that is not a draft fails with ErrInvalidState.
Discard(ctx context.Context, id int64) (Revision, error)
// ImportHistory copies revisions verbatim into an empty store, keeping
// IDs, states, authors and timestamps. It is used by migrate --history.
ImportHistory(ctx context.Context, revs []Revision) error
// Sequence grows with every write (a revision created, published,
// rolled back or discarded, history imported), as every process sharing
// the store sees it: a reader learns that revisions changed, a discard
// of an old draft included, by comparing two readings. It may also grow
// without a change to revisions.
Sequence(ctx context.Context) (int64, error)
Close() error
}
Store persists revisions. Implementations must be safe for concurrent use and perform each state transition atomically.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package revisiontest provides the conformance suite every revision.Store implementation must pass, so SQL stores keep the MemoryStore semantics.
|
Package revisiontest provides the conformance suite every revision.Store implementation must pass, so SQL stores keep the MemoryStore semantics. |