Documentation
¶
Overview ¶
Package generation owns the on-disk store of published graph generations: how one is built, published, backed up and rolled back.
Index ¶
- Constants
- Variables
- func GenerationsDir(root string) string
- type BuildFunc
- type Config
- type FaultInjector
- type Generation
- type Operation
- type Publication
- type PublishRequest
- type PublishStep
- type SpaceAssessment
- type Store
- func (store *Store) Backup(ctx context.Context) (Generation, error)
- func (store *Store) CheckSpace(ctx context.Context, estimatedSnapshotBytes int64) (SpaceAssessment, error)
- func (store *Store) Current(ctx context.Context) (Generation, error)
- func (store *Store) Discard(ctx context.Context) (removed []string, returnErr error)
- func (store *Store) DiscardExcept(ctx context.Context, id string) (removed []string, returnErr error)
- func (store *Store) List(ctx context.Context) ([]Generation, error)
- func (store *Store) NextID(ctx context.Context) (string, error)
- func (store *Store) Prepare(ctx context.Context) error
- func (store *Store) Prune(ctx context.Context) (removed []string, returnErr error)
- func (store *Store) Publish(ctx context.Context, request PublishRequest) (publication Publication, returnErr error)
- func (store *Store) Restore(ctx context.Context, id string, validate ValidateFunc) (returnErr error)
- type ValidateFunc
Constants ¶
const ( MinimumReserveBytes = int64(512 << 20) MinimumMarginBytes = int64(1 << 30) MinimumFreePermille = uint64(150) )
Variables ¶
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 ¶
func GenerationsDir ¶ added in v0.3.6
GenerationsDir answers where a store keeps its generations. Three callers joined the literal themselves before this existed, which is two too many for a path that names an on-disk layout.
Types ¶
type Config ¶
type Config struct {
ReserveBytes int64
MarginBytes int64
FreePermille uint64
DatabaseFile string
FaultInjector FaultInjector
}
func DefaultConfig ¶
func DefaultConfig() Config
type FaultInjector ¶
type Generation ¶
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
// Steps is empty when Publish failed.
Steps []PublishStep
}
type PublishRequest ¶
type PublishRequest struct {
ID string
EstimatedSnapshotBytes int64
Build BuildFunc
Validate ValidateFunc
}
type PublishStep ¶ added in v0.10.0
PublishStep is how long one step of Publish took. The steps follow one another and together account for the whole call, so what a reader sees as "publish" can be told apart from the stages the caller measures inside it.
type SpaceAssessment ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
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) Discard ¶
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) (removed []string, returnErr 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.
id must still be the active generation when the removal starts. The caller read it before asking, and a publication that landed in between would otherwise have its generation removed with CURRENT still naming it.
func (*Store) List ¶
func (store *Store) List(ctx context.Context) ([]Generation, error)
List returns every published generation, ordered by id.
func (*Store) NextID ¶
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) Prune ¶
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)
type ValidateFunc ¶
type ValidateFunc func(context.Context, Generation) error