db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2016 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// DefaultFilesystem is the default filesystem in volplugin. Overridden by policy.
	DefaultFilesystem = "ext4"
	// GlobalConfigName is the path to the global configuration under the db prefix.
	GlobalConfigName = "global-config"

	// DefaultGlobalTTL is the TTL used when no TTL exists.
	DefaultGlobalTTL = 30 * time.Second
	// DefaultTimeout is the standard command timeout when none is provided.
	DefaultTimeout = 10 * time.Minute

	// TimeoutFixBase is our base timeout -- timeouts supplied to the user are multiplied against this for storage and evaluation.
	TimeoutFixBase = time.Minute
	// TTLFixBase is our base TTL. TTLs supplied to the user are multipled against this for storage and evaulation.
	TTLFixBase = time.Second
	// DefaultMountPath is the standard mount path for all mounts.
	DefaultMountPath = "/mnt"
)

Variables

View Source
var (
	// RuntimeSchema defines json schema for runtime configuration
	RuntimeSchema = `` /* 459-byte string literal not displayed */

	// PolicySchema defines the json schema for policy
	PolicySchema = `` /* 612-byte string literal not displayed */

	//VolumeSchema defines the json schema for volume
	VolumeSchema = `` /* 578-byte string literal not displayed */

)
View Source
var DefaultDrivers = map[string]*BackendDrivers{
	"ceph": {"ceph", "ceph", "ceph"},
	"nfs":  {"", "nfs", ""},
}

DefaultDrivers are macro type definitions for backend drivers.

View Source
var DefaultFilesystems = map[string]string{
	"ext4": "mkfs.ext4 -m0 %",
}

DefaultFilesystems is a map of our default supported filesystems. Overridden by policy.

Functions

This section is empty.

Types

type BackendDrivers

type BackendDrivers struct {
	CRUD     string `json:"crud"`
	Mount    string `json:"mount"`
	Snapshot string `json:"snapshot"`
}

BackendDrivers is a struct containing all the drivers used under this policy

type Client

type Client interface {
	// Get the entity. Will copy the contents of the JSON into the entity for
	// use.
	Get(Entity) error
	// Set the entity. Will persist the entity to etcd based on the path it
	// provides. (See Path())
	Set(Entity) error
	// Delete the entity from the database. Does nothing to the underlying
	// Object.
	Delete(Entity) error
	// Watch the Entity; just the entity and nothing else. Returns a channel for
	// Entity updates and one for errors.
	Watch(Entity) (chan Entity, chan error) // watch of entity
	// WatchStop stops a watch on a specific Entity.
	WatchStop(Entity) error
	// WatchAll watches the prefix of the entity for changes, watching all of the
	// specific type.
	WatchAll(Entity) (chan Entity, chan error) // watch of subtree
	// WatchAllStop stops a WatchAll.
	WatchAllStop(Entity) error
	// Dump dumps a tarball make with mktemp() to the specified directory.
	Dump(string) (string, error)
	// Prefix returns the base prefix for our keyspace.
	Prefix() string
	// List takes an Entity which it will then populate an []Entity with a list of objects.
	List(Entity) ([]Entity, error)
}

Client provides a method of hooking into our data stores. It processes entities (see below) and their pipeline between them and k/v stores such as etcd and consul.

type CreateOptions

type CreateOptions struct {
	Size       string `json:"size" merge:"size"`
	FileSystem string `json:"filesystem" merge:"filesystem"`
}

CreateOptions are the set of options used by apiserver during the volume create operation.

func (*CreateOptions) ActualSize

func (co *CreateOptions) ActualSize() (uint64, error)

ActualSize returns the size of the volume as an integer of megabytes.

type Entity

type Entity interface {
	// Prefix is the base path for all keys; used for watchall and list
	Prefix() string
	// Path to object; used for watch and i/o operations.
	Path() (string, error)
	// Validate the object and ensure it is safe to write, and to use after read.
	Validate() error
	// Copy the object and returns Entity. Typically used to work around
	// interface polymorphism idioms in go.
	Copy() Entity
	// Hooks returns a db.Hooks which contains several functions for the Entity
	// lifecycle, such as pre-set and post-get.
	Hooks() *Hooks
}

