datastore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2015 License: Apache-2.0, BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NetworkKeyPrefix is the prefix for network key in the kv store
	NetworkKeyPrefix = "network"
	// EndpointKeyPrefix is the prefix for endpoint key in the kv store
	EndpointKeyPrefix = "endpoint"
)

Variables

View Source
var (
	ErrKeyModified = store.ErrKeyModified
	ErrKeyNotFound = store.ErrKeyNotFound
)

ErrKeyModified is raised for an atomic update when the update is working on a stale state

View Source
var (
	// ErrNotImplmented exported
	ErrNotImplmented = errors.New("Functionality not implemented")
)

Functions

func Key

func Key(key ...string) string

Key provides convenient method to create a Key

func ParseKey

func ParseKey(key string) ([]string, error)

ParseKey provides convenient method to unpack the key to complement the Key function

Types

type DataStore

type DataStore interface {
	// GetObject gets data from datastore and unmarshals to the specified object
	GetObject(key string, o KV) error
	// PutObject adds a new Record based on an object into the datastore
	PutObject(kvObject KV) error
	// PutObjectAtomic provides an atomic add and update operation for a Record
	PutObjectAtomic(kvObject KV) error
	// DeleteObject deletes a record
	DeleteObject(kvObject KV) error
	// DeleteObjectAtomic performs an atomic delete operation
	DeleteObjectAtomic(kvObject KV) error
	// DeleteTree deletes a record
	DeleteTree(kvObject KV) error
	// KVStore returns access to the KV Store
	KVStore() store.Store
}

DataStore exported

func NewCustomDataStore

func NewCustomDataStore(customStore store.Store) DataStore

NewCustomDataStore can be used by clients to plugin cusom datatore that adhers to store.Store

func NewDataStore

func NewDataStore(cfg *config.DatastoreCfg) (DataStore, error)

NewDataStore creates a new instance of LibKV data store

type KV

type KV interface {
	// Key method lets an object to provide the Key to be used in KV Store
	Key() []string
	// KeyPrefix method lets an object to return immediate parent key that can be used for tree walk
	KeyPrefix() []string
	// Value method lets an object to marshal its content to be stored in the KV store
	Value() []byte
	// SetValue is used by the datastore to set the object's value when loaded from the data store.
	SetValue([]byte) error
	// Index method returns the latest DB Index as seen by the object
	Index() uint64
	// SetIndex method allows the datastore to store the latest DB Index into the object
	SetIndex(uint64)
	// True if the object exists in the datastore, false if it hasn't been stored yet.
	// When SetIndex() is called, the object has been stored.
	Exists() bool
}

KV Key Value interface used by objects to be part of the DataStore

type MockData

type MockData struct {
	Data  []byte
	Index uint64
}

MockData exported

type MockStore

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

MockStore exported

func NewMockStore

func NewMockStore() *MockStore

NewMockStore creates a Map backed Datastore that is useful for mocking

func (*MockStore) AtomicDelete

func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error)

AtomicDelete deletes a value at "key" if the key has not been modified in the meantime, throws an error if this is the case

func (*MockStore) AtomicPut

func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut put a value at "key" if the key has not been modified in the meantime, throws an error if this is the case

func (*MockStore) Close

func (s *MockStore) Close()

Close closes the client connection

func (*MockStore) Delete

func (s *MockStore) Delete(key string) error

Delete a value at "key"

func (*MockStore) DeleteTree

func (s *MockStore) DeleteTree(prefix string) error

DeleteTree deletes a range of values at "directory"

func (*MockStore) Exists

func (s *MockStore) Exists(key string) (bool, error)

Exists checks that the key exists inside the store

func (*MockStore) Get

func (s *MockStore) Get(key string) (*store.KVPair, error)

Get the value at "key", returns the last modified index to use in conjunction to CAS calls

func (*MockStore) List

func (s *MockStore) List(prefix string) ([]*store.KVPair, error)

List gets a range of values at "directory"

func (*MockStore) NewLock

func (s *MockStore) NewLock(key string, options *store.LockOptions) (store.Locker, error)

NewLock exposed

func (*MockStore) Put

func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error

Put a value at "key"

func (*MockStore) Watch

func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error)

Watch a single key for modifications

func (*MockStore) WatchTree

func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error)

WatchTree triggers a watch on a range of values at "directory"

Jump to

Keyboard shortcuts

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