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 Hash(payload []byte) string
- func ValidateHistory(revs []Revision) error
- type Draft
- type MemoryStore
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) Create(_ context.Context, d Draft) (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)
- 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 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.
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.
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)
// 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
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. |