storage

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: Apache-2.0 Imports: 20 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 (
	KeyStorageVersion = ("storage.v1")
	KeySnapshot       = ("snapshots")
	KeyParents        = ("parents")
	KeyParentIDs      = "parentIDs"
	KeyObjectLabels   = "labels"

	KeyID        = ("id")
	KeyKind      = ("kind")
	KeyInodes    = ("inodes")
	KeySize      = ("size")
	KeyCreatedAt = "createdat"
	KeyUpdatedAt = "updatedat"

	KeyLock     = ("lock")
	KeyUpperdir = "upperdir"
)

storage.v1

|ー> snapshots ー> *key*

*key* ー| ー> id

|ー>  kind
|ー>  parents
 |  ->  parentIDs
|ー>  size
|ー>  inodes
|ー>  createdat
|ー>  updatedat
 | ー>  labels
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

This section is empty.

Types

type BoltMetaStore added in v1.6.9

type BoltMetaStore 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 (*BoltMetaStore) Close added in v1.6.9

func (ms *BoltMetaStore) Close() error

Close closes the metastore and any underlying database connections

func (*BoltMetaStore) TransactionContext added in v1.6.9

func (ms *BoltMetaStore) 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 BoltSnapshotStore added in v1.6.9

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

func (*BoltSnapshotStore) Commit added in v1.6.9

func (ss *BoltSnapshotStore) Commit() error

func (*BoltSnapshotStore) CommitActive added in v1.6.9

func (ss *BoltSnapshotStore) CommitActive(ctx context.Context, key, name string, usage snapshots.Usage, opts ...snapshots.Opt) (string, 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 (*BoltSnapshotStore) CreateSnapshot added in v1.6.9

func (ss *BoltSnapshotStore) CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts ...snapshots.Opt) (s Snapshot, err error)

CreateSnapshot inserts a record for an active or view snapshot with the provided parent.

func (*BoltSnapshotStore) CreateSnapshotWithParents added in v1.6.9

func (ss *BoltSnapshotStore) CreateSnapshotWithParents(ctx context.Context, kind snapshots.Kind, key, parent string, parents []string, opts ...snapshots.Opt) (s Snapshot, err error)

func (*BoltSnapshotStore) GetInfo added in v1.6.9

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

func (*BoltSnapshotStore) GetInfoWithUUID added in v1.6.9

func (ss *BoltSnapshotStore) GetInfoWithUUID(ctx context.Context, key string) (string, snapshots.Info, snapshots.Usage, error)

func (*BoltSnapshotStore) GetSnapshot added in v1.6.9

func (ss *BoltSnapshotStore) GetSnapshot(ctx context.Context, key string) (s Snapshot, err error)

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

func (*BoltSnapshotStore) GetSnapshotWithParents added in v1.6.9

func (ss *BoltSnapshotStore) GetSnapshotWithParents(ctx context.Context, key string) (s Snapshot, err error)

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

func (*BoltSnapshotStore) IDMap added in v1.6.9

func (ss *BoltSnapshotStore) IDMap(ctx context.Context) (map[string]string, error)

IDMap returns all the IDs mapped to their key

func (*BoltSnapshotStore) IDMapWithUUID added in v1.6.9

func (ss *BoltSnapshotStore) IDMapWithUUID(ctx context.Context) (map[string]string, error)

IDMap returns all the IDs mapped to their key

func (*BoltSnapshotStore) Remove added in v1.6.9

