cluster

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Overview

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 (
	// HeartbeatInterval is the interval for heartbeat.
	HeartbeatInterval = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster interface {
	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)

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

	Delete(key string) error
	DeletePrefix(prefix string) 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 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 `yaml:"id"`
	StartTime string `yaml:"startTime"`
	State     string `yaml:"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) 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(name string) string

StatusObjectKey returns the key of object status.

func (*Layout) StatusObjectPrefix

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

StatusObjectPrefix returns the prefix of object status.

func (*Layout) StatusObjectsPrefix

func (l *Layout) StatusObjectsPrefix() string

StatusObjectsPrefix returns the prefix of objects status.

func (*Layout) WasmCodeEvent added in v1.1.0

func (l *Layout) WasmCodeEvent() string

WasmCodeEvent returns the key of wasm code event

type MemberStatus

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

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

	LastDefragTime string `yaml:"lastDefragTime,omitempty"`

	// Etcd is non-nil only it is a writer.
	Etcd *EtcdStatus `yaml:"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 struct {
	// contains filtered or unexported fields
}

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.

func (*Syncer) Close

func (s *Syncer) Close()

Close closes the syncer.

func (*Syncer) Sync

func (s *Syncer) Sync(key string) (<-chan *string, error)

Sync syncs a given Etcd key's value through the returned channel.

func (*Syncer) SyncPrefix

func (s *Syncer) SyncPrefix(prefix string) (<-chan map[string]string, error)

SyncPrefix syncs Etcd keys' values with the same prefix through the returned channel.

func (*Syncer) SyncRaw

func (s *Syncer) SyncRaw(key string) (<-chan *mvccpb.KeyValue, error)

SyncRaw syncs a given Etcd key's raw Etcd mvccpb structure through the returned channel.

func (*Syncer) SyncRawPrefix

func (s *Syncer) SyncRawPrefix(prefix string) (<-chan map[string]*mvccpb.KeyValue, error)

SyncRawPrefix syncs Etcd keys' values with the same prefix in raw Etcd mvccpb structure format through the returned channel.

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)
	Close()
}

Watcher wraps etcd watcher.

Jump to

Keyboard shortcuts

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