storage

package
v0.1.0-dev10 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = errors.New("record already exists")

ErrAlreadyExists is returned by storage implementations when attempting to create a record that already exists.

View Source
var ErrNotFound = errors.New("record not found")

ErrNotFound is returned by storage implementations when the requested record is not found in the database.

View Source
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

func IsNotFound(err error) bool

IsNotFound returns true if any error in the error chain is a ErrNotFound.

func WrapNotFound

func WrapNotFound(err error) error

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.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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