Documentation
¶
Overview ¶
Package sqlcore holds the checks that the SQL backends of meta.Store run after a write changed no row: they read the cause and pick the error. A backend keeps its SQL and gives these functions a Probe.
Index ¶
- Constants
- func AckLandLost(ctx context.Context, p Probe, repo, id string) error
- func ClaimLost(ctx context.Context, p Probe, id string) error
- func FenceLost(ctx context.Context, p Probe, ws string, epoch uint64, repo string) error
- func FlushLost(ctx context.Context, p Probe, ws string, epoch uint64) error
- func LandLeaseBusy(ctx context.Context, p Probe, repo, ref string, now time.Time) (time.Time, error)
- func LandLeaseLost(ctx context.Context, p Probe, repo, ref, owner string, now time.Time) error
- func LeaseLost(ctx context.Context, p Probe, id string, partition int) error
- func NextSeq(param string) string
- func OpHeadsLost(ctx context.Context, p Probe, ws string, epoch uint64, repo string) error
- func RefConflict(ctx context.Context, p Probe, repo, name string) error
- func RefLost(ctx context.Context, p Probe, node bool, ws string, epoch uint64, ...) error
- type Migration
- type Probe
Constants ¶
const BumpGeneration = `UPDATE counters SET value = value + 1 WHERE name = 'ref_generation'`
BumpGeneration takes the next ref generation. Every ref write has it as its first statement.
const BumpSeq = `` /* 152-byte string literal not displayed */
BumpSeq takes the number that the event insert just used, and only when that insert changed a row, so a failed write leaves no gap even in a batch that does not roll back.
const FenceHolds = `EXISTS (SELECT 1 FROM workspaces WHERE id = ?1 AND epoch = ?2 AND repo = ?3 AND deleted_at IS NULL)`
FenceHolds is the fence of every write. ?1, ?2 and ?3 are the workspace, the epoch and the repo.
const LeaseHeld = `EXISTS (SELECT 1 FROM land_leases WHERE repo = ?1 AND ref = ?2 AND owner = ?3 AND lease_until > ?4)`
LeaseHeld holds when ?3 owns the land lease of repo ?1 and ref ?2 at time ?4.
const LeaseOK = `EXISTS (SELECT 1 FROM land_leases WHERE repo = ?2 AND ref = ?3 AND owner = ?4 AND lease_until > ?5)`
LeaseOK is LeaseHeld for the statements of LandRef, which number repo, ref, owner and now as ?2, ?3, ?4 and ?5.
const NextGeneration = `(SELECT value FROM counters WHERE name = 'ref_generation')`
NextGeneration is the generation that BumpGeneration took.
Variables ¶
This section is empty.
Functions ¶
func AckLandLost ¶ added in v0.22.0
AckLandLost is the error of an ack that changed no row: ErrNotFound for a missing land, and ErrLandPending for a land that is not done.
func ClaimLost ¶ added in v0.22.0
ClaimLost is the error of a claim that changed no row: ErrGone for a deleted workspace and ErrWorkspaceConflict for one that another owner or repo holds.
func FenceLost ¶
FenceLost reports a failed fenced write as ErrClaimLost when the fence no longer holds. It returns nil when the fence holds, so the write lost on its own condition.
func LandLeaseBusy ¶ added in v0.22.0
func LandLeaseBusy(ctx context.Context, p Probe, repo, ref string, now time.Time) (time.Time, error)
LandLeaseBusy is the answer to an acquire that changed no row: ErrLeaseHeld, and the time that the holder's lease ends, or now when the row is gone.
func LandLeaseLost ¶
LandLeaseLost returns meta.ErrLeaseHeld when owner no longer holds the land lease of the ref, and nil when it does, so the write lost on its own condition.
func NextSeq ¶ added in v0.36.0
NextSeq is the number of the next event of the partition in the parameter at param.
func OpHeadsLost ¶
OpHeadsLost is the error of an op heads swap that changed no row.
func RefConflict ¶
RefConflict is the conflict of a ref write that lost on its own condition: the current ref, or none when it is missing.
Types ¶
type Migration ¶ added in v0.36.0
type Migration struct{ Version, Script string }
Migration is one schema step of the SQLite dialect. Version is the file name without the suffix.
func Migrations ¶ added in v0.36.0
Migrations returns the schema steps in the order to apply them. The SQLite backends share them.
type Probe ¶
type Probe interface {
// Fence returns meta.ErrNotFound for a workspace that does not exist.
Fence(ctx context.Context, ws string) (meta.Fence, error)
// OpHeads returns meta.ErrNotFound for a workspace with no op heads.
OpHeads(ctx context.Context, ws string) (meta.OpHeads, error)
// Ref returns meta.ErrNotFound for a missing ref.
Ref(ctx context.Context, repo, name string) (meta.Ref, error)
// CursorExists reports whether the subscription has a cursor row for the partition.
CursorExists(ctx context.Context, id string, partition int) (bool, error)
// LandLeaseHeld reports whether owner holds the land lease of the ref at now.
LandLeaseHeld(ctx context.Context, repo, ref, owner string, now time.Time) (bool, error)
// LandLeaseEnd returns when the land lease of the ref ends, or meta.ErrNotFound when it has no row.
LandLeaseEnd(ctx context.Context, repo, ref string) (time.Time, error)
// LandItem returns meta.ErrNotFound for a land that does not exist.
LandItem(ctx context.Context, repo, id string) (meta.LandItem, error)
}
Probe reads the rows that the checks need. Each method wraps a database error with the name of its backend.