store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RegisteredInformers contains a list of store Informers configured using the package
	// it is useful for printing debug information related to store.
	RegisteredInformers map[string]*Informer = make(map[string]*Informer)

	// ControllerManager is a global controller manager for all the store Informers
	ControllerManager *controller.Manager = controller.NewManager()
)

Functions

func Setup

func Setup(storageDir string) error

Setup sets up the store backend for xene.

Types

type Backend

type Backend interface {
	// GetName returns the name of the backend module.
	GetName() string

	// Close closes the database client and does not allow to do any more transactions.
	Close() error

	// Configured returns if the backend client has been configured or not.
	Configured() bool

	// Status returns the status of the initialized backend, it returns an error
	// if anything is wrong with the backend module.
	Status() (string, error)

	// Get returns the value of the key.
	Get(ctx context.Context, key string) (*types.Value, error)

	// Exists checks if the provided key exists or not
	Exists(ctx context.Context, key string) (bool, error)

	// KeyDoesNotExistError is the method to check if the error is due to non
	// existance of the key during the get operation.
	KeyDoesNotExistError(err error) bool

	// GetPrefix returns the first key which matches the prefix and its value
	GetPrefix(ctx context.Context, prefix string) (string, *types.Value, error)

	// Set sets value of key
	Set(ctx context.Context, key string, value []byte) error

	// Delete deletes a key
	Delete(ctx context.Context, key string) error

	// DeletePrefix deletes the first key which matches the prefix and its value.
	DeletePrefix(ctx context.Context, path string) error

	// CreateOnly atomically creates a key or fails if it already exists
	CreateOnly(ctx context.Context, key string, value []byte) (bool, error)

	// CreateIfExists creates a key with the value only if key condKey exists
	CreateIfExists(ctx context.Context, condKey, key string, value []byte) error

	// ListPrefixKeys list all the keys with the provided prefix.
	ListPrefixKeys(ctx context.Context, path string) ([]string, error)

	// ListPrefix returns a list of keys matching the prefix
	ListPrefix(ctx context.Context, prefix string) (types.KeyValuePairs, error)

	// ListPrefix returns a list of keys matching the prefix
	PrefixScanWithFunction(ctx context.Context, prefix string, f types.KVPairStructFunc)

	// Encodes a binary slice into a character set that the backend
	// supports
	Encode(in []byte) string

	// Decodes a key previously encoded back into the original binary slice
	Decode(in string) ([]byte, error)
}

Backend is the interface which needs to be implemented by each client configured for the store.

var KVStore Backend

KVStore is the configured backend store for xene.

type Cache

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

Cache is a map containing store keys corresponding to the last revision applied for the same object.

var GlobalSharedCache Cache = NewCache("global-cache")

GlobalSharedCache is the global shared cache that can be used by any of the store controller.

func NewCache

func NewCache(name string) Cache

NewCache returns a new instance of Store cache

func (*Cache) CheckIfAdded

func (c *Cache) CheckIfAdded(key string, revision uint64) bool

CheckIfAdded checks if the key and the revision provided have been added looking at the configured cache.

func (*Cache) CheckIfExists

func (c *Cache) CheckIfExists(key string) bool

CheckIfExists checks if the provided key exists in the cache or not.

func (*Cache) CheckIfUpdated

func (c *Cache) CheckIfUpdated(key string, revision uint64) bool

CheckIfUpdated checks if the key and the revision provided have been added or updated looking at the configured cache.

func (*Cache) Get

func (c *Cache) Get(key string) uint64

Get returns the saved version of the provided key in the cache.

func (*Cache) RegisterDeleteFunc

func (c *Cache) RegisterDeleteFunc(prefix string, deleteFunc deleteFuncType)

RegisterDeleteFunc registers a delete function for delete on the registered prefix.

func (*Cache) Remove

func (c *Cache) Remove(key string)

Remove deletes the key from the Cache.

func (*Cache) RunController

func (c *Cache) RunController() error

RunController starts running the cache controller.

func (*Cache) Set

func (c *Cache) Set(key string, revision uint64)

Set adds or update an existing key in the Cache

func (*Cache) StopController

func (c *Cache) StopController()

StopController stops the running controller.

type Informer

type Informer struct {
	AddFunc addFuncType

	UpdateFunc updateFuncType

	DeleteFunc deleteFuncType

	// Key is the prefix key to watch for.
	Key string

	Manager *controller.Manager
	// contains filtered or unexported fields
}

Informer is a type corresponding to a store Informer. A store Informer can be used to run function based on changes to a store object.

func NewInformer

func NewInformer(
	key string,
	addFunc func(*v1alpha1.KVPairStruct) error,
	delFunc func(string) error,
	updateFunc func(*v1alpha1.KVPairStruct, uint64) error) *Informer

NewInformer returns a new store controller to periodically run functions based on changes to the specifed key in the store.

func NewInformerWithSharedCache

func NewInformerWithSharedCache(
	key string,
	addFunc func(*v1alpha1.KVPairStruct) error,
	delFunc func(string) error,
	updateFunc func(*v1alpha1.KVPairStruct, uint64) error) *Informer

NewInformerWithSharedCache returns a new store Informer to periodically run functions based on changes to the specifed key in the store. The Informer in this case is configured with the global shared store, which share its state with other Informer.

func (*Informer) DeleteFromCache

func (c *Informer) DeleteFromCache(key string)

DeleteFromCache deletes the entry from the store cache.

func (*Informer) Name

func (c *Informer) Name() string

Name returns the name of the controller.

func (*Informer) Run

func (c *Informer) Run() error

Run starts running the store controller configured.

func (*Informer) Stop

func (c *Informer) Stop() error

Stop shuts down a running store controller.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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