Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultScopes(dataDir string) map[string]*ScopeCfg
- func Key(key ...string) string
- func ParseKey(key string) ([]string, error)
- type DataStore
- type KVConstructor
- type KVObject
- type MockData
- type MockStore
- func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error)
- func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, ...) (bool, *store.KVPair, error)
- func (s *MockStore) Close()
- func (s *MockStore) Delete(key string) error
- func (s *MockStore) DeleteTree(prefix string) error
- func (s *MockStore) Exists(key string) (bool, error)
- func (s *MockStore) Get(key string) (*store.KVPair, error)
- func (s *MockStore) List(prefix string) ([]*store.KVPair, error)
- func (s *MockStore) NewLock(key string, options *store.LockOptions) (store.Locker, error)
- func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error
- func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error)
- func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error)
- type ScopeCfg
- type ScopeClientCfg
Constants ¶
const ( // LocalScope indicates to store the KV object in local datastore such as boltdb LocalScope = "local" // GlobalScope indicates to store the KV object in global datastore such as consul/etcd/zookeeper GlobalScope = "global" )
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 ¶
var ( ErrKeyModified = store.ErrKeyModified ErrKeyNotFound = store.ErrKeyNotFound )
ErrKeyModified is raised for an atomic update when the update is working on a stale state
var ( // ErrNotImplmented exported ErrNotImplmented = errors.New("Functionality not implemented") )
Functions ¶
func DefaultScopes ¶
DefaultScopes returns a map of default scopes and it's config for clients to use.
Types ¶
type DataStore ¶
type DataStore interface { // GetObject gets data from datastore and unmarshals to the specified object GetObject(key string, o KVObject) error // PutObject adds a new Record based on an object into the datastore PutObject(kvObject KVObject) error // PutObjectAtomic provides an atomic add and update operation for a Record PutObjectAtomic(kvObject KVObject) error // DeleteObject deletes a record DeleteObject(kvObject KVObject) error // DeleteObjectAtomic performs an atomic delete operation DeleteObjectAtomic(kvObject KVObject) error // DeleteTree deletes a record DeleteTree(kvObject KVObject) error // Watchable returns whether the store is watchable or not Watchable() bool // Watch for changes on a KVObject Watch(kvObject KVObject, stopCh <-chan struct{}) (<-chan KVObject, error) // RestartWatch retriggers stopped Watches RestartWatch() // Active returns if the store is active Active() bool // List returns of a list of KVObjects belonging to the parent // key. The caller must pass a KVObject of the same type as // the objects that need to be listed List(string, KVObject) ([]KVObject, error) // Scope returns the scope of the store Scope() string // KVStore returns access to the KV Store KVStore() store.Store // Close closes the data store Close() }
DataStore exported
func NewDataStore ¶
NewDataStore creates a new instance of LibKV data store
func NewDataStoreFromConfig ¶
func NewDataStoreFromConfig(dsc discoverapi.DatastoreConfigData) (DataStore, error)
NewDataStoreFromConfig creates a new instance of LibKV data store starting from the datastore config data
type KVConstructor ¶
type KVConstructor interface { // New returns a new object which is created based on the // source object New() KVObject // CopyTo deep copies the contents of the implementing object // to the passed destination object CopyTo(KVObject) error }
KVConstructor interface defines methods which can construct a KVObject from another.
type KVObject ¶
type KVObject 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 // DataScope indicates the storage scope of the KV object DataScope() string // Skip provides a way for a KV Object to avoid persisting it in the KV Store Skip() bool }
KVObject is Key/Value interface used by objects to be part of the DataStore
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 ¶
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) DeleteTree ¶
DeleteTree deletes a range of values at "directory"
func (*MockStore) Get ¶
Get the value at "key", returns the last modified index to use in conjunction to CAS calls
type ScopeCfg ¶
type ScopeCfg struct {
Client ScopeClientCfg
}
ScopeCfg represents Datastore configuration.