Documentation
¶
Overview ¶
Package grpcprocetcd keeps a grpcproc cluster's membership in etcd. A node registers under a lease it keeps alive; peers resolve its address from there; and when the lease ends, because the node stopped or because it stopped answering, every node that watches the cluster drops its links to it, firing Down{noconnection} for monitors across them.
cluster := grpcprocetcd.New(etcdClient, "/grpcproc/prod")
node, err := grpcproc.NewNode(grpcproc.Config{
Name: "orders-1",
Advertise: "10.0.0.5:9000",
Resolver: cluster, Registrar: cluster, Membership: cluster,
})
Each node is one key, <prefix>/nodes/<name>, holding its name, incarnation and address as JSON. A node that registers a name already present replaces it: a restarted node supersedes its previous incarnation, whose lease has not yet expired.
Index ¶
- Variables
- type Cluster
- func (c *Cluster) Members(ctx context.Context) ([]grpcproc.Member, error)
- func (c *Cluster) Register(ctx context.Context, self grpcproc.Member) (func(context.Context) error, error)
- func (c *Cluster) Resolve(ctx context.Context, node string) (string, error)
- func (c *Cluster) Watch(ctx context.Context) (<-chan grpcproc.MemberEvent, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrNotRegistered = errors.New("grpcprocetcd: node is not registered")
ErrNotRegistered is returned by Resolve for a node absent from etcd.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster implements grpcproc.Resolver, grpcproc.Registrar and grpcproc.Membership on etcd. One value serves every node of a process.
func (*Cluster) Members ¶
Members lists the registered nodes, ordered by name. Records that cannot be decoded are skipped.
func (*Cluster) Register ¶
func (c *Cluster) Register(ctx context.Context, self grpcproc.Member) (func(context.Context) error, error)
Register publishes self under a lease and keeps it alive. If the lease is lost (etcd was unreachable for longer than the TTL), it registers again, every retry interval, until it succeeds or withdraw is called. withdraw revokes the lease, which removes the key at once.
func (*Cluster) Watch ¶
Watch reports every registered node as up, then follows the prefix: a new or replaced key is a member up, a deleted one (a withdrawn or expired lease) a member down. If the watch breaks (etcd restarted, its history compacted), it lists the members again, every retry interval until that works, and reports what changed in between.