store

package
v2.4.4+incompatible Latest Latest
Warning

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

Go to latest
Published: May 11, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBackendNotSupported is thrown when the backend k/v store is not supported by libkv
	ErrBackendNotSupported = errors.New("Backend storage not supported yet, please choose one of")
	// ErrCallNotSupported is thrown when a method is not implemented/supported by the current backend
	ErrCallNotSupported = errors.New("The current call is not supported with this backend")
	// ErrNotReachable is thrown when the API cannot be reached for issuing common store operations
	ErrNotReachable = errors.New("Api not reachable")
	// ErrCannotLock is thrown when there is an error acquiring a lock on a key
	ErrCannotLock = errors.New("Error acquiring the lock")
	// ErrKeyModified is thrown during an atomic operation if the index does not match the one in the store
	ErrKeyModified = errors.New("Unable to complete atomic operation, key modified")
	// ErrKeyNotFound is thrown when the key is not found in the store during a Get operation
	ErrKeyNotFound = errors.New("Key not found in store")
	// ErrPreviousNotSpecified is thrown when the previous value is not specified for an atomic operation
	ErrPreviousNotSpecified = errors.New("Previous K/V pair should be provided for the Atomic operation")
	// ErrKeyExists is thrown when the previous value exists in the case of an AtomicPut
	ErrKeyExists = errors.New("Previous K/V pair exists, cannnot complete Atomic operation")
)

Functions

func CreateEndpoints

func CreateEndpoints(addrs []string, scheme string) (entries []string)

CreateEndpoints creates a list of endpoints given the right scheme

func Normalize

func Normalize(key string) string

Normalize the key for each store to the form:

/path/to/key

func Register

func Register(name string, f Initializer)

Register a new store, the Intializer is a function used to initialize store

func SplitKey

func SplitKey(key string) (path []string)

SplitKey splits the key to extract path informations

Types

type Action

type Action int

Action is the event type

const (
	// ERROR event action, this will be set when geting error from backend(etcd, zk...)
	ERROR Action = iota - 1
	// GET event action, useless
	GET
	// SET event action, same with update, it's useless
	SET
	// UPDATE event action, return when data changed in backend, include set, create, update, compareAndSwap
	UPDATE
	// DELETE event action, return when some key was delete or expired or compareAndDelete
	DELETE
	// INIT event action, this is only retured when calling watch() and only the first correct event.
	INIT
)

func (Action) String

func (a Action) String() string

Return the string value for a action

type Event

type Event struct {
	Action        Action
	Key           string
	ModifiedIndex uint64
	Data          []*KVPair
}

Event represents a event get from watch, Action is 'delete' or 'update' Data is the latest key-value-data of the watched key

func (*Event) Error

func (e *Event) Error() string

func (*Event) String

func (e *Event) String() string

type Initializer

type Initializer func([]string) (Store, error)

Initializer is initialization function which can create real store, used when Register()

type KVPair

type KVPair struct {
	Key       string
	Value     []byte
	LastIndex uint64
}

KVPair represents {Key, Value, Lastindex} tuple

type Store

type Store interface {
	// Get a value given its key
	Get(key string) (*KVPair, error)

	// Get the content of a given prefix by recursive
	GetTree(key string) ([]*KVPair, error)

	// Set a value for the given key
	Put(key string, value []byte) error

	// Delete a key
	Delete(key string, recursive bool) error

	// Verify if a Key exists in the store
	Exists(key string) (bool, error)

	// Watch for changes on a key
	Watch(key string, ctx context.Context, recursive bool, index uint64) (<-chan *Event, error)

	// WatchTree watches for changes on child nodes under
	// a given directory
	WatchTree(directory string, ctx context.Context, index uint64) (<-chan *Event, error)

	// List all the nodes in a directory
	List(dir string) ([]string, error)

	// Close the store connection
	Close()
}

Store represents the backend K/V storage Each store should support every call listed here. Or it couldn't be implemented as a K/V backend for libkv

func New

func New(name string, addrs []string) (Store, error)

New return a new store by given name and initialize addrs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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