cluster

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package cluster provides the cluster management.

Package cluster contains: 1. an etcd server 2. an etcd client

The cluster only provide interface to maintain the etcd members(join/drop), but not data access. The client is delegated to the api layer to access data from/to the cluster.

Index

Constants

View Source
const (
	// NamespaceDefault is the default namespace of object.
	NamespaceDefault = "default"
	// NamespaceSystemPrefix is the prefix of system namespace.
	// all namespaces started with this prefix is reserved for system.
	// The users should avoid creating namespaces started with this prefix.
	NamespaceSystemPrefix  = "eg-"
	NamespacetrafficPrefix = "eg-traffic-"
)

Cluster store tree layout. Status means dynamic, different in every member. Config means static, same in every member.

View Source
const (
	// HeartbeatInterval is the interval for heartbeat.
	HeartbeatInterval = 5 * time.Second
)

Variables

This section is empty.

Functions

func CreateOptionsForTest

func CreateOptionsForTest(tempDir string) *option.Options

CreateOptionsForTest creates a options for testing purposes.

func CreateStaticClusterEtcdConfig

func CreateStaticClusterEtcdConfig(opt *option.Options) (*embed.Config, error)

CreateStaticClusterEtcdConfig creates an embedded etcd config for static sized cluster, listing all cluster members for etcd's initial-cluster argument.

func SystemNamespace

func SystemNamespace(name string) string

SystemNamespace returns the system namespace.

func TrafficNamespace

func TrafficNamespace(name string) string

TrafficNamespace returns the traffic namespace.

Types

type ClientOp

type ClientOp string

ClientOp is client operation option type for etcd client used in cluster and watcher

const (
	// OpPrefix will watch all event with certain prefix
	OpPrefix ClientOp = "prefix"

	// OpNotWatchPut will not watch put event
	OpNotWatchPut ClientOp = "put"

	// OpNotWatchDelete will not watch delete event
	OpNotWatchDelete ClientOp = "delete"

	// OpKeysOnly will get etcd and only return keys, for example, get all prefix without values
	OpKeysOnly ClientOp = "keysOnly"
)

type Cluster

type Cluster interface {
	IsLeader() bool

	Layout() *Layout

	Get(key string) (*string, error)
	GetPrefix(prefix string) (map[string]string, error)
	GetRaw(key string) (*mvccpb.KeyValue, error)
	GetRawPrefix(prefix string) (map[string]*mvccpb.KeyValue, error)
	GetWithOp(key string, ops ...ClientOp) (map[string]string, error)

	Put(key, value string) error
	PutUnderLease(key, value string) error
	PutAndDelete(map[string]*string) error
	PutAndDeleteUnderLease(map[string]*string) error

	PutUnderTimeout(key, value string, timeout time.Duration) error

	Delete(key string) error
	DeletePrefix(prefix string) error

	// The STM function is used to do cluster-level atomic operations like
	// increase/decrease an integer by one, which is very useful to create
	// a cluster-level counter.
	STM(apply func(concurrency.STM) error) error

	Watcher() (Watcher, error)
	Syncer(pullInterval time.Duration) (Syncer, error)

	Mutex(name string) (Mutex, error)

	CloseServer(wg *sync.WaitGroup)
	StartServer() (chan struct{}, chan struct{}, error)

	Close(wg *sync.WaitGroup)

	PurgeMember(member string) error
}

Cluster is the open cluster interface.

func CreateClusterForTest

func CreateClusterForTest(tempDir string) Cluster

CreateClusterForTest creates a cluster for testing purposes.

func New

func New(opt *option.Options) (Cluster, error)

New creates a cluster asynchronously, return non-nil err only if reaching hard limit.

type EtcdStatus

type EtcdStatus struct {
	ID        string `json:"id"`
	StartTime string `json:"startTime"`
	State     string `json:"state"`
}

EtcdStatus is the etcd status, and extracts fields from server.Server.SelfStats.

type Layout

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

Layout represents storage tree layout.

func (*Layout) ClusterNameKey

func (l *Layout) ClusterNameKey() string

ClusterNameKey returns the key of the cluster name.

func (*Layout) ConfigObjectKey

