Documentation ¶
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, ...) *transporter
- func TLSServerConfig(info *TLSInfo) *tls.Config
- func Usage() string
- type ClusterConfig
- type DemoteCommand
- type HEADResponseWriter
- type JoinCommandV1
- type JoinCommandV2
- type Mode
- type 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 (ps *PeerServer) GetLogHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) HTTPHandler() http.Handler
- func (ps *PeerServer) JoinHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) Mode() Mode
- func (ps *PeerServer) NameHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) PeerStats() []byte
- func (ps *PeerServer) PromoteHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) RaftServer() raft.Server
- func (ps *PeerServer) RemoveHttpHandler(w http.ResponseWriter, req *http.Request)
- func (s *PeerServer) SetClusterConfig(c *ClusterConfig)
- func (s *PeerServer) SetRaftServer(raftServer raft.Server)
- func (s *PeerServer) SetServer(server *Server)
- 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, discoverURL string, peers []string) 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 (r *Registry) ClientURL(name string) (string, bool)
- func (r *Registry) ClientURLs(leaderName, selfName string) []string
- func (r *Registry) Invalidate(name string)
- func (r *Registry) PeerCount() int
- func (r *Registry) PeerExists(name string) bool
- 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) Peers() []string
- func (r *Registry) RegisterPeer(name string, peerURL string, machURL string) error
- func (r *Registry) RegisterStandby(name string, peerURL string, machURL string) error
- func (r *Registry) StandbyClientURL(name string) (string, bool)
- func (r *Registry) StandbyCount() int
- func (r *Registry) StandbyExists(name string) bool
- func (r *Registry) StandbyPeerURL(name string) (string, bool)
- func (r *Registry) Standbys() []string
- func (r *Registry) UnregisterPeer(name string) error
- func (r *Registry) UnregisterStandby(name string) error
- func (r *Registry) UpdatePeerURL(name string, peerURL string) error
- type RemoveCommandV1
- type RemoveCommandV2
- type 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) 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
- type TLSInfo
Constants ¶
const ( // DefaultActiveSize is the default number of active followers allowed. DefaultActiveSize = 9 // MinActiveSize is the minimum active size allowed. MinActiveSize = 3 // DefaultPromoteDelay is the default elapsed time before promotion. DefaultPromoteDelay = int((30 * time.Minute) / time.Second) // MinPromoteDelay is the minimum promote delay allowed. MinPromoteDelay = int((2 * time.Second) / time.Second) )
const ( // 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 different than the actual size then // etcd attempts to promote/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 )
const ( // PeerMode is when the server is an active node in Raft. PeerMode = Mode("peer") // StandbyMode is when the server is an inactive, request-forwarding node. StandbyMode = Mode("standby") )
const RegistryPeerKey = "/_etcd/machines"
The location of the peer URL data.
const RegistryStandbyKey = "/_etcd/standbys"
The location of the standby URL data.
const ReleaseVersion = "0.3.0+git"
const Version = "v2"
Variables ¶
This section is empty.
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
Types ¶
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"` // PromoteDelay is the amount of time, in seconds, after a node is // unreachable that it will be swapped out for a standby node, if available. PromoteDelay int `json:"promoteDelay"` }
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 DemoteCommand ¶
type DemoteCommand struct {
Name string `json:"name"`
}
DemoteCommand represents a command to change a peer to a standby.
func (*DemoteCommand) Apply ¶
func (c *DemoteCommand) Apply(context raft.Context) (interface{}, error)
Apply executes the command.
func (*DemoteCommand) CommandName ¶
func (c *DemoteCommand) CommandName() string
CommandName returns the name of the command.
func (*DemoteCommand) NodeName ¶
func (c *DemoteCommand) NodeName() string
NodeName returns the name of the affected node.
type HEADResponseWriter ¶
type HEADResponseWriter struct {
http.ResponseWriter
}
type JoinCommandV1 ¶
type JoinCommandV1 struct { MinVersion int `json:"minVersion"` MaxVersion int `json:"maxVersion"` Name string `json:"name"` RaftURL string `json:"raftURL"` EtcdURL string `json:"etcdURL"` }
JoinCommandV1 represents a request to join the cluster. The command returns the join_index (Uvarint).
func (*JoinCommandV1) Apply ¶
func (c *JoinCommandV1) Apply(context raft.Context) (interface{}, error)
Join a server to the cluster
func (*JoinCommandV1) CommandName ¶
func (c *JoinCommandV1) CommandName() string
The name of the join command in the log
func (*JoinCommandV1) NodeName ¶
func (c *JoinCommandV1) NodeName() string
type JoinCommandV2 ¶
type JoinCommandV2 struct { MinVersion int `json:"minVersion"` MaxVersion int `json:"maxVersion"` Name string `json:"name"` PeerURL string `json:"peerURL"` ClientURL string `json:"clientURL"` }
JoinCommandV2 represents a request to join the cluster.
func (*JoinCommandV2) Apply ¶
func (c *JoinCommandV2) Apply(context raft.Context) (interface{}, error)
Apply attempts to join a machine to the cluster.
func (*JoinCommandV2) CommandName ¶
func (c *JoinCommandV2) CommandName() string
CommandName returns the name of the command in the Raft log.
func (*JoinCommandV2) NodeName ¶
func (c *JoinCommandV2) NodeName() string
type Mode ¶
type Mode string
Mode represents whether the server is an active peer or if the server is simply acting as a standby.
type PeerServer ¶
type PeerServer struct { Config PeerServerConfig sync.Mutex // contains filtered or unexported fields }
func NewPeerServer ¶
func NewPeerServer(psConfig PeerServerConfig, 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) 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) JoinHttpHandler ¶
func (ps *PeerServer) JoinHttpHandler(w http.ResponseWriter, req *http.Request)
Response to the join request
func (*PeerServer) Mode ¶
func (s *PeerServer) Mode() Mode
Mode retrieves the current mode of the server.
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) PromoteHttpHandler ¶
func (ps *PeerServer) PromoteHttpHandler(w http.ResponseWriter, req *http.Request)
Attempt to rejoin the cluster as a peer.
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) SetClusterConfig ¶
func (s *PeerServer) SetClusterConfig(c *ClusterConfig)
SetClusterConfig updates the current cluster configuration. Adjusting the active size will cause the PeerServer to demote peers or promote standbys to match the new size.
func (*PeerServer) SetRaftServer ¶
func (s *PeerServer) SetRaftServer(raftServer raft.Server)
func (*PeerServer) SetServer ¶
func (s *PeerServer) SetServer(server *Server)
Associates the client server with the peer server.
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, discoverURL string, peers []string) error
Start the raft server
func (*PeerServer) Stats ¶
func (s *PeerServer) Stats() []byte
func (*PeerServer) Stop ¶
func (s *PeerServer) Stop()
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 Registry ¶
The Registry stores URL information for nodes.
func (*Registry) ClientURLs ¶
Retrieves the Client URLs for all nodes.
func (*Registry) Invalidate ¶
Removes a node from the cache.
func (*Registry) PeerExists ¶
PeerExists checks if a peer with the given name exists.
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) RegisterPeer ¶
RegisterPeer adds a peer to the registry.
func (*Registry) RegisterStandby ¶
RegisterStandby adds a standby to the registry.
func (*Registry) StandbyClientURL ¶
Retrieves the client URL for a given standby by name.
func (*Registry) StandbyCount ¶
StandbyCount returns the number of standbys in the cluster.
func (*Registry) StandbyExists ¶
StandbyExists checks if a standby with the given name exists.
func (*Registry) StandbyPeerURL ¶
Retrieves the peer URL for a given standby by name.
func (*Registry) UnregisterPeer ¶
UnregisterPeer removes a peer from the registry.
func (*Registry) UnregisterStandby ¶
UnregisterStandby removes a standby from the registry.
type RemoveCommandV1 ¶
type RemoveCommandV1 struct {
Name string `json:"name"`
}
The RemoveCommandV1 removes a server from the cluster.
func (*RemoveCommandV1) Apply ¶
func (c *RemoveCommandV1) Apply(context raft.Context) (interface{}, error)
Remove a server from the cluster
func (*RemoveCommandV1) CommandName ¶
func (c *RemoveCommandV1) CommandName() string
The name of the remove command in the log
type RemoveCommandV2 ¶
type RemoveCommandV2 struct {
Name string `json:"name"`
}
RemoveCommandV2 represents a command to remove a machine from the server.
func (*RemoveCommandV2) Apply ¶
func (c *RemoveCommandV2) Apply(context raft.Context) (interface{}, error)
Apply removes the given machine from the cluster.
func (*RemoveCommandV2) CommandName ¶
func (c *RemoveCommandV2) CommandName() string
CommandName returns the name of the command.
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) CommitIndex ¶
The current Raft committed index.
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) SpeedTestHandler ¶
Executes a speed test to evaluate the performance of update replication.
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.
Source Files ¶
- cluster_config.go
- demote_command.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
- release_version.go
- remove_command.go
- server.go
- set_cluster_config_command.go
- stats_queue.go
- tls_info.go
- transporter.go
- usage.go
- version.go