datastore

package
v26.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 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

Functions

func Key

func Key(key ...string) string

Key provides convenient method to create a Key

Types

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)
	// Exists returns 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
	// Skip provides a way for a KV Object to avoid persisting it in the KV Store
	Skip() bool
	// 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
}

KVObject is Key/Value interface used by objects to be part of the Store.

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

type Store

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

func New

func New(cfg ScopeCfg) (*Store, error)

New creates a new Store instance.

func (*Store) Close

func (ds *Store) Close()

Close closes the data store.

func (*Store) DeleteObject

func (ds *Store) DeleteObject(kvObject KVObject) error

DeleteObject deletes a kvObject from the on-disk DB and the in-memory cache. Unlike DeleteObjectAtomic, it doesn't check the optimistic lock of the passed kvObject.

func (*Store) DeleteObjectAtomic

func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error

DeleteObjectAtomic performs atomic delete on a record.

func (*Store) GetObject

func (ds *Store) GetObject(o KVObject) error

GetObject gets data from the store and unmarshals to the specified object.

func (*Store) List

func (ds *Store) List(kvObject KVObject) ([]KVObject, error)

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.

func (*Store) Map

func (ds *Store) Map(key string, kvObject KVObject) (map[string]KVObject, error)

Map returns a Map of KVObjects.

func (*Store) PutObjectAtomic

func (ds *Store) PutObjectAtomic(kvObject KVObject) error

PutObjectAtomic provides an atomic add and update operation for a Record.

Jump to

Keyboard shortcuts

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