func (l *Layout) ConfigObjectKey(name string) string

ConfigObjectKey returns the key of object config.

func (*Layout) ConfigObjectPrefix

func (l *Layout) ConfigObjectPrefix() string

ConfigObjectPrefix returns the prefix of object config.

func (*Layout) ConfigVersion

func (l *Layout) ConfigVersion() string

ConfigVersion returns the key of config version.

func (*Layout) CustomDataKindPrefix

func (l *Layout) CustomDataKindPrefix() string

CustomDataKindPrefix returns the prefix of all custom data kind

func (*Layout) CustomDataPrefix

func (l *Layout) CustomDataPrefix() string

CustomDataPrefix returns the prefix of all custom data

func (*Layout) Lease

func (l *Layout) Lease() string

Lease returns the key of own member lease.

func (*Layout) OtherLease

func (l *Layout) OtherLease(memberName string) string

OtherLease returns the key of the given member lease.

func (*Layout) OtherStatusMemberKey

func (l *Layout) OtherStatusMemberKey(memberName string) string

OtherStatusMemberKey returns the key of given member status.

func (*Layout) StatusMemberKey

func (l *Layout) StatusMemberKey() string

StatusMemberKey returns the key of own member status.

func (*Layout) StatusMemberPrefix

func (l *Layout) StatusMemberPrefix() string

StatusMemberPrefix returns the prefix of member status.

func (*Layout) StatusObjectKey

func (l *Layout) StatusObjectKey(namespace, name string) string

StatusObjectKey returns the key of object status.

func (*Layout) StatusObjectPrefix

func (l *Layout) StatusObjectPrefix(namespace, name string) string

StatusObjectPrefix returns the prefix of object status that for all easegress nodes.

func (*Layout) StatusObjectsPrefix

func (l *Layout) StatusObjectsPrefix() string

StatusObjectsPrefix returns the prefix of objects status.

func (*Layout) WasmCodeEvent

func (l *Layout) WasmCodeEvent() string

WasmCodeEvent returns the key of wasm code event

func (*Layout) WasmDataPrefix

func (l *Layout) WasmDataPrefix(pipeline string, name string) string

WasmDataPrefix returns the prefix of wasm data

type MemberStatus

type MemberStatus struct {
	Options option.Options `json:"options"`

	// RFC3339 format
	LastHeartbeatTime string `json:"lastHeartbeatTime"`

	LastDefragTime string `json:"lastDefragTime,omitempty"`

	// Etcd is non-nil only if it's cluster status is primary.
	Etcd *EtcdStatus `json:"etcd,omitempty"`
}

MemberStatus is the member status.

type Mutex

type Mutex interface {
	Lock() error
	Unlock() error
}

Mutex is a cluster level mutex.

type Syncer

type Syncer interface {
	Sync(string) (<-chan *string, error)
	SyncRaw(string) (<-chan *mvccpb.KeyValue, error)
	SyncPrefix(string) (<-chan map[string]string, error)
	SyncRawPrefix(string) (<-chan map[string]*mvccpb.KeyValue, error)
	Close()
}

Syncer syncs data from Etcd, it uses an Etcd watcher to receive update. The syncer keeps a full copy of data, and keeps apply changes onto it when an update event is received from the watcher, and then send out the full data copy. The syncer also pulls full data from Etcd at a configurable pull interval, this is to ensure data consistency, as Etcd watcher may be cancelled if it cannot catch up with the key-value store.

type Watcher

type Watcher interface {
	Watch(key string) (<-chan *string, error)
	WatchPrefix(prefix string) (<-chan map[string]*string, error)
	WatchRaw(key string) (<-chan *clientv3.Event, error)
	WatchRawPrefix(prefix string) (<-chan map[string]*clientv3.Event, error)
	WatchWithOp(key string, ops ...ClientOp) (<-chan map[string]*string, error)
	Close()
}

Watcher wraps etcd watcher.

Directories

Path Synopsis
Package clustertest provides a mocked cluster for testing.
Package clustertest provides a mocked cluster for testing.
Package customdata provides a way to store custom data in Easegress cluster.
Package customdata provides a way to store custom data in Easegress cluster.

Jump to

Keyboard shortcuts

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