kv

package
v0.0.0-...-3b9dd47 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: Apache-2.0 Imports: 4 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// UninitializedVersion is the version of an uninitialized kv value.
	UninitializedVersion = 0
)

Variables

View Source
var (
	// ErrVersionMismatch is returned when attempting a CheckAndSet and the
	// key is not at the provided version
	ErrVersionMismatch = errors.New("key is not at the specified version")

	// ErrAlreadyExists is returned when attempting a SetIfEmpty and the key
	// already has a value
	ErrAlreadyExists = errors.New("key already has a value")

	// ErrNotFound is returned when attempting a Get but no value is found for
	// the given key
	ErrNotFound = errors.New("key not found")

	// ErrUnknownTargetType is returned when an unknown TargetType is requested
	ErrUnknownTargetType = errors.New("unknown target type")

	// ErrUnknownCompareType is returned when an unknown CompareType is requested
	ErrUnknownCompareType = errors.New("unknown compare type")

	// ErrUnknownOpType is returned when an unknown OpType is requested
	ErrUnknownOpType = errors.New("unknown op type")

	// ErrConditionCheckFailed is returned when condition check failed
	ErrConditionCheckFailed = errors.New("condition check failed")
)

Functions

This section is empty.

Types

type CompareType

type CompareType string

CompareType is the type of the comparison in the condition

const (
	CompareEqual CompareType = "="
)

list of supported CompareType

func (CompareType) String

func (t CompareType) String() string

type Condition

type Condition interface {
	// TargetType returns the type of the TargetType
	TargetType() TargetType
	// SetTargetType sets the type of the TargetType
	SetTargetType(t TargetType) Condition

	// CompareType returns the type of the CompareType
	CompareType() CompareType
	// SetCompareType sets the type of the CompareType
	SetCompareType(t CompareType) Condition

	// Key returns the key in the condition
	Key() string
	// SetKey sets the key in the condition
	SetKey(key string) Condition

	// Value returns the value for comparison
	Value() interface{}
	// SetValue sets the value for comparison
	SetValue(value interface{}) Condition
}

Condition defines the prerequisite for a transaction

func NewCondition

func NewCondition() Condition

NewCondition returns a new Condition

type MockCondition

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

Mock of Condition interface

func NewMockCondition

func NewMockCondition(ctrl *gomock.Controller) *MockCondition

func (*MockCondition) CompareType

func (_m *MockCondition) CompareType() CompareType

func (*MockCondition) EXPECT

func (_m *MockCondition) EXPECT() *_MockConditionRecorder

func (*MockCondition) Key

func (_m *MockCondition) Key() string

func (*MockCondition) SetCompareType

func (_m *MockCondition) SetCompareType(t CompareType) Condition

func (*MockCondition) SetKey

func (_m *MockCondition) SetKey(key string) Condition

func (*MockCondition) SetTargetType

func (_m *MockCondition) SetTargetType(t TargetType) Condition

func (*MockCondition) SetValue

func (_m *MockCondition) SetValue(value interface{}) Condition

func (*MockCondition) TargetType

func (_m *MockCondition) TargetType() TargetType

func (*MockCondition) Value

func (_m *MockCondition) Value() interface{}

type MockOp

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

Mock of Op interface

func NewMockOp

func NewMockOp(ctrl *gomock.Controller) *MockOp

func (*MockOp) EXPECT

func (_m *MockOp) EXPECT() *_MockOpRecorder

func (*MockOp) Key

func (_m *MockOp) Key() string

func (*MockOp) SetKey

func (_m *MockOp) SetKey(key string) Op

func (*MockOp) SetType

func (_m *MockOp) SetType(ot OpType) Op

func (*MockOp) Type

func (_m *MockOp) Type() OpType

type MockOpResponse

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

Mock of OpResponse interface

func NewMockOpResponse

func NewMockOpResponse(ctrl *gomock.Controller) *MockOpResponse