Entity provides an abstraction on our types and how they are persisted to k/v stores. They are capable of describing all they need to be written to the database, which Client above is trained to do.

type Global

type Global struct {
	Debug     bool
	Timeout   time.Duration
	TTL       time.Duration
	MountPath string
}

Global is the global configuration.

func NewGlobal

func NewGlobal() *Global

NewGlobal constructs a new global object.

func (*Global) Canonical

func (g *Global) Canonical() *Global

Canonical returns a copy of the current global with the parameters adjusted to fit the internal (or canonical) representation. To see the published version, see Published() above.

It is very important that you do not run this function multiple times against the same data set. It will adjust the parameters twice.

func (*Global) Copy

func (g *Global) Copy() Entity

Copy returns a copy of this Global.

func (*Global) Hooks

func (g *Global) Hooks() *Hooks

Hooks returns an empty hooks set.

func (*Global) Path

func (g *Global) Path() (string, error)

Path returns the path to the global configuration

func (*Global) Prefix

func (g *Global) Prefix() string

Prefix returns the path to the global configuration

func (*Global) Published

func (g *Global) Published() *Global

Published returns a copy of the current global with the parameters adjusted to fit the published representation. To see the internal/system/canonical version, please see Canonical() below.

It is very important that you do not run this function multiple times against the same data set. It will adjust the parameters twice.

func (*Global) Validate

func (g *Global) Validate() error

Validate validates the global configuration.

type Hook

type Hook func(c Client, obj Entity) error

Hook is the type that represents a client hook in our entities system. Hooks are fired at certain client operations (see Hooks below) to cleanup or reconcile work.

type Hooks

type Hooks struct {
	PreSet       Hook
	PostSet      Hook
	PreGet       Hook
	PostGet      Hook
	PreDelete    Hook
	PostDelete   Hook
	PreValidate  Hook
	PostValidate Hook
}

Hooks for CRUD operations. See Entity.Hooks()

type Policy

type Policy struct {
	Name           string            `json:"name"`
	Unlocked       bool              `json:"unlocked,omitempty" merge:"unlocked"`
	CreateOptions  CreateOptions     `json:"create"`
	RuntimeOptions *RuntimeOptions   `json:"runtime"`
	DriverOptions  map[string]string `json:"driver"`
	FileSystems    map[string]string `json:"filesystems"`
	Backends       *BackendDrivers   `json:"backends,omitempty"`
	Backend        string            `json:"backend,omitempty"`
}

Policy is the configuration of the policy. It includes default information for items such as pool and volume configuration.

func NewPolicy

func NewPolicy(name string) *Policy

NewPolicy creates a policy struct with the required parameters for using it. It will not pass validation.

func (*Policy) Copy

func (p *Policy) Copy() Entity

Copy returns a deep copy of the policy

func (*Policy) Hooks

func (p *Policy) Hooks() *Hooks

Hooks returns the public hooks this type registers with the client.

func (*Policy) Path

func (p *Policy) Path() (string, error)

Path returns the path to the policy in the DB.

func (*Policy) Prefix

func (p *Policy) Prefix() string

Prefix returns the path of the base directory where these entities are stored.

func (*Policy) String

func (p *Policy) String() string

func (*Policy) Validate

func (p *Policy) Validate() error

Validate validates the policy. Returns error on failure.

type RateLimitConfig

type RateLimitConfig struct {
	WriteBPS uint64 `json:"write-bps" merge:"rate-limit.write.bps"`
	ReadBPS  uint64 `json:"read-bps" merge:"rate-limit.read.bps"`
}

RateLimitConfig is the configuration for limiting the rate of disk access.

type RuntimeOptions

type RuntimeOptions struct {
	UseSnapshots bool            `json:"snapshots" merge:"snapshots"`
	Snapshot     SnapshotConfig  `json:"snapshot"`
	RateLimit    RateLimitConfig `json:"rate-limit,omitempty"`
	// contains filtered or unexported fields
}

RuntimeOptions are the set of options used by volplugin when mounting the volume, and by volsupervisor for calculating periodic work.

func NewRuntimeOptions

