gc

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package gc implements garbage collection for blob stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Protect

func Protect(ctx context.Context, g bs.Getter, k Keep, ref bs.Ref, traverse ProtectFunc) error

Protect adds a given Ref, and all Refs reachable from it, to a Keep. An optional callback is responsible for traversing the given Ref and reporting its child Refs (if any), plus their own optional traversal functions.

func Run

func Run(ctx context.Context, store bs.DeleterStore, k Keep) error

Run runs a garbage collection on store, deleting all refs not protected by k. See Protect.

Types

type Keep

type Keep interface {
	Add(context.Context, bs.Ref) error
	Contains(context.Context, bs.Ref) (bool, error)
}

Keep is a set of refs to protect from garbage collection.

type ProtectFunc

type ProtectFunc = func(context.Context, bs.Getter, bs.Ref) ([]ProtectPair, error)

ProtectFunc is the type of the callback passed to Protect. It is responsible for traversing a given ref to other refs that must also be protected. It should not do this recursively: that's handled within Protect itself. (However, it safely may, as long as it does its own loop detection. [Assuming loops are even a thing in content-addressable storage systems, which they probably aren't.]) It produces the refs it finds, along with their own ProtectFuncs.

type ProtectPair

type ProtectPair struct {
	Ref bs.Ref
	F   ProtectFunc
}

ProtectPair is the type of an item returned by a ProtectFunc. It is a ref to add to a Keep, plus an optional ProtectFunc for traversing the ref and finding additional refs to protect.

type Store

type Store struct {
	S               bs.DeleterStore
	Refs, Deletions int
}

Store is a DeleterStore that delegates calls to a nested DeleterStore and can count refs and deletions during a call to Run.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, ref bs.Ref) error

Delete implements bs.DeleterStore.

func (*Store) Get

func (s *Store) Get(ctx context.Context, ref bs.Ref) (bs.Blob, error)

Get implements bs.Getter.Get.

func (*Store) ListRefs

func (s *Store) ListRefs(ctx context.Context, start bs.Ref, f func(bs.Ref) error) error

ListRefs implements bs.Getter.ListRefs.

func (*Store) Put

func (s *Store) Put(ctx context.Context, blob bs.Blob) (bs.Ref, bool, error)

Put implements bs.Store.Put.

Jump to

Keyboard shortcuts

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