server

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2015 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultActiveSize is the default number of active followers allowed.
	DefaultActiveSize = 9

	// MinActiveSize is the minimum active size allowed.
	MinActiveSize = 3

	// DefaultRemoveDelay is the default elapsed time before removal.
	DefaultRemoveDelay = float64((30 * time.Minute) / time.Second)

	// MinRemoveDelay is the minimum remove delay allowed.
	MinRemoveDelay = float64((2 * time.Second) / time.Second)

	// DefaultSyncInterval is the default interval for cluster sync.
	DefaultSyncInterval = float64((5 * time.Second) / time.Second)

	// MinSyncInterval is the minimum sync interval allowed.
	MinSyncInterval = float64((1 * time.Second) / time.Second)
)
View Source
const (
	// MaxHeartbeatTimeoutBackoff is the maximum number of seconds before we warn
	// the user again about a peer not accepting heartbeats.
	MaxHeartbeatTimeoutBackoff = 15 * time.Second

	// ThresholdMonitorTimeout is the time between log notifications that the
	// Raft heartbeat is too close to the election timeout.
	ThresholdMonitorTimeout = 5 * time.Second

	// ActiveMonitorTimeout is the time between checks on the active size of
	// the cluster. If the active size is bigger than the actual size then
	// etcd attempts to demote to bring it to the correct number.
	ActiveMonitorTimeout = 1 * time.Second

	// PeerActivityMonitorTimeout is the time between checks for dead nodes in
	// the cluster.
	PeerActivityMonitorTimeout = 1 * time.Second

	// The location of cluster config in key space.
	ClusterConfigKey = "/_etcd/config"
)
View Source
const RegistryKey = "/_etcd/machines"

The location of the peer URL data.

View Source
const ReleaseVersion = "0.4.3+git"
View Source
const Version = "v2"

Variables

This section is empty.

Functions

func NewListener

func NewListener(scheme, addr string, cfg *tls.Config) net.Listener

NewListener creates a net.Listener If the given scheme is "https", it will use TLS config to set listener. If any error happens, this function will call log.Fatal

func NewPackageStats

func NewPackageStats(now time.Time, size int) *packageStats

NewPackageStats creates a pacakgeStats and return the pointer to it.

func NewRaftFollowersStats

func NewRaftFollowersStats(name string) *raftFollowersStats

func NewRaftServerStats

func NewRaftServerStats(name string) *raftServerStats

func NewTransporter

func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerStats, registry *Registry, dialTimeout, requestTimeout, responseHeaderTimeout time.Duration) *transporter

Create transporter using by raft server Create http or https transporter based on whether the user give the server cert and key

func TLSServerConfig

func TLSServerConfig(info *TLSInfo) *tls.Config

TLSServerConfig generates tls configuration based on TLSInfo If any error happens, this function will call log.Fatal

func Usage

func Usage() string

Usage returns the usage message for etcd.

Types

type Client

type Client struct {
	http.Client
}

Client sends various requests using HTTP API. It is different from raft communication, and doesn't record anything in the log. The argument url is required to contain scheme and host only, and there is no trailing slash in it. Public functions return "etcd/error".Error intentionally to figure out etcd error code easily. TODO(yichengq): It is similar to go-etcd. But it could have many efforts to integrate the two. Leave it for further discussion.

func NewClient

func NewClient(transport http.RoundTripper) *Client

func (*Client) AddMachine

func (c *Client) AddMachine(url string, cmd *JoinCommand) (uint64, *etcdErr.Error)

AddMachine adds machine to the cluster. The first return value is the commit index of join command.

func (*Client) CheckVersion

func (c *Client) CheckVersion(url string, version int) (bool, *etcdErr.Error)

CheckVersion returns true when the version check on the server returns 200.

func (*Client) GetClusterConfig

func (c *Client) GetClusterConfig(url string) (*ClusterConfig, *etcdErr.Error)

func (*Client) GetMachines

func (c *Client) GetMachines(url string) ([]*machineMessage, *etcdErr.Error)

func (*Client) GetVersion

func (c *Client) GetVersion(url string) (int, *etcdErr.Error)

GetVersion fetches the peer version of a cluster.

type ClusterConfig

type ClusterConfig struct {
	// ActiveSize is the maximum number of node that can join as Raft followers.
	// Nodes that join the cluster after the limit is reached are standbys.
	ActiveSize int `json:"activeSize"`

	// RemoveDelay is the amount of time, in seconds, after a node is
	// unreachable that it will be swapped out as a standby node.
	RemoveDelay float64 `json:"removeDelay"`

	// SyncInterval is the amount of time, in seconds, between
	// cluster sync when it runs in standby mode.
	SyncInterval float64 `json:"syncInterval"`
}

