Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("record already exists")
ErrAlreadyExists is returned by storage implementations when attempting to create a record that already exists.
var ErrNotFound = errors.New("record not found")
ErrNotFound is returned by storage implementations when the requested record is not found in the database.
var ErrVersionMismatch = errors.New("version mismatch")
ErrVersionMismatch is returned by storage implementations when a conditional (CAS) update finds that the stored version does not match the expected version. It backs optimistic locking, letting callers retry or converge instead of overwriting a concurrent change.
Functions ¶
func IsNotFound ¶
IsNotFound returns true if any error in the error chain is a ErrNotFound.
func WrapNotFound ¶
WrapNotFound wraps ErrNotFound with the original error from the storage implementation.
Types ¶
type RequestStore ¶
type RequestStore interface {
// Create persists a new request. The request must have a unique ID already assigned.
// Returns ErrAlreadyExists if a request with the same ID already exists.
Create(ctx context.Context, request entity.Request) error
// Get retrieves a request by ID. Returns ErrNotFound if the request is not found.
Get(ctx context.Context, id string) (entity.Request, error)
// Update persists the mutable fields of request if the currently stored version matches
// oldVersion, writing newVersion as the new version. Returns ErrVersionMismatch if the
// stored version does not match (including when the request does not exist).
//
// Version arithmetic is owned by the caller: it computes newVersion (typically oldVersion+1)
// and only assigns request.Version = newVersion after this call succeeds. The store performs
// a pure conditional write and does not read request.Version.
Update(ctx context.Context, request entity.Request, oldVersion, newVersion int32) error
}
RequestStore persists validation requests, keyed by request ID. The reverse index from a validated commit to the request that owns it lives in a separate RequestURIStore (one store per table), so the two concerns can evolve and be backed independently.
type RequestURIStore ¶
type RequestURIStore interface {
// Create records that request id validates the commit uri for queue. Returns ErrAlreadyExists
// if (queue, uri) is already mapped — the signal a caller uses to detect that the commit is
// already being validated by another request.
Create(ctx context.Context, queue, uri, id string) error
// GetIDByURI returns the id of the request validating (queue, uri).
// Returns ErrNotFound if no request is mapped to that commit.
GetIDByURI(ctx context.Context, queue, uri string) (string, error)
}
RequestURIStore is the reverse index from a validated commit to the request that owns it, keyed by (queue, commit URI). It is a separate store from RequestStore because it is a separate table — the two are written independently (no cross-table transaction), keeping the contract satisfiable by key/value backends. The caller orchestrates "create request, then map URI".
type Storage ¶
type Storage interface {
// GetRequestStore returns the RequestStore instance.
GetRequestStore() RequestStore
// GetRequestURIStore returns the RequestURIStore instance.
GetRequestURIStore() RequestURIStore
// Close closes the storage and all underlying connections. Should only be called once at the end of the program.
Close() error
}
Storage is a factory interface that aggregates all entity stores into a single injectable dependency.