land

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 25 Imported by: 0 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

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

View Source
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
)
View Source
const (
	Queued   = wardapi.LandQueued
	Checking = wardapi.LandChecking
	Landing  = wardapi.LandLanding
	Landed   = wardapi.LandLanded
	Failed   = wardapi.LandFailed
)
View Source
const (
	CodeConflict    = wardapi.CodeLandConflict
	CodeInvalid     = wardapi.CodeLandInvalid
	CodeRequired    = wardapi.CodeRequiredMissing
	CodeTimeout     = wardapi.CodeLandTimeout
	CodeCheckFailed = wardapi.CodeCheckFailed
	CodeStale       = wardapi.CodeLandStale
	CodeInternal    = wardapi.CodeInternal
)

The codes of a failed land.

Variables

View Source
var ErrIDInUse = errors.New("land: the id belongs to another land")

ErrIDInUse means that the ID of a request belongs to a land of another repository, ref or branch.

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

View Source
var ErrRefused = errors.New("land: the change cannot land")

ErrRefused means that motte cannot land the change of a request on its own: the range is too large for one land, holds a merge commit, or does not reach the base.

Functions

func RefMatches added in v0.10.0

func RefMatches(pattern, ref string) bool

RefMatches reports whether pattern, a ref name or a prefix that ends in *, names ref.

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"`
	// ID is the land id that motte sees when the call lands a batch. It is empty for a call of one land.
	ID string `json:"id,omitempty"`
	// Tip, FastForward and Commits are the part of a batch that belongs to this land.
	Tip         string             `json:"tip,omitempty"`
	FastForward bool               `json:"fast_forward,omitempty"`
	Commits     []api.LandedCommit `json:"commits,omitempty"`
}

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

type CheckState = wardapi.LandCheck

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
	// Refs lists the ref patterns that a land may name: a stored ref name, or a prefix that ends in *. Nil means main only.
	Refs []string
	// Required lists the checks that the check file must hold for a land onto a matching ref.
	Required []Requirement
}

Config says how ward reaches motte and signs its grants.

type Error added in v0.3.0

type Error = wardapi.Error

Error says why a land failed.

type Key added in v0.3.0

type Key struct{ Repo, Ref string }

Key names the queue of a land.

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"`
	Base          string             `json:"base"`
	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 Request

type Request struct {
	// ID is chosen by the caller. A repeat of an accepted ID answers the land that it made. Empty means ward chooses one.
	ID           string
	Repo         string
	Ref          string
	Branch       string
	Base         string
	DeleteBranch bool
}

Request names the branch to land and where.

type Requirement added in v0.10.0

type Requirement struct {
	Repo   string   `json:"repo"`
	Ref    string   `json:"ref"`
	Checks []string `json:"checks"`
}

Requirement says that the check file that judges a land of Repo onto a ref that Ref names must have a check of each name in Checks. Ref is a stored ref name, or a prefix that ends in *.

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

func (s *Service) Enqueue(ctx context.Context, req Request) (Land, error)

Enqueue records a land in state queued and wakes the queue of its ref. A repeat of a request ID answers the land that the first request made, and ErrIDInUse answers a request that differs from it.

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.

func (*Service) RefAllowed added in v0.9.0

func (s *Service) RefAllowed(ref string) bool

RefAllowed reports whether a pattern of the configuration names ref.

func (*Service) Repeat added in v0.9.0

func (s *Service) Repeat(ctx context.Context, req Request) (Land, bool, error)

Repeat returns the land that req.ID made when it exists and agrees with req.

func (*Service) Start added in v0.3.0

func (s *Service) Start(ctx context.Context) error

Start resumes every land that has not ended. The queues stop when ctx ends.

func (*Service) Wait added in v0.3.0

func (s *Service) Wait()

Wait returns when every queue has stopped. Call it after the context of Start ends.

type State added in v0.3.0

type State = wardapi.LandState

State is the state of a land.

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)
	// NextLands returns up to n of the oldest lands of the key that have not ended, oldest first.
	NextLands(ctx context.Context, key Key, n int) ([]Land, 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.

Directories

Path Synopsis
Package landtest is the conformance suite of land.Store.
Package landtest is the conformance suite of land.Store.

Jump to

Keyboard shortcuts

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