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
- func CreateEtcdConfig(opt *option.Options, members *members) (*embed.Config, error)
- func CreateOptionsForTest(tempDir string) *option.Options
- func CreateStaticClusterEtcdConfig(opt *option.Options) (*embed.Config, error)
- type ClientOp
- type Cluster
- type EtcdStatus
- type Layout
- func (l *Layout) ClusterNameKey() string
- func (l *Layout) ConfigObjectKey(name string) string
- func (l *Layout) ConfigObjectPrefix() string
- func (l *Layout) ConfigVersion() string
- func (l *Layout) CustomDataKindPrefix() string
- func (l *Layout) CustomDataPrefix() string
- func (l *Layout) Lease() string
- func (l *Layout) OtherLease(memberName string) string
- func (l *Layout) OtherStatusMemberKey(memberName string) string
- func (l *Layout) StatusMemberKey() string
- func (l *Layout) StatusMemberPrefix() string
- func (l *Layout) StatusObjectKey(name string) string
- func (l *Layout) StatusObjectName(kind string, specName string) string
- func (l *Layout) StatusObjectPrefix(name string) string
- func (l *Layout) StatusObjectsPrefix() string
- func (l *Layout) WasmCodeEvent() string
- func (l *Layout) WasmDataPrefix(pipeline string, name string) string
- type MemberStatus
- type Mutex
- type Syncer
- type Watcher
Constants ¶
const ( // HeartbeatInterval is the interval for heartbeat. HeartbeatInterval = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func CreateEtcdConfig ¶ added in v1.4.0
CreateEtcdConfig creates an embedded etcd config that starts the cluster by adding one member at a time. Deprecated: Use CreateStaticClusterEtcdConfig instead.
func CreateOptionsForTest ¶ added in v1.5.1
CreateOptionsForTest creates a options for testing purposes.
Types ¶
type ClientOp ¶ added in v1.4.1
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 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 ¶ added in v1.5.0
CreateClusterForTest creates a cluster for testing purposes.
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 ¶
ClusterNameKey returns the key of the cluster name.
func (*Layout) ConfigObjectKey ¶
ConfigObjectKey returns the key of object config.
func (*Layout) ConfigObjectPrefix ¶
ConfigObjectPrefix returns the prefix of object config.
func (*Layout) ConfigVersion ¶
ConfigVersion returns the key of config version.
func (*Layout) CustomDataKindPrefix ¶ added in v1.5.0
CustomDataKindPrefix returns the prefix of all custom data kind
func (*Layout) CustomDataPrefix ¶ added in v1.5.0
CustomDataPrefix returns the prefix of all custom data
func (*Layout) OtherLease ¶
OtherLease returns the key of the given member lease.
func (*Layout) OtherStatusMemberKey ¶
OtherStatusMemberKey returns the key of given member status.
func (*Layout) StatusMemberKey ¶
StatusMemberKey returns the key of own member status.
func (*Layout) StatusMemberPrefix ¶
StatusMemberPrefix returns the prefix of member status.
func (*Layout) StatusObjectKey ¶
StatusObjectKey returns the key of object status.
func (*Layout) StatusObjectName ¶ added in v1.5.1
StatusObjectName returns the name of the status object.
func (*Layout) StatusObjectPrefix ¶
StatusObjectPrefix returns the prefix of object status.
func (*Layout) StatusObjectsPrefix ¶
StatusObjectsPrefix returns the prefix of objects status.
func (*Layout) WasmCodeEvent ¶ added in v1.1.0
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 if it's cluster status is primary. Etcd *EtcdStatus `yaml:"etcd,omitempty"` }
MemberStatus is the member status.
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.