// sendMemberEvent is used to send a single member event func (es *eventStream) sendMemberEvent(me serf.MemberEvent) error { members := make([]Member, 0, len(me.Members)) for _, m := range me.Members { sm := Member{ Name: m.Name, Addr: m.Addr, Port: m.Port, Tags: m.Tags, Status: m.Status.String(), ProtocolMin: m.ProtocolMin, ProtocolMax: m.ProtocolMax, ProtocolCur: m.ProtocolCur, DelegateMin: m.DelegateMin, DelegateMax: m.DelegateMax, DelegateCur: m.DelegateCur, } members = append(members, sm) } header := responseHeader{ Seq: es.seq, Error: "", } rec := memberEventRecord{ Event: me.String(), Members: members, } return es.client.Send(&header, &rec) }
// localMemberEvent is used to reconcile Serf events with the strongly // consistent store if we are the current leader func (s *Server) localMemberEvent(me serf.MemberEvent) { // Do nothing if we are not the leader if !s.IsLeader() { return } // Check if this is a reap event isReap := me.EventType() == serf.EventMemberReap // Queue the members for reconciliation for _, m := range me.Members { // Change the status if this is a reap event if isReap { m.Status = StatusReap } select { case s.reconcileCh <- m: default: } } }
// reconcile is used to reconcile Serf events with the strongly // consistent store if we are the current leader func (s *SerfEventHandler) reconcile(me serf.MemberEvent) { // Do nothing if we are not the leader. if !s.IsLeader() { return } // Check if this is a reap event isReap := me.EventType() == serf.EventMemberReap // Queue the members for reconciliation for _, m := range me.Members { // Change the status if this is a reap event if isReap { m.Status = StatusReap } // Call reconcile if s.Reconciler != nil { s.Reconciler.Reconcile(m) } } }