2019-05-01 15:11:27 +00:00
|
|
|
// +build !consulent
|
2017-08-14 14:36:07 +00:00
|
|
|
|
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2017-09-01 00:39:46 +00:00
|
|
|
"net"
|
2017-09-07 01:01:53 +00:00
|
|
|
"time"
|
2017-08-14 14:36:07 +00:00
|
|
|
|
2017-09-07 01:01:53 +00:00
|
|
|
"github.com/armon/go-metrics"
|
2020-11-14 00:26:08 +00:00
|
|
|
"github.com/armon/go-metrics/prometheus"
|
2017-09-01 00:39:46 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2017-08-14 14:36:07 +00:00
|
|
|
"github.com/hashicorp/serf/serf"
|
|
|
|
)
|
|
|
|
|
2020-11-14 00:26:08 +00:00
|
|
|
var SegmentOSSSummaries = []prometheus.SummaryDefinition{
|
|
|
|
{
|
|
|
|
Name: []string{"leader", "reconcile"},
|
2020-11-16 19:02:11 +00:00
|
|
|
Help: "Measures the time spent updating the raft store from the serf member information.",
|
2020-11-14 00:26:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-09-05 19:22:20 +00:00
|
|
|
// LANMembersAllSegments returns members from all segments.
|
|
|
|
func (s *Server) LANMembersAllSegments() ([]serf.Member, error) {
|
|
|
|
return s.LANMembers(), nil
|
|
|
|
}
|
|
|
|
|
2017-08-14 14:36:07 +00:00
|
|
|
// LANSegmentMembers is used to return the members of the given LAN segment.
|
2017-08-30 23:44:04 +00:00
|
|
|
func (s *Server) LANSegmentMembers(segment string) ([]serf.Member, error) {
|
|
|
|
if segment == "" {
|
2017-08-14 14:36:07 +00:00
|
|
|
return s.LANMembers(), nil
|
|
|
|
}
|
|
|
|
|
2017-09-01 00:39:46 +00:00
|
|
|
return nil, structs.ErrSegmentsNotSupported
|
2017-08-14 14:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LANSegmentAddr is used to return the address used for the given LAN segment.
|
|
|
|
func (s *Server) LANSegmentAddr(name string) string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-09-01 00:39:46 +00:00
|
|
|
// setupSegmentRPC returns an error if any segments are defined since the OSS
|
|
|
|
// version of Consul doesn't support them.
|
|
|
|
func (s *Server) setupSegmentRPC() (map[string]net.Listener, error) {
|
|
|
|
if len(s.config.Segments) > 0 {
|
|
|
|
return nil, structs.ErrSegmentsNotSupported
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-08-14 14:36:07 +00:00
|
|
|
// setupSegments returns an error if any segments are defined since the OSS
|
2017-09-01 00:39:46 +00:00
|
|
|
// version of Consul doesn't support them.
|
2017-09-01 00:56:43 +00:00
|
|
|
func (s *Server) setupSegments(config *Config, port int, rpcListeners map[string]net.Listener) error {
|
2017-08-14 14:36:07 +00:00
|
|
|
if len(config.Segments) > 0 {
|
2017-09-01 00:39:46 +00:00
|
|
|
return structs.ErrSegmentsNotSupported
|
2017-08-14 14:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// floodSegments is a NOP in the OSS version of Consul.
|
|
|
|
func (s *Server) floodSegments(config *Config) {
|
|
|
|
}
|
2017-09-07 01:01:53 +00:00
|
|
|
|
|
|
|
// reconcile is used to reconcile the differences between Serf membership and
|
|
|
|
// what is reflected in our strongly consistent store. Mainly we need to ensure
|
|
|
|
// all live nodes are registered, all failed nodes are marked as such, and all
|
2020-05-08 14:03:45 +00:00
|
|
|
// left nodes are deregistered.
|
2017-09-07 01:01:53 +00:00
|
|
|
func (s *Server) reconcile() (err error) {
|
2017-10-04 23:43:27 +00:00
|
|
|
defer metrics.MeasureSince([]string{"leader", "reconcile"}, time.Now())
|
2017-09-07 01:01:53 +00:00
|
|
|
members := s.serfLAN.Members()
|
|
|
|
knownMembers := make(map[string]struct{})
|
|
|
|
for _, member := range members {
|
|
|
|
if err := s.reconcileMember(member); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
knownMembers[member.Name] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reconcile any members that have been reaped while we were not the
|
|
|
|
// leader.
|
|
|
|
return s.reconcileReaped(knownMembers)
|
|
|
|
}
|