func (*MockOpResponse) EXPECT

func (_m *MockOpResponse) EXPECT() *_MockOpResponseRecorder

func (*MockOpResponse) Key

func (_m *MockOpResponse) Key() string

func (*MockOpResponse) SetKey

func (_m *MockOpResponse) SetKey(key string) Op

func (*MockOpResponse) SetType

func (_m *MockOpResponse) SetType(ot OpType) Op

func (*MockOpResponse) SetValue

func (_m *MockOpResponse) SetValue(v interface{}) OpResponse

func (*MockOpResponse) Type

func (_m *MockOpResponse) Type() OpType

func (*MockOpResponse) Value

func (_m *MockOpResponse) Value() interface{}

type MockOverrideOptions

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

Mock of OverrideOptions interface

func NewMockOverrideOptions

func NewMockOverrideOptions(ctrl *gomock.Controller) *MockOverrideOptions

func (*MockOverrideOptions) EXPECT

func (_m *MockOverrideOptions) EXPECT() *_MockOverrideOptionsRecorder

func (*MockOverrideOptions) Environment

func (_m *MockOverrideOptions) Environment() string

func (*MockOverrideOptions) Namespace

func (_m *MockOverrideOptions) Namespace() string

func (*MockOverrideOptions) SetEnvironment

func (_m *MockOverrideOptions) SetEnvironment(env string) OverrideOptions

func (*MockOverrideOptions) SetNamespace

func (_m *MockOverrideOptions) SetNamespace(namespace string) OverrideOptions

func (*MockOverrideOptions) SetZone

func (_m *MockOverrideOptions) SetZone(value string) OverrideOptions

func (*MockOverrideOptions) Validate

func (_m *MockOverrideOptions) Validate() error

func (*MockOverrideOptions) Zone

func (_m *MockOverrideOptions) Zone() string

type MockResponse

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

Mock of Response interface

func NewMockResponse

func NewMockResponse(ctrl *gomock.Controller) *MockResponse

func (*MockResponse) EXPECT

func (_m *MockResponse) EXPECT() *_MockResponseRecorder

func (*MockResponse) Responses

func (_m *MockResponse) Responses() []OpResponse

func (*MockResponse) SetResponses

func (_m *MockResponse) SetResponses(oprs []OpResponse) Response

type MockStore

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

Mock of Store interface

func NewMockStore

func NewMockStore(ctrl *gomock.Controller) *MockStore

func (*MockStore) CheckAndSet

func (_m *MockStore) CheckAndSet(key string, version int, v proto.Message) (int, error)

func (*MockStore) Delete

func (_m *MockStore) Delete(key string) (Value, error)

func (*MockStore) EXPECT

func (_m *MockStore) EXPECT() *_MockStoreRecorder

func (*MockStore) Get

func (_m *MockStore) Get(key string) (Value, error)

func (*MockStore) History

func (_m *MockStore) History(key string, from int, to int) ([]Value, error)

func (*MockStore) Set

func (_m *MockStore) Set(key string, v proto.Message) (int, error)

func (*MockStore) SetIfNotExists

func (_m *MockStore) SetIfNotExists(key string, v proto.Message) (int, error)

func (*MockStore) Watch

func (_m *MockStore) Watch(key string) (ValueWatch, error)

type MockTxnStore

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

Mock of TxnStore interface

func NewMockTxnStore

func NewMockTxnStore(ctrl *gomock.Controller) *MockTxnStore

func (*MockTxnStore) CheckAndSet

func (_m *MockTxnStore) CheckAndSet(key string, version int, v proto.Message) (int, error)

func (*MockTxnStore) Commit

func (_m *MockTxnStore) Commit(_param0 []Condition, _param1 []Op) (Response, error)

func (*MockTxnStore) Delete

func (_m *MockTxnStore) Delete(key string) (Value, error)

func (*MockTxnStore) EXPECT

