maintenance

package
v0.6.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: Apache-2.0 Imports: 20 Imported by: 2

Documentation

Overview

Package maintenance manages automatic repository maintenance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteUnreferencedBlobs

func DeleteUnreferencedBlobs(ctx context.Context, rep MaintainableRepository, opt DeleteUnreferencedBlobsOptions) (int, error)

DeleteUnreferencedBlobs deletes old blobs that are no longer referenced by index entries.

func DropDeletedContents

func DropDeletedContents(ctx context.Context, rep MaintainableRepository, dropDeletedBefore time.Time) error

DropDeletedContents rewrites indexes while dropping deleted contents above certain age.

func IndexCompaction

func IndexCompaction(ctx context.Context, rep MaintainableRepository) error

IndexCompaction rewrites index blobs to reduce their count but does not drop any contents.

func ReportRun

func ReportRun(ctx context.Context, rep MaintainableRepository, runType string, run func() error) error

ReportRun reports timing of a maintenance run and persists it in repository.

func RewriteContents

func RewriteContents(ctx context.Context, rep MaintainableRepository, opt *RewriteContentsOptions) error

RewriteContents rewrites contents according to provided criteria and creates new blobs and index entries to point at the

func Run

func Run(ctx context.Context, runParams RunParameters) error

Run performs maintenance activities for a repository.

func RunExclusive

func RunExclusive(ctx context.Context, rep MaintainableRepository, mode Mode, force bool, cb func(runParams RunParameters) error) error

RunExclusive runs the provided callback if the maintenance is owned by local user and lock can be acquired. Lock is passed to the function, which ensures that every call to Run() is within the exclusive context.

func SetParams

func SetParams(ctx context.Context, rep MaintainableRepository, par *Params) error

SetParams sets the maintenance parameters.

func SetSchedule

func SetSchedule(ctx context.Context, rep MaintainableRepository, s *Schedule) error

SetSchedule updates scheduled maintenance times.

Types

type CycleParams

type CycleParams struct {
	Enabled  bool          `json:"enabled"`
	Interval time.Duration `json:"interval"`
}

CycleParams specifies parameters for a maintenance cycle (quick or full).

type DeleteUnreferencedBlobsOptions

type DeleteUnreferencedBlobsOptions struct {
	Parallel int
	Prefix   blob.ID
	MinAge   time.Duration
	DryRun   bool
}

DeleteUnreferencedBlobsOptions provides option for blob garbage collection algorithm.

type MaintainableRepository

type MaintainableRepository interface {
	Username() string
	Hostname() string
	Time() time.Time
	ConfigFilename() string

	BlobStorage() blob.Storage
	ContentManager() *content.Manager

	GetManifest(ctx context.Context, id manifest.ID, data interface{}) (*manifest.EntryMetadata, error)
	PutManifest(ctx context.Context, labels map[string]string, payload interface{}) (manifest.ID, error)
	FindManifests(ctx context.Context, labels map[string]string) ([]*manifest.EntryMetadata, error)
	DeleteManifest(ctx context.Context, id manifest.ID) error

	DeriveKey(purpose []byte, keyLength int) []byte
}

MaintainableRepository is a subset of Repository required for maintenance tasks.

type Mode

type Mode string

Mode describes the mode of maintenance to perfor

const (
	ModeNone  Mode = "none"
	ModeQuick Mode = "quick"
	ModeFull  Mode = "full"
	ModeAuto  Mode = "auto" // run either quick of full if required by schedule
)

Supported maintenance modes

type NotOwnedError

type NotOwnedError struct {
	Owner string
}

NotOwnedError is returned when maintenance cannot run because it is owned by another user.

func (NotOwnedError) Error

func (e NotOwnedError) Error() string

type Params

type Params struct {
	Owner string `json:"owner"`

	QuickCycle CycleParams `json:"quick"`
	FullCycle  CycleParams `json:"full"`

	SnapshotGC SnapshotGCParams `json:"snapshotGC"`
}

Params is a JSON-serialized maintenance configuration stored in a repository.

func DefaultParams

func DefaultParams() Params

DefaultParams represents default values of maintenance parameters.

func GetParams

func GetParams(ctx context.Context, rep MaintainableRepository) (*Params, error)

GetParams returns repository-wide maintenance parameters.

type RewriteContentsOptions

type RewriteContentsOptions struct {
	Parallel       int
	MinAge         time.Duration
	ContentIDs     []content.ID
	ContentIDRange content.IDRange
	PackPrefix     blob.ID
	ShortPacks     bool
	FormatVersion  int
	DryRun         bool
}

RewriteContentsOptions provides options for RewriteContents

type RunInfo

type RunInfo struct {
	Start   time.Time `json:"start"`
	End     time.Time `json:"end"`
	Success bool      `json:"success,omitempty"`
	Error   string    `json:"error,omitempty"`
}

RunInfo represents information about a single run of a maintenance task.

type RunParameters

type RunParameters struct {
	Mode Mode

	Params *Params
	// contains filtered or unexported fields
}

RunParameters passes essential parameters for maintenance. It is generated by RunExclusive and can't be create outside of its package and is required to ensure all maintenance tasks run under an exclusive lock.

type Schedule

type Schedule struct {
	NextFullMaintenanceTime  time.Time `json:"nextFullMaintenance"`
	NextQuickMaintenanceTime time.Time `json:"nextQuickMaintenance"`

	Runs map[string][]RunInfo `json:"runs"`
}

Schedule keeps track of scheduled maintenance times.

func GetSchedule

func GetSchedule(ctx context.Context, rep MaintainableRepository) (*Schedule, error)

GetSchedule gets the scheduled maintenance times.

func (*Schedule) ReportRun

func (s *Schedule) ReportRun(runType string, info RunInfo)

ReportRun adds the provided run information to the history and discards oldest entried.

type SnapshotGCParams

type SnapshotGCParams struct {
	MinContentAge time.Duration `json:"minAge"`
}

SnapshotGCParams contains parameters for Snapshot Garbage Collection NOTE: Due to layering, the implementation of Snapshot GC is outside of repository package but for simplicity we store it here.

Jump to

Keyboard shortcuts

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