Documentation
¶
Overview ¶
Package store is ynf's state port (ADR-004): key/value documents with compare-and-swap, an append-only log per item, and timers. It is designed down to what S3 can do, so every provider (SQLite, S3, DynamoDB) can implement it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrConflict means the document's version was not the one the caller read. ErrConflict = errors.New("store: version conflict") // ErrNotFound means there is no document at the key. ErrNotFound = errors.New("store: not found") )
Functions ¶
This section is empty.
Types ¶
type LogEntry ¶
type LogEntry struct {
ID string `json:"id"` // ULID, so entries sort by time
Time time.Time `json:"time"`
Kind string `json:"kind"` // decision, action, run, note
Body json.RawMessage `json:"body"`
}
LogEntry is one immutable record in an item's log.
type Store ¶
type Store interface {
// Get returns a document and its version.
Get(ctx context.Context, key string) (doc []byte, version string, err error)
// Put writes a document if its current version is ifVersion; "" means create only. It returns
// the new version, or ErrConflict.
Put(ctx context.Context, key string, doc []byte, ifVersion string) (string, error)
// Delete removes a document if its current version is ifVersion. ErrConflict means it was
// changed since; ErrNotFound means it is already gone. Unlike Put there is no unconditional
// form, so a delete can never remove a document someone else has just rewritten.
Delete(ctx context.Context, key string, ifVersion string) error
// Keys lists document keys with a prefix, sorted.
Keys(ctx context.Context, prefix string) ([]string, error)
// Append adds an immutable entry to an item's log.
Append(ctx context.Context, item string, e LogEntry) error
// Log returns an item's log in order.
Log(ctx context.Context, item string) ([]LogEntry, error)
// Schedule sets when an item is next due; a zero time clears it.
Schedule(ctx context.Context, item string, at time.Time) error
// Due returns items due at or before now, earliest first.
Due(ctx context.Context, now time.Time, limit int) ([]string, error)
Close() error
}
Store is the port every provider implements.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package s3store is the S3 store provider (ADR-004), for the hosted service and the CI-native host, where state must outlive any one process.
|
Package s3store is the S3 store provider (ADR-004), for the hosted service and the CI-native host, where state must outlive any one process. |
|
Package sqlite is the SQLite store provider (ADR-004), for the daemon host.
|
Package sqlite is the SQLite store provider (ADR-004), for the daemon host. |
|
Package storetest is the conformance suite every store provider must pass (ADR-004), including concurrent compare-and-swap races.
|
Package storetest is the conformance suite every store provider must pass (ADR-004), including concurrent compare-and-swap races. |
Click to show internal directories.
Click to hide internal directories.