ClusterConfig represents cluster-wide configuration settings. These settings can only be changed through Raft.

func NewClusterConfig

func NewClusterConfig() *ClusterConfig

NewClusterConfig returns a cluster configuration with default settings.

type HEADResponseWriter

type HEADResponseWriter struct {
	http.ResponseWriter
}

func (*HEADResponseWriter) Write

func (w *HEADResponseWriter) Write([]byte) (int, error)

type JoinCommand

type JoinCommand struct {
	MinVersion int    `json:"minVersion"`
	MaxVersion int    `json:"maxVersion"`
	Name       string `json:"name"`
	RaftURL    string `json:"raftURL"`
	EtcdURL    string `json:"etcdURL"`
}

JoinCommand represents a request to join the cluster. The command returns the join_index (Uvarint).

func (*JoinCommand) Apply

func (c *JoinCommand) Apply(context raft.Context) (interface{}, error)

Apply attempts to join a machine to the cluster.

func (*JoinCommand) CommandName

func (c *JoinCommand) CommandName() string

The name of the join command in the log

func (*JoinCommand) NodeName

func (c *JoinCommand) NodeName() string

type PeerServer

type PeerServer struct {
	Config PeerServerConfig

	sync.Mutex
	// contains filtered or unexported fields
}

func NewPeerServer

func NewPeerServer(psConfig PeerServerConfig, client *Client, registry *Registry, store store.Store, mb *metrics.Bucket, followersStats *raftFollowersStats, serverStats *raftServerStats) *PeerServer

func (*PeerServer) AppendEntriesHttpHandler

func (ps *PeerServer) AppendEntriesHttpHandler(w http.ResponseWriter, req *http.Request)

Response to append entries request

func (*PeerServer) ClusterConfig

func (s *PeerServer) ClusterConfig() *ClusterConfig

ClusterConfig retrieves the current cluster configuration.

func (*PeerServer) EtcdURLHttpHandler

func (ps *PeerServer) EtcdURLHttpHandler(w http.ResponseWriter, req *http.Request)

Get the port that listening for etcd connecting of the server

func (*PeerServer) FindCluster

func (s *PeerServer) FindCluster(discoverURL string, peers []string) (toStart bool, possiblePeers []string, err error)

Try all possible ways to find clusters to join Include log data in -data-dir, -discovery and -peers

Peer discovery follows this order: 1. previous peers in -data-dir 2. -discovery 3. -peers

func (*PeerServer) GetLogHttpHandler

func (ps *PeerServer) GetLogHttpHandler(w http.ResponseWriter, req *http.Request)

Get all the current logs

func (*PeerServer) HTTPHandler

func (s *PeerServer) HTTPHandler() http.Handler

func (*PeerServer) InitNewCluster

func (s *PeerServer) InitNewCluster(clusterConfig *ClusterConfig)

func (*PeerServer) JoinHttpHandler

func (ps *PeerServer) JoinHttpHandler(w http.ResponseWriter, req *http.Request)

Response to the join request

func (*PeerServer) NameHttpHandler

func (ps *PeerServer) NameHttpHandler(w http.ResponseWriter, req *http.Request)

Response to the name request

func (*PeerServer) PeerStats

func (s *PeerServer) PeerStats() []byte

func (*PeerServer) RaftServer

func (s *PeerServer) RaftServer() raft.Server

Retrieves the underlying Raft server.

func (*PeerServer) RemoveHttpHandler

func (ps *PeerServer) RemoveHttpHandler(w http.ResponseWriter, req *http.Request)

Response to remove request

func (*PeerServer) RemoveNotify

func (s *PeerServer) RemoveNotify() <-chan bool

RemoveNotify notifies the server is removed from peer mode due to removal from the cluster.

func (*PeerServer) SetClusterConfig

func (s *PeerServer) SetClusterConfig(c *ClusterConfig)

SetClusterConfig updates the current cluster configuration. Adjusting the active size will cause cluster to add or remove machines to match the new size.

func (*PeerServer) SetJoinIndex

func (s *PeerServer) SetJoinIndex(joinIndex uint64)

func (*PeerServer) SetRaftServer

func (s *PeerServer) SetRaftServer(raftServer raft.Server, snapshot bool)

func (*PeerServer) SetRegistry

func (s *PeerServer) SetRegistry(registry *Registry)

func (*PeerServer) SetServer

func (s *PeerServer) SetServer(server *Server)

Associates the client server with the peer server.

func (*PeerServer) SetStore

func (s *PeerServer) SetStore(store store.Store)

func (*PeerServer) SnapshotHttpHandler

func (ps *PeerServer) SnapshotHttpHandler(w http.ResponseWriter, req *http.Request)

