servers

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2017 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package servers provides a Manager interface for Manager managed agent.Server objects. The servers package manages servers from a Consul client's perspective (i.e. a list of servers that a client talks with for RPCs). The servers package does not provide any API guarantees and should be called only by `hashicorp/consul`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsulClusterInfo

type ConsulClusterInfo interface {
	NumNodes() int
}

ConsulClusterInfo is an interface wrapper around serf in order to prevent a cyclic import dependency.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(logger *log.Logger, shutdownCh chan struct{}, clusterInfo ConsulClusterInfo, connPoolPinger Pinger) (m *Manager)

New is the only way to safely create a new Manager struct.

func (*Manager) AddServer

func (m *Manager) AddServer(s *agent.Server)

AddServer takes out an internal write lock and adds a new server. If the server is not known, appends the server to the list. The new server will begin seeing use after the rebalance timer fires or enough servers fail organically. If the server is already known, merge the new server details.

func (*Manager) FindServer

func (m *Manager) FindServer() *agent.Server

FindServer takes out an internal "read lock" and searches through the list of servers to find a "healthy" server. If the server is actually unhealthy, we rely on Serf to detect this and remove the node from the server list. If the server at the front of the list has failed or fails during an RPC call, it is rotated to the end of the list. If there are no servers available, return nil.

func (*Manager) NotifyFailedServer

func (m *Manager) NotifyFailedServer(s *agent.Server)

NotifyFailedServer marks the passed in server as "failed" by rotating it to the end of the server list.

func (*Manager) NumServers

func (m *Manager) NumServers() int

NumServers takes out an internal "read lock" and returns the number of servers. numServers includes both healthy and unhealthy servers.

func (*Manager) RebalanceServers

func (m *Manager) RebalanceServers()

RebalanceServers shuffles the list of servers on this agent. The server at the front of the list is selected for the next RPC. RPC calls that fail for a particular server are rotated to the end of the list. This method reshuffles the list periodically in order to redistribute work across all known consul servers (i.e. guarantee that the order of servers in the server list is not positively correlated with the age of a server in the Consul cluster). Periodically shuffling the server list prevents long-lived clients from fixating on long-lived servers.

Unhealthy servers are removed when serf notices the server has been deregistered. Before the newly shuffled server list is saved, the new remote endpoint is tested to ensure its responsive.

func (*Manager) RemoveServer

func (m *Manager) RemoveServer(s *agent.Server)

RemoveServer takes out an internal write lock and removes a server from the server list.

func (*Manager) ResetRebalanceTimer

func (m *Manager) ResetRebalanceTimer()

ResetRebalanceTimer resets the rebalance timer. This method exists for testing and should not be used directly.

func (*Manager) Start

func (m *Manager) Start()

Start is used to start and manage the task of automatically shuffling and rebalancing the list of Consul servers. This maintenance only happens periodically based on the expiration of the timer. Failed servers are automatically cycled to the end of the list. New servers are appended to the list. The order of the server list must be shuffled periodically to distribute load across all known and available Consul servers.

type Pinger

type Pinger interface {
	PingConsulServer(s *agent.Server) (bool, error)
}

Pinger is an interface wrapping client.ConnPool to prevent a cyclic import dependency.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL