datastore

package
v24.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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
	GlobalScope = "global"
	// SwarmScope is not indicating a datastore location. It is defined here
	// along with the other two scopes just for consistency.
	SwarmScope = "swarm"
)
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 (
	// ErrNotImplemented exported
	ErrNotImplemented = 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 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)
	// Map returns a Map of KVObjects
	Map(key string, kvObject KVObject) (map[string]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

func NewDataStore(cfg ScopeCfg) (DataStore, error)

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 provide the Key to be used in KV Store
	Key() []string
	// KeyPrefix method lets an object return immediate parent key that can be used for tree walk
	KeyPrefix() []string
	// Value method lets an object 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 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"

type ScopeCfg

type ScopeCfg struct {
	Client ScopeClientCfg
}

ScopeCfg represents Datastore configuration.

func DefaultScope

func DefaultScope(dataDir string) ScopeCfg

DefaultScope returns a default scope config for clients to use.

func (*ScopeCfg) IsValid

func (cfg *ScopeCfg) IsValid() bool

IsValid checks if the scope config has valid configuration.

type ScopeClientCfg

type ScopeClientCfg struct {
	Provider string
	Address  string
	Config   *store.Config
}

ScopeClientCfg represents Datastore Client-only mode configuration

Jump to

Keyboard shortcuts

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