Response to recover from snapshot request

func (*PeerServer) SnapshotRecoveryHttpHandler

func (ps *PeerServer) SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request)

Response to recover from snapshot request

func (*PeerServer) Start

func (s *PeerServer) Start(snapshot bool, clusterConfig *ClusterConfig) error

Start starts the raft server. The function assumes that join has been accepted successfully.

func (*PeerServer) Stats

func (s *PeerServer) Stats() []byte

func (*PeerServer) Stop

func (s *PeerServer) Stop()

Stop stops the server gracefully.

func (*PeerServer) Upgradable

func (s *PeerServer) Upgradable() error

Upgradable checks whether all peers in a cluster support an upgrade to the next store version.

func (*PeerServer) UpgradeHttpHandler

func (ps *PeerServer) UpgradeHttpHandler(w http.ResponseWriter, req *http.Request)

Upgrades the current store version to the next version.

func (*PeerServer) VersionCheckHttpHandler

func (ps *PeerServer) VersionCheckHttpHandler(w http.ResponseWriter, req *http.Request)

Checks whether a given version is supported.

func (*PeerServer) VersionHttpHandler

func (ps *PeerServer) VersionHttpHandler(w http.ResponseWriter, req *http.Request)

Response to the name request

func (*PeerServer) VoteHttpHandler

func (ps *PeerServer) VoteHttpHandler(w http.ResponseWriter, req *http.Request)

Response to vote request

type PeerServerConfig

type PeerServerConfig struct {
	Name          string
	Scheme        string
	URL           string
	SnapshotCount int
	RetryTimes    int
	RetryInterval float64
}

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

The Registry stores URL information for nodes.

func NewRegistry

func NewRegistry(s store.Store) *Registry

Creates a new Registry.

func (*Registry) ClientURL

func (r *Registry) ClientURL(name string) (string, bool)

Retrieves the client URL for a given node by name.

func (*Registry) ClientURLs

func (r *Registry) ClientURLs(leaderName, selfName string) []string

Retrieves the Client URLs for all nodes.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of peers in the cluster.

func (*Registry) Exists

func (r *Registry) Exists(name string) bool

Exists checks if a peer with the given name exists.

func (*Registry) Invalidate

func (r *Registry) Invalidate(name string)

Removes a node from the cache.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns a list of cached peer names.

func (*Registry) PeerHost

func (r *Registry) PeerHost(name string) (string, bool)

TODO(yichengq): have all of the code use a full URL with scheme and remove this method PeerHost retrieves the host part of peer URL for a given node by name.

func (*Registry) PeerURL

func (r *Registry) PeerURL(name string) (string, bool)

Retrieves the peer URL for a given node by name.

func (*Registry) PeerURLs

func (r *Registry) PeerURLs(leaderName, selfName string) []string

Retrieves the Peer URLs for all nodes.

func (*Registry) Register

func (r *Registry) Register(name string, peerURL string, machURL string) error

Register adds a peer to the registry.

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a peer from the registry.

func (*Registry) UpdatePeerURL

func (r *Registry) UpdatePeerURL(name string, peerURL string) error

UpdatePeerURL updates peer URL in registry

type RemoveCommand

type RemoveCommand struct {
	Name string `json:"name"`
}

The RemoveCommand removes a server from the cluster.

func (*RemoveCommand) Apply

func (c *RemoveCommand) Apply(context raft.Context) (interface{}, error)

Remove a server from the cluster

func (*RemoveCommand) CommandName

func (c *RemoveCommand) CommandName() string

The name of the remove command in the log

type Server

type Server struct {
	Name string
	// contains filtered or unexported fields
}

This is the default implementation of the Server interface.

func New

func New(name, url string, peerServer *PeerServer, registry *Registry, store store.Store, mb *metrics.Bucket) *Server

Creates a new Server.

func (*Server) ClientURL

func (s *Server) ClientURL(name string) (string, bool)

ClientURL retrieves the Client URL for a given node name.

func (*Server) CommitIndex

func (s *Server) CommitIndex() uint64

The current Raft committed index.

func (*Server) Dispatch

func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Request) error

Dispatch command to the current leader

func (*Server) EnableTracing

func (s *Server) EnableTracing()

func (*Server) GetLeaderHandler

func (s *Server) GetLeaderHandler(w http.ResponseWriter, req *http.Request) error

Handler to return the current leader's raft address

func (*Server) GetLeaderStatsHandler

func (s *Server) GetLeaderStatsHandler(w http.ResponseWriter, req *http.Request) error

Retrieves stats on the leader.

func (*Server) GetMetricsHandler

func (s *Server) GetMetricsHandler(w http.ResponseWriter, req *http.Request) error

Retrieves metrics from bucket

