kv

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: Apache-2.0 Imports: 18 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Get a specific key.  Will use a codec to deserialise key to appropriate type.
	Get(ctx context.Context, key string) (interface{}, error)

	// CAS stands for Compare-And-Swap.  Will call provided callback f with the
	// current value of the key and allow callback to return a different value.
	// Will then attempt to atomically swap the current value for the new value.
	// If that doesn't succeed will try again - callback will be called again
	// with new value etc.  Guarantees that only a single concurrent CAS
	// succeeds.  Callback can return nil to indicate it is happy with existing
	// value.
	CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error

	// WatchKey calls f whenever the value stored under key changes.
	WatchKey(ctx context.Context, key string, f func(interface{}) bool)

	// WatchPrefix calls f whenever any value stored under prefix changes.
	WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)
}

Client is a high-level client for key-value stores (such as Etcd and Consul) that exposes operations such as CAS and Watch which take callbacks. It also deals with serialisation by using a Codec and having a instance of the the desired type passed in to methods ala json.Unmarshal.

func NewClient

func NewClient(cfg Config, codec codec.Codec) (Client, error)

NewClient creates a new Client (consul, etcd or inmemory) based on the config, encodes and decodes data for storage using the codec.

func PrefixClient

func PrefixClient(client Client, prefix string) Client

PrefixClient takes a KVClient and forces a prefix on all its operations.

type Config

type Config struct {
	Store       string `yaml:"store"`
	Prefix      string `yaml:"prefix"`
	StoreConfig `yaml:",inline"`

	Mock Client `yaml:"-"`
}

Config is config for a KVStore currently used by ring and HA tracker, where store can be consul or inmemory.

func (*Config) RegisterFlagsWithPrefix

func (cfg *Config) RegisterFlagsWithPrefix(flagsPrefix, defaultPrefix string, f *flag.FlagSet)

RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet. If prefix is an empty string we will register consul flags with no prefix and the store flag with the prefix ring, so ring.store. For everything else we pass the prefix to the Consul flags. If prefix is not an empty string it should end with a period.

type MultiClient added in v0.6.0

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

MultiClient implements kv.Client by forwarding all API calls to primary client. Writes performed via CAS method are also (optionally) forwarded to secondary clients.

func NewMultiClient added in v0.6.0

func NewMultiClient(cfg MultiConfig, clients []kvclient) *MultiClient

NewMultiClient creates new MultiClient with given KV Clients. First client in the slice is the primary client.

func (*MultiClient) CAS added in v0.6.0

func (m *MultiClient) CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error

CAS is a part of kv.Client interface.

func (*MultiClient) Get added in v0.6.0

func (m *MultiClient) Get(ctx context.Context, key string) (interface{}, error)

Get is a part of kv.Client interface.

func (*MultiClient) WatchKey added in v0.6.0

func (m *MultiClient) WatchKey(ctx context.Context, key string, f func(interface{}) bool)

WatchKey is a part of kv.Client interface.

func (*MultiClient) WatchPrefix added in v0.6.0

func (m *MultiClient) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)

WatchPrefix is a part of kv.Client interface.

type MultiConfig added in v0.6.0

type MultiConfig struct {
	Primary   string `yaml:"primary"`
	Secondary string `yaml:"secondary"`

	MirrorEnabled bool          `yaml:"mirror_enabled"`
	MirrorTimeout time.Duration `yaml:"mirror_timeout"`

	// ConfigProvider returns channel with MultiRuntimeConfig updates.
	ConfigProvider func() <-chan MultiRuntimeConfig `yaml:"-"`
}

MultiConfig is a configuration for MultiClient.

func (*MultiConfig) RegisterFlagsWithPrefix added in v0.6.0

func (cfg *MultiConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string)

RegisterFlagsWithPrefix registers flags with prefix.

type MultiRuntimeConfig added in v0.6.0

type MultiRuntimeConfig struct {
	// Primary store used by MultiClient. Can be updated in runtime to switch to a different store (eg. consul -> etcd,
	// or to gossip). Doing this allows nice migration between stores. Empty values are ignored.
	PrimaryStore string `yaml:"primary"`

	// Mirroring enabled or not. Nil = no change.
	Mirroring *bool `yaml:"mirror_enabled"`
}

MultiRuntimeConfig has values that can change in runtime (via overrides)

type StoreConfig added in v0.6.0

type StoreConfig struct {
	Consul consul.Config `yaml:"consul"`
	Etcd   etcd.Config   `yaml:"etcd"`
	Multi  MultiConfig   `yaml:"multi"`

	// Function that returns memberlist.KV store to use. By using a function, we can delay
	// initialization of memberlist.KV until it is actually required.
	MemberlistKV func() (*memberlist.KV, error) `yaml:"-"`
}

StoreConfig is a configuration used for building single store client, either Consul, Etcd, Memberlist or MultiClient. It was extracted from Config to keep single-client config separate from final client-config (with all the wrappers)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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