land

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 24 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
	// DefaultBatchMax is the most lands that one check run judges when Config.BatchMax is zero.
	DefaultBatchMax = 8
)
View Source
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

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.

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"`
	// 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 struct {
	Name  string      `json:"name"`
	State check.State `json:"state"`
}

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
	// BatchMax is the most lands that one check run judges. Zero means DefaultBatchMax, and 1 judges each land alone.
	BatchMax int
}

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 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"`
	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 {
	Repo         string
	Ref          string
	Branch       string
	DeleteBranch bool
}

Request names the branch to land and where.

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.

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) 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 string

State is the state of a land.

const (
	Queued   State = "queued"
	Checking State = "checking"
	Landing  State = "landing"
	Landed   State = "landed"
	Failed   State = "failed"
)

func (State) Ended added in v0.3.0

func (s State) Ended() bool

Ended reports whether the land has ended.

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.

Jump to

Keyboard shortcuts

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