store

package
v0.0.0-...-6472126 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2017 License: Apache-2.0, Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package store provides the interface to the backend storage for the config and the default fsstore implementation.

Index

Constants

View Source
const (
	// example fs:///tmp/testdata/configroot
	FSUrl = "fs"
)

URL types supported by the config store

View Source
const IndexNotSupported = -1

IndexNotSupported will be used as the returned index value when the KeyValueStore implementation does not support index.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is the error to be returned when the given key does not exist in the storage.

View Source
var ErrWatchAlreadyExists = errors.New("watch already exists")

ErrWatchAlreadyExists is the error to report that the watching channel already exists.

Functions

func RunStoreTest

func RunStoreTest(t *testing.T, newManagerFn func() *TestManager)

RunStoreTest runs the test cases for a KeyValueStore implementation.

Types

type BackEndResource

type BackEndResource struct {
	Metadata ResourceMeta
	Spec     map[string]interface{}
}

BackEndResource represents a resources with a raw spec

type BackendEvent

type BackendEvent struct {
	Key
	Type  ChangeType
	Value *BackEndResource
}

BackendEvent is an event used between Store2Backend and Store2.

type Builder

type Builder func(u *url.URL) (KeyValueStore, error)

Builder is the type of function to build a KeyValueStore.

type Change

type Change struct {
	// Key that was affected
	Key string `json:"key"`
	// Type how did the key change
	Type ChangeType `json:"change_type"`
	// change log index number of the change
	Index int `json:"index"`
}

Change - A record of mutation to the underlying KeyValueStore.

type ChangeLogReader

type ChangeLogReader interface {
	// Read reads change events >= index
	Read(index int) ([]Change, error)
}

ChangeLogReader read change log from the KV Store

type ChangeNotifier

type ChangeNotifier interface {
	// Register StoreListener
	// KeyValueStore should call this method when there is a change
	// The client should issue ReadChangeLog to see what has changed if the call is available.
	// else it should re-read the store, perform diff and apply changes.
	RegisterListener(s Listener)
}

ChangeNotifier implements change notification machinery for the KeyValueStore.

type ChangeType

type ChangeType int

ChangeType denotes the type of a change

const (
	// Update - change was an update or a create to a key.
	Update ChangeType = iota
	// Delete - key was removed.
	Delete
)

type Event

type Event struct {
	Key
	Type ChangeType

	// Value refers the new value in the updated event. nil if the event type is delete.
	Value *Resource
}

Event represents an event. Used by Store2.Watch.

type Key

type Key struct {
	Kind      string
	Namespace string
	Name      string
}

Key represents the key to identify a resource in the store.

func (Key) String

func (k Key) String() string

String is the Istio compatible string representation of the resource. Name.Kind.Namespace At the point of use Namespace can be omitted, and it is assumed to be the namespace of the document.

type KeyValueStore

type KeyValueStore interface {
	// Get value at a key, false if not found.
	Get(key string) (value string, index int, found bool)

	// Set a value.
	Set(key string, value string) (index int, err error)

	// List keys with the prefix.
	List(key string, recurse bool) (keys []string, index int, err error)

	// Delete a key.
	Delete(key string) error

	// Close the storage.
	Close()

	fmt.Stringer
}

KeyValueStore defines the key value store back end interface used by mixer and Mixer config API server.

It should support back ends like redis, etcd and NFS All commands should return a change log index number which can be used to Read changes. If a KeyValueStore does not support it, it should return -1

type Listener

type Listener interface {
	// NotifyStoreChanged notify listener that a new change is available.
	NotifyStoreChanged(index int)
}

Listener listens for calls from the store that some keys have changed.

type MemstoreWriter

type MemstoreWriter interface {
	Put(key Key, resource *BackEndResource)
	Delete(key Key)
}

MemstoreWriter is the interface to make changes on the memstore backend. This will be used by tests to set up the on-memory data in the store.

func GetMemstoreWriter

func GetMemstoreWriter(u string) MemstoreWriter

GetMemstoreWriter returns the MemstoreWriter used for the config store URL, or nil if the URL is not used.

type RegisterFunc

type RegisterFunc func(map[string]Builder)

RegisterFunc is the type to register a builder for URL scheme.

type RegisterFunc2

type RegisterFunc2 func(map[string]Store2Builder)

RegisterFunc2 is the type to register a builder for URL scheme.

type Registry

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

Registry keeps the relationship between the URL scheme and the storage implementation.

func NewRegistry

func NewRegistry(inventory ...RegisterFunc) *Registry

NewRegistry creates a new Registry instance for the inventory.

func (*Registry) NewStore

func (r *Registry) NewStore(configURL string) (KeyValueStore, error)

NewStore create a new store based on the config URL.

type Registry2

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

Registry2 keeps the relationship between the URL scheme and the Store2Backend implementation.

func NewRegistry2

func NewRegistry2(inventory ...RegisterFunc2) *Registry2

NewRegistry2 creates a new Registry instance for the inventory.

func (*Registry2) NewStore2

func (r *Registry2) NewStore2(configURL string) (Store2, error)

NewStore2 creates a new Store2 instance with the specified backend.

type Resource

type Resource struct {
	Metadata ResourceMeta
	Spec     proto.Message
}

Resource represents a resources with converted spec.

type ResourceMeta

type ResourceMeta struct {
	Name        string
	Namespace   string
	Labels      map[string]string
	Annotations map[string]string
	Revision    string
}

ResourceMeta is the standard metadata associated with a resource.

type Store2

type Store2 interface {
	Init(ctx context.Context, kinds map[string]proto.Message) error

	// Watch creates a channel to receive the events. A store can conduct a single
	// watch channel at the same time. Multiple calls lead to an error.
	Watch(ctx context.Context) (<-chan Event, error)

	// Get returns a resource's spec to the key.
	Get(key Key, spec proto.Message) error

	// List returns the whole mapping from key to resource specs in the store.
	List() map[Key]*Resource
}

Store2 defines the access to the storage for mixer. TODO: rename to Store.

type Store2Backend

type Store2Backend interface {
	Init(ctx context.Context, kinds []string) error

	// Watch creates a channel to receive the events.
	Watch(ctx context.Context) (<-chan BackendEvent, error)

	// Get returns a resource's spec to the key.
	Get(key Key) (*BackEndResource, error)

	// List returns the whole mapping from key to resource specs in the store.
	List() map[Key]*BackEndResource
}

Store2Backend defines the typeless storage backend for mixer. TODO: rename to StoreBackend.

func NewFsStore2

func NewFsStore2(root string) Store2Backend

NewFsStore2 creates a new Store2Backend backed by the filesystem.

type Store2Builder

type Store2Builder func(u *url.URL) (Store2Backend, error)

Store2Builder is the type of function to build a Store2Backend.

type TestManager

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

TestManager manages the data to run test cases.

func NewTestManager

func NewTestManager(s KeyValueStore, cleanup func()) *TestManager

NewTestManager creates a new StoreTestManager.

type Validator

type Validator interface {
	Validate(t ChangeType, key Key, spec proto.Message) bool
}

Validator defines the interface to validate a new change.

Jump to

Keyboard shortcuts

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