func (*Server) GetPeersHandler

func (s *Server) GetPeersHandler(w http.ResponseWriter, req *http.Request) error

Handler to return all the known peers in the current cluster.

func (*Server) GetStatsHandler

func (s *Server) GetStatsHandler(w http.ResponseWriter, req *http.Request) error

Retrieves stats on the Raft server.

func (*Server) GetStoreStatsHandler

func (s *Server) GetStoreStatsHandler(w http.ResponseWriter, req *http.Request) error

Retrieves stats on the leader.

func (*Server) GetVersionHandler

func (s *Server) GetVersionHandler(w http.ResponseWriter, req *http.Request) error

Handler to return the current version of etcd.

func (*Server) HTTPHandler

func (s *Server) HTTPHandler() http.Handler

func (*Server) Leader

func (s *Server) Leader() string

The node name of the leader in the cluster.

func (*Server) PeerHost

func (s *Server) PeerHost(name string) (string, bool)

PeerHost retrieves the host part of Peer URL for a given node name.

func (*Server) PeerURL

func (s *Server) PeerURL(name string) (string, bool)

Retrives the Peer URL for a given node name.

func (*Server) SetRegistry

func (s *Server) SetRegistry(registry *Registry)

func (*Server) SetStore

func (s *Server) SetStore(store store.Store)

func (*Server) SpeedTestHandler

func (s *Server) SpeedTestHandler(w http.ResponseWriter, req *http.Request) error

Executes a speed test to evaluate the performance of update replication.

func (*Server) State

func (s *Server) State() string

The current state of the server in the cluster.

func (*Server) Store

func (s *Server) Store() store.Store

Returns a reference to the Store.

func (*Server) Term

func (s *Server) Term() uint64

The current Raft term.

func (*Server) URL

func (s *Server) URL() string

The server URL.

type SetClusterConfigCommand

type SetClusterConfigCommand struct {
	Config *ClusterConfig `json:"config"`
}

SetClusterConfigCommand sets the cluster-level configuration.

func (*SetClusterConfigCommand) Apply

func (c *SetClusterConfigCommand) Apply(context raft.Context) (interface{}, error)

Apply updates the cluster configuration.

func (*SetClusterConfigCommand) CommandName

func (c *SetClusterConfigCommand) CommandName() string

CommandName returns the name of the command.

type StandbyServer

type StandbyServer struct {
	Config StandbyServerConfig

	sync.Mutex
	// contains filtered or unexported fields
}

func NewStandbyServer

func NewStandbyServer(config StandbyServerConfig, client *Client) *StandbyServer

func (*StandbyServer) ClientHTTPHandler

func (s *StandbyServer) ClientHTTPHandler() http.Handler

func (*StandbyServer) ClusterLeader

func (s *StandbyServer) ClusterLeader() *machineMessage

func (*StandbyServer) ClusterSize

func (s *StandbyServer) ClusterSize() int

func (*StandbyServer) ClusterURLs

func (s *StandbyServer) ClusterURLs() []string

func (*StandbyServer) IsRunning

func (s *StandbyServer) IsRunning() bool

func (*StandbyServer) JoinIndex

func (s *StandbyServer) JoinIndex() uint64

func (*StandbyServer) RemoveNotify

func (s *StandbyServer) RemoveNotify() <-chan bool

RemoveNotify notifies the server is removed from standby mode and ready for peer mode. It should have joined the cluster successfully.

func (*StandbyServer) SetRaftServer

func (s *StandbyServer) SetRaftServer(raftServer raft.Server)

func (*StandbyServer) SetSyncInterval

func (s *StandbyServer) SetSyncInterval(second float64)

func (*StandbyServer) Start

func (s *StandbyServer) Start()

func (*StandbyServer) Stop

func (s *StandbyServer) Stop()

Stop stops the server gracefully.

func (*StandbyServer) SyncCluster

func (s *StandbyServer) SyncCluster(peers []string) error

type StandbyServerConfig

type StandbyServerConfig struct {
	Name       string
	PeerScheme string
	PeerURL    string
	ClientURL  string
	DataDir    string
}

type TLSInfo

type TLSInfo struct {
	CertFile string `json:"CertFile"`
	KeyFile  string `json:"KeyFile"`
	CAFile   string `json:"CAFile"`
}

TLSInfo holds the SSL certificates paths.

func (TLSInfo) ClientConfig

func (info TLSInfo) ClientConfig() (*tls.Config, error)

Generates a tls.Config object for a client from the given files.

func (TLSInfo) Scheme

func (info TLSInfo) Scheme() string

func (TLSInfo) ServerConfig

func (info TLSInfo) ServerConfig() (*tls.Config, error)

Generates a tls.Config object for a server from the given files.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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