func (ss *BoltSnapshotStore) Remove(ctx context.Context, key string) (string, snapshots.Kind, 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 (*BoltSnapshotStore) RemoveWithUUID added in v1.6.9

func (ss *BoltSnapshotStore) RemoveWithUUID(ctx context.Context, key string) (string, snapshots.Kind, error)

func (*BoltSnapshotStore) Rollback added in v1.6.9

func (ss *BoltSnapshotStore) Rollback() error

func (*BoltSnapshotStore) UpdateInfo added in v1.6.9

func (ss *BoltSnapshotStore) UpdateInfo(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error)

UpdateInfo updates an existing snapshot info's data

func (*BoltSnapshotStore) WalkInfo added in v1.6.9

func (ss *BoltSnapshotStore) WalkInfo(ctx context.Context, fn snapshots.WalkFunc, fs ...string) 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.

type EtcdSnapshotStore added in v1.6.9

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

func (*EtcdSnapshotStore) Commit added in v1.6.9

func (ss *EtcdSnapshotStore) Commit() error

func (*EtcdSnapshotStore) CommitActive added in v1.6.9

func (ss *EtcdSnapshotStore) CommitActive(ctx context.Context, key, name string, usage snapshots.Usage, opts ...snapshots.Opt) (string, error)

func (*EtcdSnapshotStore) CreateSnapshot added in v1.6.9

func (ss *EtcdSnapshotStore) CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts ...snapshots.Opt) (s Snapshot, err error)

func (*EtcdSnapshotStore) GetActiveSnapshot added in v1.6.9

func (ss *EtcdSnapshotStore) GetActiveSnapshot(ctx context.Context, key string) (s Snapshot, err error)

func (*EtcdSnapshotStore) GetInfo added in v1.6.9

func (*EtcdSnapshotStore) GetSnapshot added in v1.6.9

func (ss *EtcdSnapshotStore) GetSnapshot(ctx context.Context, key string) (s Snapshot, err error)

func (*EtcdSnapshotStore) IDMap added in v1.6.9

func (ss *EtcdSnapshotStore) IDMap(ctx context.Context) (map[string]string, error)

IDMap returns all the IDs mapped to their key

func (*EtcdSnapshotStore) Remove added in v1.6.9

func (ss *EtcdSnapshotStore) Remove(ctx context.Context, key string) (string, snapshots.Kind, error)

func (*EtcdSnapshotStore) Rollback added in v1.6.9

func (ss *EtcdSnapshotStore) Rollback() error

func (*EtcdSnapshotStore) UpdateInfo added in v1.6.9

func (ss *EtcdSnapshotStore) UpdateInfo(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error)

func (*EtcdSnapshotStore) WalkInfo added in v1.6.9

func (ss *EtcdSnapshotStore) WalkInfo(ctx context.Context, fn snapshots.WalkFunc, fs ...string) error

type EtcdStore added in v1.6.9

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

func (*EtcdStore) Close added in v1.6.9

func (ms *EtcdStore) Close() error

func (*EtcdStore) TransactionContext added in v1.6.9

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

type EtcdTransactor added in v1.6.9

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

type MetaStore

type MetaStore interface {
	TransactionContext(ctx context.Context, writable bool) (context.Context, Transactor, error)
	Close() error
}

func NewBoltMetaStore added in v1.6.9

func NewBoltMetaStore(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 NewEtcdStore added in v1.6.9

func NewEtcdStore(root string, c *clientv3.Config) (MetaStore, error)

type Snapshot

type Snapshot struct {
	Kind      snapshots.Kind
	ID        string
	ParentIDs []string
}

Snapshot hold the metadata for an active or view snapshot transaction. The ParentIDs hold the snapshot identifiers for the committed snapshots this active or view 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.

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

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

	UpdateInfo(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error)

	WalkInfo(ctx context.Context, fn snapshots.WalkFunc, fs ...string) error

	GetSnapshot(ctx context.Context, key string) (s Snapshot, err error)

	CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts ...snapshots.Opt) (s Snapshot, err error)

	Remove(ctx context.Context, key string) (string, snapshots.Kind, error)

	CommitActive(ctx context.Context, key, name string, usage snapshots.Usage, opts ...snapshots.Opt) (string, error)

	IDMap(ctx context.Context) (map[string]string, error)
}

Transactor is used to finalize an active transaction.

Jump to

Keyboard shortcuts

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