func NewRuntimeOptions(policy, volume string) *RuntimeOptions

NewRuntimeOptions creates a new runtime options struct with a path so it can be found or written to.

func (*RuntimeOptions) Copy

func (ro *RuntimeOptions) Copy() Entity

Copy returns a copy of this RuntimeOptions.

func (*RuntimeOptions) Hooks

func (ro *RuntimeOptions) Hooks() *Hooks

Hooks returns nothing for RuntimeOptions.

func (*RuntimeOptions) Path

func (ro *RuntimeOptions) Path() (string, error)

Path returns a combined path of the runtime payload.

func (*RuntimeOptions) Prefix

func (ro *RuntimeOptions) Prefix() string

Prefix returns the path of the base directory where these entities are stored.

func (*RuntimeOptions) Validate

func (ro *RuntimeOptions) Validate() error

Validate the Runtime Options.

type SnapshotConfig

type SnapshotConfig struct {
	Frequency string `json:"frequency" merge:"snapshots.frequency"`
	Keep      uint   `json:"keep" merge:"snapshots.keep"`
}

SnapshotConfig is the configuration for snapshots.

type UseLocker

type UseLocker interface {
	// GetVolume gets the volume name for this use.
	GetVolume() string
	// GetReason gets the reason for this use.
	GetReason() string
	// Type returns the type of lock.
	Type() string
	// MayExist determines if a key may exist during initial write
	MayExist() bool
}

UseLocker is an interface to locks controlled in etcd, or what we call "users".

type UseMount

type UseMount struct {
	Volume   string
	Hostname string
	Reason   string
}

UseMount is the mount locking mechanism for users. Users are hosts, consumers of a volume. Examples of uses are: creating a volume, using a volume, removing a volume, snapshotting a volume. These are supplied in the `Reason` field as text.

type UseSnapshot

type UseSnapshot struct {
	Volume string
	Reason string
}

UseSnapshot is similar to UseMount in that it is a locking mechanism, just for snapshots this time. Taking snapshots can block certain actions such as taking other snapshots or deleting snapshots.

type Volume

type Volume struct {
	PolicyName     string            `json:"policy"`
	VolumeName     string            `json:"name"`
	Unlocked       bool              `json:"unlocked,omitempty" merge:"unlocked"`
	DriverOptions  map[string]string `json:"driver"`
	MountSource    string            `json:"mount" merge:"mount"`
	CreateOptions  CreateOptions     `json:"create"`
	RuntimeOptions *RuntimeOptions   `json:"runtime"`
	Backends       *BackendDrivers   `json:"backends,omitempty"`
}

Volume is the configuration of the policy. It includes pool and snapshot information.

func CreateVolume

func CreateVolume(vr *VolumeRequest) (*Volume, error)

CreateVolume creates a volume from parameters, including the policy to copy.

func NewVolume

func NewVolume(policy, volume string) *Volume

NewVolume constructs a new volume given the policy and volume parameters.

func (*Volume) Copy

func (v *Volume) Copy() Entity

Copy returns a deep copy of the volume.

func (*Volume) Hooks

func (v *Volume) Hooks() *Hooks

Hooks provides hooks into the volume CRUD lifecycle. Currently this is used to split runtime parameters out from the rest of the volume information.

func (*Volume) Path

func (v *Volume) Path() (string, error)

Path provides the path to this volumes data store.

func (*Volume) Prefix

func (v *Volume) Prefix() string

Prefix provides the prefix for the volumes root.

func (*Volume) String

func (v *Volume) String() string

func (*Volume) ToDriverOptions

func (v *Volume) ToDriverOptions(timeout time.Duration) (storage.DriverOptions, error)

ToDriverOptions converts a volume to a storage.DriverOptions.

func (*Volume) Validate

func (v *Volume) Validate() error

Validate validates the structure of the volume.

type VolumeRequest

type VolumeRequest struct {
	Name    string
	Policy  *Policy
	Options map[string]string
}

VolumeRequest provides a request structure for communicating volumes to the apiserver or internally. it is the basic representation of a volume.

Directories

Path Synopsis
impl

Jump to

Keyboard shortcuts

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