func (_m *MockTxnStore) EXPECT() *_MockTxnStoreRecorder

func (*MockTxnStore) Get

func (_m *MockTxnStore) Get(key string) (Value, error)

func (*MockTxnStore) History

func (_m *MockTxnStore) History(key string, from int, to int) ([]Value, error)

func (*MockTxnStore) Set

func (_m *MockTxnStore) Set(key string, v proto.Message) (int, error)

func (*MockTxnStore) SetIfNotExists

func (_m *MockTxnStore) SetIfNotExists(key string, v proto.Message) (int, error)

func (*MockTxnStore) Watch

func (_m *MockTxnStore) Watch(key string) (ValueWatch, error)

type MockValue

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

Mock of Value interface

func NewMockValue

func NewMockValue(ctrl *gomock.Controller) *MockValue

func (*MockValue) EXPECT

func (_m *MockValue) EXPECT() *_MockValueRecorder

func (*MockValue) IsNewer

func (_m *MockValue) IsNewer(other Value) bool

func (*MockValue) Unmarshal

func (_m *MockValue) Unmarshal(v proto.Message) error

func (*MockValue) Version

func (_m *MockValue) Version() int

type MockValueWatch

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

Mock of ValueWatch interface

func NewMockValueWatch

func NewMockValueWatch(ctrl *gomock.Controller) *MockValueWatch

func (*MockValueWatch) C

func (_m *MockValueWatch) C() <-chan struct{}

func (*MockValueWatch) Close

func (_m *MockValueWatch) Close()

func (*MockValueWatch) EXPECT

func (_m *MockValueWatch) EXPECT() *_MockValueWatchRecorder

func (*MockValueWatch) Get

func (_m *MockValueWatch) Get() Value

type MockValueWatchable

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

Mock of ValueWatchable interface

func NewMockValueWatchable

func NewMockValueWatchable(ctrl *gomock.Controller) *MockValueWatchable

func (*MockValueWatchable) Close

func (_m *MockValueWatchable) Close()

func (*MockValueWatchable) EXPECT

func (_m *MockValueWatchable) EXPECT() *_MockValueWatchableRecorder

func (*MockValueWatchable) Get

func (_m *MockValueWatchable) Get() Value

func (*MockValueWatchable) IsClosed

func (_m *MockValueWatchable) IsClosed() bool

func (*MockValueWatchable) NumWatches

func (_m *MockValueWatchable) NumWatches() int

func (*MockValueWatchable) Update

func (_m *MockValueWatchable) Update(_param0 Value) error

func (*MockValueWatchable) Watch

func (_m *MockValueWatchable) Watch() (Value, ValueWatch, error)

type Op

type Op interface {
	// Type returns the type of the operation
	Type() OpType
	// SetType sets the type of the operation
	SetType(ot OpType) Op

	// Key returns the key used in the operation
	Key() string
	// SetKey sets the key in the operation
	SetKey(key string) Op
}

Op is the operation to be performed in a transaction

type OpResponse

type OpResponse interface {
	Op

	Value() interface{}
	SetValue(v interface{}) OpResponse
}

OpResponse is the response of a transaction operation

func NewOpResponse

func NewOpResponse(op Op) OpResponse

NewOpResponse creates a new OpResponse

type OpType

type OpType int

OpType is the type of the operation

const (
	OpSet OpType = iota
)

list of supported OpTypes

type OverrideConfiguration

type OverrideConfiguration struct {
	Zone        string `yaml:"zone"`
	Environment string `yaml:"environment"`
	Namespace   string `yaml:"namespace"`
}

OverrideConfiguration is the config for OverrideOptions.

func (OverrideConfiguration) NewOverrideOptions

func (cfg OverrideConfiguration) NewOverrideOptions() (OverrideOptions, error)

NewOverrideOptions creates a OverrideOptions.

type OverrideOptions

