2021-10-26 20:08:55 +00:00
|
|
|
//go:build !consulent
|
2020-09-25 17:46:38 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
2017-11-29 00:30:07 +00:00
|
|
|
package consul
|
|
|
|
|
2020-01-28 23:50:41 +00:00
|
|
|
import (
|
2021-11-15 15:51:14 +00:00
|
|
|
"fmt"
|
2022-02-24 22:54:47 +00:00
|
|
|
"strings"
|
2021-11-15 15:51:14 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/armon/go-metrics"
|
|
|
|
"github.com/hashicorp/go-multierror"
|
|
|
|
"github.com/hashicorp/serf/coordinate"
|
2020-09-25 17:46:38 +00:00
|
|
|
"github.com/hashicorp/serf/serf"
|
2021-07-22 18:58:08 +00:00
|
|
|
"google.golang.org/grpc"
|
2021-10-26 20:08:55 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2021-11-15 15:51:14 +00:00
|
|
|
"github.com/hashicorp/consul/lib"
|
2020-01-28 23:50:41 +00:00
|
|
|
)
|
|
|
|
|
2021-11-15 15:51:14 +00:00
|
|
|
func (s *Server) registerEnterpriseGRPCServices(deps Deps, srv *grpc.Server) {}
|
|
|
|
|
2021-12-06 19:18:02 +00:00
|
|
|
func (s *Server) enterpriseValidateJoinWAN() error {
|
|
|
|
return nil // no-op
|
|
|
|
}
|
|
|
|
|
2021-11-15 15:51:14 +00:00
|
|
|
// JoinLAN is used to have Consul join the inner-DC pool The target address
|
|
|
|
// should be another node inside the DC listening on the Serf LAN address
|
|
|
|
func (s *Server) JoinLAN(addrs []string, entMeta *structs.EnterpriseMeta) (int, error) {
|
|
|
|
return s.serfLAN.Join(addrs, true)
|
2017-12-20 21:43:38 +00:00
|
|
|
}
|
2021-07-22 18:58:08 +00:00
|
|
|
|
2021-11-15 15:51:14 +00:00
|
|
|
// removeFailedNode is used to remove a failed node from the cluster
|
2021-12-02 23:15:10 +00:00
|
|
|
//
|
|
|
|
// if node is empty, just remove wanNode from the WAN
|
2021-11-15 15:51:14 +00:00
|
|
|
func (s *Server) removeFailedNode(
|
|
|
|
removeFn func(*serf.Serf, string) error,
|
|
|
|
node, wanNode string,
|
|
|
|
entMeta *structs.EnterpriseMeta,
|
|
|
|
) error {
|
|
|
|
maybeRemove := func(s *serf.Serf, node string) (bool, error) {
|
|
|
|
if !isSerfMember(s, node) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return true, removeFn(s, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
foundAny := false
|
|
|
|
|
|
|
|
var merr error
|
|
|
|
|
2021-12-02 23:15:10 +00:00
|
|
|
if node != "" {
|
|
|
|
if found, err := maybeRemove(s.serfLAN, node); err != nil {
|
|
|
|
merr = multierror.Append(merr, fmt.Errorf("could not remove failed node from LAN: %w", err))
|
|
|
|
} else if found {
|
|
|
|
foundAny = true
|
|
|
|
}
|
2021-11-15 15:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if s.serfWAN != nil {
|
|
|
|
if found, err := maybeRemove(s.serfWAN, wanNode); err != nil {
|
|
|
|
merr = multierror.Append(merr, fmt.Errorf("could not remove failed node from WAN: %w", err))
|
|
|
|
} else if found {
|
|
|
|
foundAny = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if merr != nil {
|
|
|
|
return merr
|
|
|
|
}
|
|
|
|
|
|
|
|
if !foundAny {
|
|
|
|
return fmt.Errorf("agent: No node found with name '%s'", node)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-26 20:08:55 +00:00
|
|
|
|
|
|
|
// lanPoolAllMembers only returns our own segment or partition's members, because
|
|
|
|
// OSS servers can't be in multiple segments or partitions.
|
|
|
|
func (s *Server) lanPoolAllMembers() ([]serf.Member, error) {
|
|
|
|
return s.LANMembersInAgentPartition(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LANMembers returns the LAN members for one of:
|
|
|
|
//
|
|
|
|
// - the requested partition
|
|
|
|
// - the requested segment
|
|
|
|
// - all segments
|
|
|
|
//
|
|
|
|
// This is limited to segments and partitions that the node is a member of.
|
|
|
|
func (s *Server) LANMembers(filter LANMemberFilter) ([]serf.Member, error) {
|
|
|
|
if err := filter.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if filter.Segment != "" {
|
|
|
|
return nil, structs.ErrSegmentsNotSupported
|
|
|
|
}
|
|
|
|
return s.LANMembersInAgentPartition(), nil
|
|
|
|
}
|
2021-11-15 15:51:14 +00:00
|
|
|
|
|
|
|
func (s *Server) GetMatchingLANCoordinate(_, _ string) (*coordinate.Coordinate, error) {
|
|
|
|
return s.serfLAN.GetCoordinate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) addEnterpriseLANCoordinates(cs lib.CoordinateSet) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) LANSendUserEvent(name string, payload []byte, coalesce bool) error {
|
|
|
|
err := s.serfLAN.UserEvent(name, payload, coalesce)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error broadcasting event: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) DoWithLANSerfs(
|
|
|
|
fn func(name, poolKind string, pool *serf.Serf) error,
|
|
|
|
errorFn func(name, poolKind string, err error) error,
|
|
|
|
) error {
|
|
|
|
if errorFn == nil {
|
|
|
|
errorFn = func(_, _ string, err error) error { return err }
|
|
|
|
}
|
|
|
|
err := fn("", "", s.serfLAN)
|
|
|
|
if err != nil {
|
|
|
|
return errorFn("", "", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// left nodes are deregistered.
|
|
|
|
func (s *Server) reconcile() (err error) {
|
|
|
|
defer metrics.MeasureSince([]string{"leader", "reconcile"}, time.Now())
|
|
|
|
|
|
|
|
members := s.serfLAN.Members()
|
|
|
|
knownMembers := make(map[string]struct{})
|
|
|
|
for _, member := range members {
|
2022-02-24 22:54:47 +00:00
|
|
|
memberName := strings.ToLower(member.Name)
|
2021-11-15 15:51:14 +00:00
|
|
|
if err := s.reconcileMember(member); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-02-24 22:54:47 +00:00
|
|
|
knownMembers[memberName] = struct{}{}
|
2021-11-15 15:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reconcile any members that have been reaped while we were not the
|
|
|
|
// leader.
|
|
|
|
return s.reconcileReaped(knownMembers, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) addEnterpriseStats(stats map[string]map[string]string) {
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSerfMemberEnterpriseMeta(member serf.Member) *structs.EnterpriseMeta {
|
|
|
|
return structs.NodeEnterpriseMetaInDefaultPartition()
|
|
|
|
}
|