Documentation ¶
Index ¶
Constants ¶
const SysMemberPrefix = "_nats.cluster.members."
SysMemberPrefix creates a namespace for system cluster membership communication. This prefix aims to avoid collisions with user-level topics. Only system processes / internal clients should write to these topics, but everyone is welcome to listen on them.
note: `_nats` is for now, can easily changed to be `_SYS` later once we're sure everything is working.
Variables ¶
This section is empty.
Functions ¶
func AgentLocLessThan ¶
AgentLocLessThan returns true iff i < j, in terms of leader preference where lowest is more electable/preferred as leader.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements the InternalClient interface. It provides health status checks and leader election from among the candidate hnatsd instances in a cluster.
type AgentLoc ¶
type AgentLoc struct { ID string `json:"serverId"` NatsHost string `json:"natsHost"` NatsClientPort int `json:"natsClientPort"` Grpc ExtInt `json:"grpc"` // LeaseExpires is zero for any // non-leader. For the leader, // LeaseExpires tells you when // the leaders lease expires. LeaseExpires time.Time `json:"leaseExpires"` // lower rank is leader until lease // expires. Ties are broken by ID. // Rank should be assignable on the // gnatsd command line with -rank to // let the operator prioritize // leadership for certain hosts. Rank int `json:"rank"` // Pid or process id is the only // way to tell apart two processes // sometimes, if they share the // same nats server. // // Pid is one difference between // a nats.ServerLoc and a health.AgentLoc. // Pid int `json:"pid"` }
AgentLoc conveys to interested parties the Id and location of one gnatsd server in the cluster.
type ExtInt ¶
type ExtInt struct { External HostPort `json:"externalHostPort"` Internal HostPort `json:"internalHostPort"` }
ExtInt conveys the external/internal port pairs. Sshd secures external ports, and forwards authenticated connections to localhost:internal port.
type Icc ¶
Icc allows the server to detect a net.Conn as an internal client connection by checking if it implements the LocalInternalClient interface.
func NewInternalClientPair ¶
NewInternalClientPair constructs a client/server pair that wrap tcp endpoints in Icc to let the server recognized them as internal.
func (*Icc) IsInternal ¶
func (c *Icc) IsInternal()
IsInternal satisfy LocalInternalClient interface
type Membership ¶
type Membership struct { Cfg MembershipCfg // contains filtered or unexported fields }
Membership tracks the nats server cluster membership, issuing health checks and choosing a leader.
func NewMembership ¶
func NewMembership(cfg *MembershipCfg) *Membership
NewMembership creates a new Membership.
func (*Membership) Start ¶
func (m *Membership) Start() error
Start launches the Membership goroutine.
func (*Membership) Stop ¶
func (m *Membership) Stop()
Stop blocks until the Membership goroutine acknowledges the shutdown request.
type MembershipCfg ¶
type MembershipCfg struct { // max we allow for clocks to be out of sync. // default to 1 second if not set. MaxClockSkew time.Duration // how often we heartbeat. defaults to 100msec // if not set. BeatDur time.Duration // NatsURL example "nats://127.0.0.1:4222" NatsURL string // defaults to "_nats.cluster.members." SysMemberPrefix string // LeaseTime is the minimum time the // leader is elected for. Defaults to 10 sec. LeaseTime time.Duration // provide a default until the server gives us rank MyRank int // optional, if provided we will use this connection on // the client side. CliConn net.Conn // where we log stuff. Log server.Logger // contains filtered or unexported fields }
MembershipCfg configures the Membership service, which is the health-agent implementation.
func (*MembershipCfg) Dial ¶
func (cfg *MembershipCfg) Dial(network, address string) (net.Conn, error)
Dial allows us to replace a client's dial of an external TCP socket with an already established internal TCP connection.
func (*MembershipCfg) SetDefaults ¶
func (cfg *MembershipCfg) SetDefaults()
SetDefaults fills in default values.