type OverrideOptions interface {
	// Zone returns the zone of the KV store.
	Zone() string

	// SetZone sets the zone of the KV store.
	SetZone(value string) OverrideOptions

	// Namespace returns the namespace of the KV store.
	Namespace() string

	// SetNamespace sets the namespace of the KV store.
	SetNamespace(namespace string) OverrideOptions

	// Environment returns the environment of the KV store.
	Environment() string

	// SetEnvironment sets the environment of the KV store.
	SetEnvironment(env string) OverrideOptions

	// Validate validates the Options.
	Validate() error
}

OverrideOptions provides a set of options to override the default configurations of a KV store.

func NewOverrideOptions

func NewOverrideOptions() OverrideOptions

NewOverrideOptions creates a new kv Options.

type Response

type Response interface {
	Responses() []OpResponse
	SetResponses(oprs []OpResponse) Response
}

Response captures the response of the transaction

func NewResponse

func NewResponse() Response

NewResponse creates a new transaction Response

type SetOp

type SetOp struct {
	Value proto.Message
	// contains filtered or unexported fields
}

SetOp is a Op with OpType Set

func NewSetOp

func NewSetOp(key string, value proto.Message) SetOp

NewSetOp returns a SetOp

func (SetOp) Key

func (r SetOp) Key() string

func (SetOp) SetKey

func (r SetOp) SetKey(key string) Op

func (SetOp) SetType

func (r SetOp) SetType(t OpType) Op

func (SetOp) Type

func (r SetOp) Type() OpType

type Store

type Store interface {
	// Get retrieves the value for the given key
	Get(key string) (Value, error)

	// Watch adds a watch for value updates for given key. This is a non-blocking
	// call - a notification will be sent to ValueWatch.C() once a value is
	// available
	Watch(key string) (ValueWatch, error)

	// Set stores the value for the given key
	Set(key string, v proto.Message) (int, error)

	// SetIfNotExists sets the value for the given key only if no value already
	// exists
	SetIfNotExists(key string, v proto.Message) (int, error)

	// CheckAndSet stores the value for the given key if the current version
	// matches the provided version
	CheckAndSet(key string, version int, v proto.Message) (int, error)

	// Delete deletes a key in the store and returns the last value before deletion
	Delete(key string) (Value, error)

	// History returns the value for a key in version range [from, to)
	History(key string, from, to int) ([]Value, error)
}

Store provides access to the configuration store

type TargetType

type TargetType int

TargetType is the type of the comparison target in the condition

const (
	TargetVersion TargetType = iota
)

list of supported TargetTypes

type TxnStore

type TxnStore interface {
	Store

	Commit([]Condition, []Op) (Response, error)
}

TxnStore supports transactions on top of Store interface

type Value

type Value interface {
	// Unmarshal retrieves the stored value
	Unmarshal(v proto.Message) error

	// Version returns the current version of the value
	Version() int

	// IsNewer returns if this Value is newer than the other Value
	IsNewer(other Value) bool
}

A Value provides access to a versioned value in the configuration store

type ValueWatch

type ValueWatch interface {
	// C returns the notification channel
	C() <-chan struct{}
	// Get returns the latest version of the value
	Get() Value
	// Close stops watching for value updates
	Close()
}

ValueWatch provides updates to a Value

type ValueWatchable

type ValueWatchable interface {
	// Get returns the latest Value
	Get() Value
	// Watch returns the Value and a ValueWatch that will be notified on updates
	Watch() (Value, ValueWatch, error)
	// NumWatches returns the number of watches on the Watchable
	NumWatches() int
	// Update sets the Value and notify Watches
	Update(Value) error
	// IsClosed returns true if the Watchable is closed
	IsClosed() bool
	// Close stops watching for value updates
	Close()
}

ValueWatchable can be watched for Value changes

func NewValueWatchable

func NewValueWatchable() ValueWatchable

NewValueWatchable creates a new ValueWatchable

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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