chain

package
v3.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package chain builds recovery chains from backup manifests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPartial

func LoadPartial(
	ctx context.Context,
	store storage.Storage,
	opts ...Option,
) (*Chain, []Unreadable, error)

LoadPartial builds the chain from the manifests it could read and returns the ones it could not, so that a diagnostic caller (tt backup verify) reports a single broken object instead of going blind on the whole storage.

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain is the in-memory view of all manifests in one storage.

func Build

func Build(manifests []*backup.ClusterManifest, opts ...Option) (*Chain, error)

Build groups manifests, attaches own and inherited chain problems, and stitches cluster recovery points.

func Load

func Load(ctx context.Context, store storage.Storage, opts ...Option) (*Chain, error)

Load reads every stored manifest and builds a fully marked chain. A manifest that cannot be read or decoded fails the whole load: a chain silently missing a link would send its caller down a broken recovery path. Callers that diagnose the storage rather than recover from it use LoadPartial.

func (*Chain) ClusterPoints

func (c *Chain) ClusterPoints() []ClusterPoint

ClusterPoints returns cluster recovery points ordered by effective timestamp.

func (*Chain) Groups

func (c *Chain) Groups() []Group

Groups returns backup groups from oldest full backup to newest.

func (*Chain) Latest

func (c *Chain) Latest() *Entry

Latest returns the last entry in chain order, regardless of its Problems.

func (*Chain) Manifests

func (c *Chain) Manifests() []*backup.ClusterManifest

Manifests returns every loaded manifest, including problematic ones.

func (*Chain) PlanFor

func (c *Chain) PlanFor(point ClusterPoint) (Plan, error)

PlanFor builds per-replicaset backup paths for a cluster recovery point, or errors if p is not a point produced by this chain.

func (*Chain) Problems

func (c *Chain) Problems() []*Problem

Problems returns a flat list of all own and inherited entry problems.

func (*Chain) Resolve

func (c *Chain) Resolve(target time.Time) Resolution

Resolve maps a requested recovery time to a cluster recovery point.

type ClusterPoint

type ClusterPoint struct {
	// Name is the manager-generated common point name.
	Name string
	// Timestamp is the earliest timestamp among the shard points.
	Timestamp time.Time
	// Topology of the segment this point was stitched in, constant within it.
	// It lists every backed-up replicaset, including those a selection left out
	// of Shards; a consumer that cares only about the restored ones narrows it
	// by the keys of Shards. Consumers compare it against the live cluster;
	// chain does not.
	Topology backup.Topology
	// Shards maps a replicaset UUID to its position at this point.
	Shards map[string]Position
}

ClusterPoint joins equally named points from every replicaset in a segment.

type Entry

type Entry struct {
	// Manifest is the original cluster manifest.
	Manifest *backup.ClusterManifest
	// Problems is empty only when this manifest is usable for recovery.
	Problems []*Problem
}

Entry is one manifest and the chain problems that make it unusable.

type Group

type Group struct {
	// Entries starts with the full backup and follows previous_backup_id.
	Entries []*Entry
}

Group is a cascade-deletion unit rooted at one full backup.

type Option

type Option func(*buildOptions)

Option tunes how a chain is built.

func WithSelection

func WithSelection(selection *Selection) Option

WithSelection stitches cluster points over the selected replicasets only: a point name becomes a cluster point once it is present on each selected replicaset, whatever the others carry, and the point holds positions for the selected ones alone. Grouping and chain problems are unaffected - every manifest is still read whole.

type Plan

type Plan struct {
	// Point is the recovery target.
	Point ClusterPoint
	// Shards maps a replicaset UUID to the backup path needed for it.
	Shards map[string]ShardPlan
}

Plan describes all backups required to recover one cluster point.

type Position

type Position struct {
	// ReplicaID is the source instance identifier in the replicaset.
	ReplicaID uint32
	// LSN is the xlog position on that replica.
	LSN uint64
}

Position is a recovery position inside one replicaset.

func (Position) String

func (p Position) String() string

String renders the position the way tt restore apply takes it on the command line, so an error naming one can be acted on directly.

type Problem

type Problem struct {
	// Kind classifies the problem.
	Kind ProblemKind
	// BackupID identifies the manifest whose recovery path is affected.
	BackupID string
	// Inherited reports that the problem originated in an ancestor.
	Inherited bool
	// Detail identifies the missing, conflicting, or mismatched link.
	Detail string
}

Problem is a chain problem attached to one manifest.

type ProblemKind

type ProblemKind int

ProblemKind identifies a manifest's place in a broken chain.

const (
	ProblemOrphan ProblemKind = iota
	ProblemFork
	ProblemVclockMismatch
	ProblemInvalidManifest
)

type Resolution

type Resolution struct {
	// Status explains whether Point can be used.
	Status Status
	// Point is selected for StatusOK, or the last healthy point before a break.
	Point *ClusterPoint
	// Before and After are nearest points around an unresolved target time.
	Before *ClusterPoint
	After  *ClusterPoint
}

Resolution is the result of resolving a requested recovery time.

type Selection

type Selection struct {
	// contains filtered or unexported fields
}

Selection narrows the replicasets a cluster point is stitched over. It is expressed as a set of instance names because a manifest knows instances and replicaset UUIDs, while the operator names replicasets the way the cluster config does. A nil *Selection covers every replicaset.

func SelectInstances

func SelectInstances(names []string) *Selection

SelectInstances builds a selection from instance names. A replicaset is selected when at least one of its topology instances carries one of them.

type ShardPlan

type ShardPlan struct {
	// Backups starts with a full backup and continues with incrementals.
	Backups []*backup.ClusterManifest
	// TrimTo limits the final incremental to the requested position.
	TrimTo *Position
}

ShardPlan is an ordered backup path for one replicaset.

type Status

type Status int

Status describes the result of resolving a requested recovery time.

const (
	StatusOK Status = iota
	StatusTopologyBoundary
	StatusNoRecoveryPoint
	StatusChainBroken
	StatusOutOfRange
)

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON encodes a status as its string.

func (Status) String

func (s Status) String() string

String returns the status name.

type Unreadable

type Unreadable struct {
	// Key is the storage key of the manifest.
	Key string
	// Err explains why the manifest could not be used.
	Err error
}

Unreadable is a listed manifest that could not be turned into a chain entry.

Jump to

Keyboard shortcuts

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