storage

package
v1.0.0-alpha0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2017 License: Apache-2.0, CC-BY-SA-4.0 Imports: 9 Imported by: 0

Documentation

Overview

Package storage provides a metadata storage implementation for snapshot drivers. Drive implementations are responsible for starting and managing transactions using the defined context creator. This storage package uses BoltDB for storing metadata. Access to the raw boltdb transaction is not provided, but the stored object is provided by the proto subpackage.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoTransaction is returned when an operation is attempted with
	// a context which is not inside of a transaction.
	ErrNoTransaction = errors.New("no transaction in context")
)

Functions

func CommitActive

func CommitActive(ctx context.Context, key, name string, usage snapshot.Usage) (id string, err error)

CommitActive renames the active snapshot transaction referenced by `key` as a committed snapshot referenced by `Name`. The resulting snapshot will be committed and readonly. The `key` reference will no longer be available for lookup or removal. The returned string identifier for the committed snapshot is the same identifier of the original active snapshot. The provided context must contain a writable transaction.

func GetInfo

func GetInfo(ctx context.Context, key string) (string, snapshot.Info, snapshot.Usage, error)

GetInfo returns the snapshot Info directly from the metadata. Requires a context with a storage transaction.

func Remove

func Remove(ctx context.Context, key string) (id string, k snapshot.Kind, err error)

Remove removes a snapshot from the metastore. The string identifier for the snapshot is returned as well as the kind. The provided context must contain a writable transaction.

func WalkInfo

func WalkInfo(ctx context.Context, fn func(context.Context, snapshot.Info) error) error

WalkInfo iterates through all metadata Info for the stored snapshots and calls the provided function for each. Requires a context with a storage transaction.

Types

type Active

type Active struct {
	ID        string
	ParentIDs []string
	Readonly  bool
}

Active hold the metadata for an active snapshot transaction. The ParentIDs hold the snapshot identifiers for the committed snapshots this active is based on. The ParentIDs are ordered from the lowest base to highest, meaning they should be applied in order from the first index to the last index. The last index should always be considered the active snapshots immediate parent.

func CreateActive

func CreateActive(ctx context.Context, key, parent string, readonly bool) (a Active, err error)

CreateActive creates a new active snapshot transaction referenced by the provided key. The new active snapshot will have the provided parent. If the readonly option is given, the active snapshot will be marked as readonly and can only be removed, and not committed. The provided context must contain a writable transaction.

func GetActive

func GetActive(ctx context.Context, key string) (a Active, err error)

GetActive returns the metadata for the active snapshot transaction referenced by the given key. Requires a context with a storage transaction.

type MetaStore

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

MetaStore is used to store metadata related to a snapshot driver. The MetaStore is intended to store metadata related to name, state and parentage. Using the MetaStore is not required to implement a snapshot driver but can be used to handle the persistence and transactional complexities of a driver implementation.

func NewMetaStore

func NewMetaStore(dbfile string) (*MetaStore, error)

NewMetaStore returns a snapshot MetaStore for storage of metadata related to a snapshot driver backed by a bolt file database. This implementation is strongly consistent and does all metadata changes in a transaction to prevent against process crashes causing inconsistent metadata state.

func (*MetaStore) TransactionContext

func (ms *MetaStore) TransactionContext(ctx context.Context, writable bool) (context.Context, Transactor, error)

TransactionContext creates a new transaction context. The writable value should be set to true for transactions which are expected to mutate data.

type Transactor

type Transactor interface {
	// Commit commits any changes made during the transaction. On error a
	// caller is expected to clean up any resources which would have relied
	// on data mutated as part of this transaction. Only writable
	// transactions can commit, non-writable must call Rollback.
	Commit() error

	// Rollback rolls back any changes made during the transaction. This
	// must be called on all non-writable transactions and aborted writable
	// transaction.
	Rollback() error
}

Transactor is used to finalize an active transaction.

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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