Documentation
¶
Overview ¶
Package land lands a motte branch on a ref through a per-ref queue. A ref only ever holds a tree that passed its checks.
Index ¶
Constants ¶
const ( // MaxWait is the longest wait of a read of a land. MaxWait = 60 * time.Second // DefaultReadBudget is the time limit of one read of motte. A replica that opens its packs on first use needs more than // the 2 s default of the client. The limit stays below the 35 s that the client gives a land call. DefaultReadBudget = 10 * time.Second )
const ( CodeConflict = "land_conflict" CodeInvalid = "land_invalid" CodeTimeout = "land_timeout" CodeCheckFailed = "check_failed" CodeStale = "land_stale" CodeInternal = "internal_error" )
The codes of a failed land.
Variables ¶
var ErrNoMergeBase = errors.New("land: the branch has no merge base with the ref")
ErrNoMergeBase means that the first-parent chain of the branch never meets the first-parent chain of the target ref.
Functions ¶
This section is empty.
Types ¶
type Call ¶ added in v0.3.0
type Call struct {
Base string `json:"base"`
Head string `json:"head"`
Tree string `json:"tree"`
BranchGen int64 `json:"branch_generation"`
}
Call is the final land call to motte, stored before it is sent so that a repeat after a restart carries the same values.
type CheckState ¶ added in v0.3.0
CheckState is one required check and its state.
type Config ¶
type Config struct {
URL string
Kid string
Key ed25519.PrivateKey
// ReadBudget is the time limit of one read of motte. Zero means DefaultReadBudget.
ReadBudget time.Duration
}
Config says how ward reaches motte and signs its grants.
type Error ¶ added in v0.3.0
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
}
Error says why a land failed.
type Land ¶ added in v0.3.0
type Land struct {
ID string `json:"id"`
Repo string `json:"repo"`
Ref string `json:"ref"`
Branch string `json:"branch"`
DeleteBranch bool `json:"delete_branch"`
State State `json:"state"`
Tree string `json:"tree"`
Checks []CheckState `json:"checks"`
Tip string `json:"tip"`
Generation int64 `json:"generation"`
FastForward bool `json:"fast_forward"`
Commits []api.LandedCommit `json:"commits"`
BranchDeleted bool `json:"branch_deleted"`
Error *Error `json:"error,omitempty"`
Retries int `json:"retries"`
Mark int64 `json:"mark"`
Attempt int `json:"attempt"`
Call *Call `json:"call,omitempty"`
}
Land is the record of one land. Attempt counts the times that the land reached step 5, and Call is the call of the latest. Mark is the result position after which a fail counts for this land.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service accepts lands and runs the queue of each (repo, ref).
func New ¶
func New(cfg Config, store Store, checks *check.Manager, clock check.Clock, log *slog.Logger) *Service
New returns a service. A nil clock means the wall clock.
func (*Service) Enqueue ¶ added in v0.3.0
Enqueue records a land in state queued and wakes the queue of its ref.
func (*Service) Get ¶ added in v0.3.0
func (s *Service) Get(ctx context.Context, id string, wait time.Duration, known State) (Land, bool, error)
Get returns a land. The baseline state is known, or the state of the land now when known is empty. With a positive wait, Get returns when the state differs from the baseline, or when the wait ends.
type Store ¶ added in v0.3.0
type Store interface {
// InsertLand stores a new land. Lands of one key keep the order of insertion.
InsertLand(ctx context.Context, l Land) error
Land(ctx context.Context, id string) (Land, bool, error)
// NextLand returns the oldest land of the key that has not ended.
NextLand(ctx context.Context, key Key) (Land, bool, error)
SaveLand(ctx context.Context, l Land) error
// UnfinishedKeys returns the key of every land that has not ended.
UnfinishedKeys(ctx context.Context) ([]Key, error)
}
Store is the transactional state of the lands. Each method that writes is one transaction.