cluster

package
v0.0.0-...-80d60d4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConnConfig = &ConnConfig{
	MaxConnections:     3,
	InitialNodeTimeout: 5 * time.Second,
	DebounceTime:       3 * time.Second,
	Retries:            2,
}
View Source
var (
	ErrNoClientAvailable = errors.New("no client nodes available")
)
View Source
var (
	ErrNoKey = errors.New("Key could not be found")
)

Functions

func GetPrefixRangeEnd

func GetPrefixRangeEnd(prefix string) string

GetPrefixRangeEnd gets the range end of the prefix. 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.

func WithCountOnly

func WithCountOnly() clientv3.OpOption

WithCountOnly makes the 'Get' request return only the count of keys.

func WithFromKey

func WithFromKey() clientv3.OpOption

WithFromKey specifies the range of 'Get', 'Delete', 'Watch' requests to be equal or greater than the key in the argument.

func WithKeysOnly

func WithKeysOnly() clientv3.OpOption

WithKeysOnly makes the 'Get' request return only the keys and the corresponding values will be omitted.

func WithLimit

func WithLimit(n int64) clientv3.OpOption

WithLimit limits the number of results to return from 'Get' request. If WithLimit is given a 0 limit, it is treated as no limit.

func WithPrefix

func WithPrefix() clientv3.OpOption

WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' can return 'foo1', 'foo2', and so on.

func WithRange

func WithRange(endKey string) clientv3.OpOption

WithRange specifies the range of 'Get', 'Delete', 'Watch' requests. For example, 'Get' requests with 'WithRange(end)' returns the keys in the range [key, end). endKey must be lexicographically greater than start key.

func WithRev

func WithRev(rev int64) clientv3.OpOption

WithRev specifies the store revision for 'Get' request. Or the start revision of 'Watch' request.

func WithSerializable

func WithSerializable() clientv3.OpOption

WithSerializable makes 'Get' request serializable. By default, it's linearizable. Serializable requests are better for lower latency requirement.

func WithSort

func WithSort(target SortTarget, order SortOrder) clientv3.OpOption

WithSort specifies the ordering in 'Get' request. It requires 'WithRange' and/or 'WithPrefix' to be specified too. 'target' specifies the target to sort by: key, version, revisions, value. 'order' can be either 'SortNone', 'SortAscend', 'SortDescend'.

Types

type Client

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

func (*Client) Call

func (c *Client) Call(serviceMethod string, args interface{}, reply interface{}) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) ConnectionErrs

func (c *Client) ConnectionErrs() chan error

func (*Client) Go

func (c *Client) Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) *rpc.Call

type Cluster

type Cluster struct {
	Registry Registry
	Store    *KVStore
	// contains filtered or unexported fields
}

func Join

func Join(ctx context.Context, cfg Config) (*Cluster, error)

func (*Cluster) Close

func (c *Cluster) Close() error

func (*Cluster) MemberList

func (c *Cluster) MemberList(ctx context.Context) ([]*etcdserverpb.Member, error)

func (*Cluster) NewClient

func (c *Cluster) NewClient(serviceName string, cfg *ConnConfig) (*Client, error)

type Config

type Config struct {
	ServiceName              string   `json:"service_name"`
	NodeName                 string   `json:"node_name"`
	Port                     int      `json:"port"`
	EtcdConfigFile           string   `json:"etcd_config_file"`
	InitialClusterClientUrls []string `json:"initial_cluster_client_urls"`
	Debug                    bool     `json:"debug"`
	// contains filtered or unexported fields
}

func ConfigFromFile

func ConfigFromFile(cfgPath string) (Config, error)

type ConnConfig

type ConnConfig struct {
	// Max connections to unique nodes in the cluster. If the value 0 is used, then
	// a mesh network will be formed (connection with every node).
	MaxConnections int
	// Timeout for establishing the initial connection with the service's nodes.
	// Connections afterwards are done asynchronously and don't have a timeout.
	InitialNodeTimeout time.Duration
	// Duration to batch the latest node changes. Prevents thundering herd of changes.
	DebounceTime time.Duration
	// Retries is the number of times a request is attempted to get a success. The
	// retires are possibliy done on different nodes.
	Retries int
}

type KVStore

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

func (*KVStore) Delete

func (kvs *KVStore) Delete(ctx context.Context, key string, options ...clientv3.OpOption) error

Delete deletes the given key

func (*KVStore) Get

func (kvs *KVStore) Get(ctx context.Context, key string, options ...clientv3.OpOption) ([]string, error)

Get returns the best matched value for the key provided

func (*KVStore) Put

func (kvs *KVStore) Put(ctx context.Context, key, value string, options ...clientv3.OpOption) error

Put sets the value for the given key

type Node

type Node struct {
	Address string `json:"address"`
	Port    int    `json:"port"`
}

type Registry

type Registry interface {
	Register(ctx context.Context, serviceName, nodeName, host string, port int) error
	Services(ctx context.Context) (map[string][]Node, error)
	WatchService(ctx context.Context, serviceName string) chan []Node
}

type SortOrder

type SortOrder int
const (
	SortNone SortOrder = iota
	SortAscend
	SortDescend
)

type SortTarget

type SortTarget int
const (
	SortByKey SortTarget = iota
	SortByVersion
	SortByCreateRevision
	SortByModRevision
	SortByValue
)

Jump to

Keyboard shortcuts

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