package server
import "github.com/coreos/etcd/server"
Index ¶
- Constants
- func NewListener(scheme, addr string, cfg *tls.Config) net.Listener
- func NewPackageStats(now time.Time, size int) *packageStats
- func NewRaftFollowersStats(name string) *raftFollowersStats
- func NewRaftServerStats(name string) *raftServerStats
- func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerStats, registry *Registry, dialTimeout, requestTimeout, responseHeaderTimeout time.Duration) *transporter
- func TLSServerConfig(info *TLSInfo) *tls.Config
- func Usage() string
- type Client
- func NewClient(transport http.RoundTripper) *Client
- func (c *Client) AddMachine(url string, cmd *JoinCommand) (uint64, *etcdErr.Error)
- func (c *Client) CheckVersion(url string, version int) (bool, *etcdErr.Error)
- func (c *Client) GetClusterConfig(url string) (*ClusterConfig, *etcdErr.Error)
- func (c *Client) GetMachines(url string) ([]*machineMessage, *etcdErr.Error)
- func (c *Client) GetVersion(url string) (int, *etcdErr.Error)
- type ClusterConfig
- type HEADResponseWriter
- type JoinCommand
- func (c *JoinCommand) Apply(context raft.Context) (interface{}, error)
- func (c *JoinCommand) CommandName() string
- func (c *JoinCommand) NodeName() string
- type PeerServer
- func NewPeerServer(psConfig PeerServerConfig, client *Client, registry *Registry, store store.Store, mb *metrics.Bucket, followersStats *raftFollowersStats, serverStats *raftServerStats) *PeerServer
- func (ps *PeerServer) AppendEntriesHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) ClusterConfig() *ClusterConfig
- func (ps *PeerServer) EtcdURLHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) FindCluster(discoverURL string, peers []string) (toStart bool, possiblePeers []string, err error)
- func (ps *PeerServer) GetLogHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) HTTPHandler() http.Handler
- func (s *PeerServer) InitNewCluster(clusterConfig *ClusterConfig)
- func (ps *PeerServer) JoinHttpHandler(w http.ResponseWriter, req *http.Request)
- func (ps *PeerServer) NameHttpHandler(w http.ResponseWriter, req *http.Request)
- func (ps *PeerServer) NextInternalVersionHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) PeerStats() []byte
- func (s *PeerServer) RaftServer() raft.Server
- func (ps *PeerServer) RemoveHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) RemoveNotify() <-chan bool
- func (s *PeerServer) SetClusterConfig(c *ClusterConfig)
- func (s *PeerServer) SetJoinIndex(joinIndex uint64)
- func (s *PeerServer) SetRaftServer(raftServer raft.Server, snapshot bool)
- func (s *PeerServer) SetRegistry(registry *Registry)
- func (s *PeerServer) SetServer(server *Server)
- func (s *PeerServer) SetStore(store store.Store)
- func (ps *PeerServer) SnapshotHttpHandler(w http.ResponseWriter, req *http.Request)
- func (ps *PeerServer) SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) Start(snapshot bool, clusterConfig *ClusterConfig) error
- func (s *PeerServer) Stats() []byte
- func (s *PeerServer) Stop()
- func (s *PeerServer) Upgradable() error
- func (ps *PeerServer) UpgradeHttpHandler(w http.ResponseWriter, req *http.Request)
- func (ps *PeerServer) VersionCheckHttpHandler(w http.ResponseWriter, req *http.Request)
- func (ps *PeerServer) VersionHttpHandler(w http.ResponseWriter, req *http.Request)
- func (ps *PeerServer) VoteHttpHandler(w http.ResponseWriter, req *http.Request)
- type PeerServerConfig
- type Registry
- func NewRegistry(s store.Store) *Registry
- func (r *Registry) ClientURL(name string) (string, bool)
- func (r *Registry) ClientURLs(leaderName, selfName string) []string
- func (r *Registry) Count() int
- func (r *Registry) Exists(name string) bool
- func (r *Registry) Invalidate(name string)
- func (r *Registry) Names() []string
- func (r *Registry) PeerHost(name string) (string, bool)
- func (r *Registry) PeerURL(name string) (string, bool)
- func (r *Registry) PeerURLs(leaderName, selfName string) []string
- func (r *Registry) Register(name string, peerURL string, machURL string) error
- func (r *Registry) Unregister(name string) error
- func (r *Registry) UpdatePeerURL(name string, peerURL string) error
- type RemoveCommand
- func (c *RemoveCommand) Apply(context raft.Context) (interface{}, error)
- func (c *RemoveCommand) CommandName() string
- type Server
- func New(name, url string, peerServer *PeerServer, registry *Registry, store store.Store, mb *metrics.Bucket) *Server
- func (s *Server) ClientURL(name string) (string, bool)
- func (s *Server) CommitIndex() uint64
- func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Request) error
- func (s *Server) EnableTracing()
- func (s *Server) GetLeaderHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) GetLeaderStatsHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) GetMetricsHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) GetPeersHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) GetStatsHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) GetStoreStatsHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) GetVersionHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) HTTPHandler() http.Handler
- func (s *Server) Leader() string
- func (s *Server) PeerHost(name string) (string, bool)
- func (s *Server) PeerURL(name string) (string, bool)
- func (s *Server) SetRegistry(registry *Registry)
- func (s *Server) SetStore(store store.Store)
- func (s *Server) SpeedTestHandler(w http.ResponseWriter, req *http.Request) error
- func (s *Server) State() string
- func (s *Server) Store() store.Store
- func (s *Server) Term() uint64
- func (s *Server) URL() string
- type SetClusterConfigCommand
- func (c *SetClusterConfigCommand) Apply(context raft.Context) (interface{}, error)
- func (c *SetClusterConfigCommand) CommandName() string
- type StandbyServer
- func NewStandbyServer(config StandbyServerConfig, client *Client) *StandbyServer
- func (s *StandbyServer) ClientHTTPHandler() http.Handler
- func (s *StandbyServer) ClusterLeader() *machineMessage
- func (s *StandbyServer) ClusterSize() int
- func (s *StandbyServer) ClusterURLs() []string
- func (s *StandbyServer) IsRunning() bool
- func (s *StandbyServer) JoinIndex() uint64
- func (s *StandbyServer) RemoveNotify() <-chan bool
- func (s *StandbyServer) SetRaftServer(raftServer raft.Server)
- func (s *StandbyServer) SetSyncInterval(second float64)
- func (s *StandbyServer) Start()
- func (s *StandbyServer) Stop()
- func (s *StandbyServer) SyncCluster(peers []string) error
- type StandbyServerConfig
- type TLSInfo
Constants ¶
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) )
const ( DefaultReadTimeout = float64((5 * time.Minute) / time.Second) DefaultWriteTimeout = float64((5 * time.Minute) / time.Second) )
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" )
const InternalVersion = "1"
const RegistryKey = "/_etcd/machines"
The location of the peer URL data.
const ReleaseVersion = "0.4.8"
const Version = "v2"
Functions ¶
func NewListener ¶
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 ¶
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 ¶
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 ¶
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 ¶
AddMachine adds machine to the cluster. The first return value is the commit index of join command.
func (*Client) CheckVersion ¶
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 (*Client) GetVersion ¶
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.
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) NextInternalVersionHandler ¶
func (ps *PeerServer) NextInternalVersionHandler(w http.ResponseWriter, req *http.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 ¶
The Registry stores URL information for nodes.
func NewRegistry ¶
Creates a new Registry.
func (*Registry) ClientURL ¶
Retrieves the client URL for a given node by name.
func (*Registry) ClientURLs ¶
Retrieves the Client URLs for all nodes.
func (*Registry) Count ¶
Count returns the number of peers in the cluster.
func (*Registry) Exists ¶
Exists checks if a peer with the given name exists.
func (*Registry) Invalidate ¶
Removes a node from the cache.
func (*Registry) Names ¶
Names returns a list of cached peer names.
func (*Registry) PeerHost ¶
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 ¶
Retrieves the peer URL for a given node by name.
func (*Registry) PeerURLs ¶
Retrieves the Peer URLs for all nodes.
func (*Registry) Register ¶
Register adds a peer to the registry.
func (*Registry) Unregister ¶
Unregister removes a peer from the registry.
func (*Registry) UpdatePeerURL ¶
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 ¶
ClientURL retrieves the Client URL for a given node name.
func (*Server) CommitIndex ¶
The current Raft committed index.
func (*Server) Dispatch ¶
Dispatch command to the current leader
func (*Server) EnableTracing ¶
func (s *Server) EnableTracing()
func (*Server) GetLeaderHandler ¶
Handler to return the current leader's raft address
func (*Server) GetLeaderStatsHandler ¶
Retrieves stats on the leader.
func (*Server) GetMetricsHandler ¶
Retrieves metrics from bucket
func (*Server) GetPeersHandler ¶
Handler to return all the known peers in the current cluster.
func (*Server) GetStatsHandler ¶
Retrieves stats on the Raft server.
func (*Server) GetStoreStatsHandler ¶
Retrieves stats on the leader.
func (*Server) GetVersionHandler ¶
Handler to return the current version of etcd.
func (*Server) HTTPHandler ¶
func (*Server) Leader ¶
The node name of the leader in the cluster.
func (*Server) PeerHost ¶
PeerHost retrieves the host part of Peer URL for a given node name.
func (*Server) PeerURL ¶
Retrives the Peer URL for a given node name.
func (*Server) SetRegistry ¶
func (*Server) SetStore ¶
func (*Server) SpeedTestHandler ¶
Executes a speed test to evaluate the performance of update replication.
func (*Server) State ¶
The current state of the server in the cluster.
func (*Server) Store ¶
Returns a reference to the Store.
func (*Server) Term ¶
The current Raft term.
func (*Server) URL ¶
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 ¶
Generates a tls.Config object for a client from the given files.
func (TLSInfo) Scheme ¶
func (TLSInfo) ServerConfig ¶
Generates a tls.Config object for a server from the given files.
Source Files ¶
client.go cluster_config.go join_command.go listener.go package_stats.go peer_server.go peer_server_handlers.go raft_follower_stats.go raft_server_stats.go registry.go remove_command.go server.go set_cluster_config_command.go standby_server.go stats_queue.go tls_info.go transporter.go usage.go version.go
Directories ¶
Path | Synopsis |
---|---|
server/v1 | |
server/v1/tests | |
server/v2 | |
server/v2/tests |
- Version
- v0.4.8
- Published
- Mar 23, 2015
- Platform
- js/wasm
- Imports
- 39 packages
- Last checked
- 3 hours ago –
Tools for package owners.