generation

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 16 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

Index

Constants

View Source
const (
	MinimumReserveBytes = int64(512 << 20)
	MinimumMarginBytes  = int64(1 << 30)
	MinimumFreePermille = uint64(150)
)

Variables

View Source
var (
	ErrNoCurrent         = errors.New("generation store has no current generation")
	ErrNoBackup          = errors.New("generation store has no backup generation")
	ErrInvalidID         = errors.New("invalid generation id")
	ErrInsufficientSpace = errors.New("insufficient space for candidate generation")
	// ErrPublishInProgress reports that another process holds the store's
	// publish lock. A store is shared by every invocation over one state
	// directory, and a rebuild takes minutes: waiting would look like a hang.
	ErrPublishInProgress = errors.New("another process is publishing into this generation store")
)

Functions

This section is empty.

Types

type BuildFunc

type BuildFunc func(context.Context, string) error

type Config

type Config struct {
	ReserveBytes  int64
	MarginBytes   int64
	FreePermille  uint64
	DatabaseFile  string
	FaultInjector FaultInjector
}

func DefaultConfig

func DefaultConfig() Config

func (Config) IsZero

func (config Config) IsZero() bool

IsZero reports whether the caller left the configuration untouched, so a component can fall back to DefaultConfig. Config carries a func field, so it cannot be compared with ==.

type FaultInjector

type FaultInjector func(Operation, string) error

type Generation

type Generation struct {
	ID           string
	Path         string
	DatabasePath string
}

type Operation

type Operation string
const (
	OperationAllocateReserve  Operation = "allocate_reserve"
	OperationSyncFile         Operation = "sync_file"
	OperationSyncDirectory    Operation = "sync_directory"
	OperationRenameGeneration Operation = "rename_generation"
	OperationWriteCurrent     Operation = "write_current"
	OperationRenameCurrent    Operation = "rename_current"
	OperationWriteBackup      Operation = "write_backup"
	OperationRenameBackup     Operation = "rename_backup"
	OperationRemoveGeneration Operation = "remove_generation"
)

type Publication

type Publication struct {
	Generation Generation
	PreviousID string
	Space      SpaceAssessment
}

type PublishRequest

type PublishRequest struct {
	ID                     string
	EstimatedSnapshotBytes int64
	Build                  BuildFunc
	Validate               ValidateFunc
}

type SpaceAssessment

type SpaceAssessment struct {
	FilesystemBytes     uint64
	AvailableBytes      uint64
	ActiveDatabaseBytes uint64
	SnapshotBytes       uint64
	RequiredBytes       uint64
}

type Store

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

func New

func New(root string, config Config) (*Store, error)

func (*Store) Backup

func (store *Store) Backup(ctx context.Context) (Generation, error)

Backup returns the generation a rollback would restore. BACKUP is interpreted, never repaired: writing BACKUP and CURRENT takes two renames that cannot be made atomic together, so a crash between them can leave BACKUP pointing at the same id as CURRENT. That state, and a BACKUP pointing at an id no longer present under generations/, both mean "no backup" rather than a corrupt one.

func (*Store) CheckSpace

func (store *Store) CheckSpace(ctx context.Context, estimatedSnapshotBytes int64) (SpaceAssessment, error)

func (*Store) Current

func (store *Store) Current(ctx context.Context) (Generation, error)

func (*Store) Discard

func (store *Store) Discard(ctx context.Context) ([]string, error)

Discard removes every published generation and both pointers, and returns the ids it removed, ordered.

The pointers go first. A crash between the two halves must leave a store that reads as empty and rebuilds cleanly, never one whose CURRENT names a directory that is gone: NextID skips the ids still on disk, and a later Discard removes what this one did not reach. The space reserve is released too, because it exists to complete a publication and there is none left to complete.

func (*Store) DiscardExcept

func (store *Store) DiscardExcept(ctx context.Context, id string) ([]string, error)

DiscardExcept removes every generation but id, and returns the ids it removed, ordered.

The BACKUP pointer goes with them: what it named is being removed, and a pointer that survives its generation is the one state this store refuses to keep. A rollback has nothing to restore afterwards, which is the whole point of asking for one generation.

func (*Store) List

func (store *Store) List(ctx context.Context) ([]Generation, error)

List returns every published generation, ordered by id.

func (*Store) NextID

func (store *Store) NextID(ctx context.Context) (string, error)

NextID returns the id a publication would use after the active one: the active id plus one, zero-padded to six digits, skipping the reserved "000000". Without a current generation it returns the first valid id. Any candidate already present on disk is skipped too, so that two rebuilds run back to back never collide on the same id.

func (*Store) Prepare

func (store *Store) Prepare(ctx context.Context) error

func (*Store) Prune

func (store *Store) Prune(ctx context.Context) ([]string, error)

Prune removes every generation that is neither active nor backup and returns the ids it removed, ordered. Without a current generation there is nothing to protect an active or a backup against, so Prune refuses to delete anything rather than guess.

func (*Store) Publish

func (store *Store) Publish(ctx context.Context, request PublishRequest) (publication Publication, returnErr error)

func (*Store) Restore

func (store *Store) Restore(ctx context.Context, id string, validate ValidateFunc) (returnErr error)

type ValidateFunc

type ValidateFunc func(context.Context, Generation) error

Jump to

Keyboard shortcuts

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