server

package
v0.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2013 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The amount of time to elapse without a heartbeat before becoming a candidate.
	ElectionTimeout = 200 * time.Millisecond

	// The frequency by which heartbeats are sent to followers.
	HeartbeatTimeout = 50 * time.Millisecond

	RetryInterval = 10
)
View Source
const DefaultSystemConfigPath = "/etc/etcd/etcd.conf"

The default location for the etcd configuration file.

View Source
const RegistryKey = "/_etcd/machines"

The location of the machine URL data.

View Source
const Version = "v2"

Variables

This section is empty.

Functions

func NewPackageStats

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

NewPackageStats creates a pacakgeStats and return the pointer to it.

Types

type Config

type Config struct {
	SystemPath string

	AdvertisedUrl    string   `toml:"advertised_url" env:"ETCD_ADVERTISED_URL"`
	CAFile           string   `toml:"ca_file" env:"ETCD_CA_FILE"`
	CertFile         string   `toml:"cert_file" env:"ETCD_CERT_FILE"`
	Cors             []string `toml:"cors" env:"ETCD_CORS"`
	DataDir          string   `toml:"datadir" env:"ETCD_DATADIR"`
	KeyFile          string   `toml:"key_file" env:"ETCD_KEY_FILE"`
	ListenHost       string   `toml:"listen_host" env:"ETCD_LISTEN_HOST"`
	Machines         []string `toml:"machines" env:"ETCD_MACHINES"`
	MachinesFile     string   `toml:"machines_file" env:"ETCD_MACHINES_FILE"`
	MaxClusterSize   int      `toml:"max_cluster_size" env:"ETCD_MAX_CLUSTER_SIZE"`
	MaxResultBuffer  int      `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"`
	MaxRetryAttempts int      `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"`
	Name             string   `toml:"name" env:"ETCD_NAME"`
	Snapshot         bool     `toml:"snapshot" env:"ETCD_SNAPSHOT"`
	SnapCount        int      `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
	Verbose          bool     `toml:"verbose" env:"ETCD_VERBOSE"`
	VeryVerbose      bool     `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
	WebURL           string   `toml:"web_url" env:"ETCD_WEB_URL"`

	Peer struct {
		AdvertisedUrl string `toml:"advertised_url" env:"ETCD_PEER_ADVERTISED_URL"`
		CAFile        string `toml:"ca_file" env:"ETCD_PEER_CA_FILE"`
		CertFile      string `toml:"cert_file" env:"ETCD_PEER_CERT_FILE"`
		KeyFile       string `toml:"key_file" env:"ETCD_PEER_KEY_FILE"`
		ListenHost    string `toml:"listen_host" env:"ETCD_PEER_LISTEN_HOST"`
	}
}

Config represents the server configuration.

func NewConfig

func NewConfig() *Config

NewConfig returns a Config initialized with default values.

func (*Config) Info

func (c *Config) Info() (*Info, error)

Reads the info file from the file system or initializes it based on the config.

func (*Config) Load

func (c *Config) Load(arguments []string) error

Loads the configuration from the system config, command line config, environment variables, and finally command line arguments.

func (*Config) LoadEnv

func (c *Config) LoadEnv() error

LoadEnv loads the configuration via environment variables.

func (*Config) LoadFile

func (c *Config) LoadFile(path string) error

Loads configuration from a file.

func (*Config) LoadFlags

func (c *Config) LoadFlags(arguments []string) error

Loads configuration from command line flags.

func (*Config) LoadMachineFile

func (c *Config) LoadMachineFile() error

LoadMachineFile loads the machines listed in the machine file.

func (*Config) LoadSystemFile

func (c *Config) LoadSystemFile() error

Loads from the system etcd configuration file if it exists.

func (*Config) PeerTLSConfig

func (c *Config) PeerTLSConfig() (TLSConfig, error)

PeerTLSConfig generates the TLS configuration for the peer server.

func (*Config) PeerTLSInfo

func (c *Config) PeerTLSInfo() TLSInfo

PeerTLSInfo retrieves a TLSInfo object for the peer server.

func (*Config) Reset

func (c *Config) Reset() error

Reset removes all server configuration files.

func (*Config) Sanitize

func (c *Config) Sanitize() error

Sanitize cleans the input fields.

func (*Config) TLSConfig

func (c *Config) TLSConfig() (TLSConfig, error)

ClientTLSConfig generates the TLS configuration for the client server.

func (*Config) TLSInfo

func (c *Config) TLSInfo() TLSInfo

TLSInfo retrieves a TLSInfo object for the client server.

type Info

type Info struct {
	Name string `json:"name"`

	RaftURL string `json:"raftURL"`
	EtcdURL string `json:"etcdURL"`
	WebURL  string `json:"webURL"`

	RaftListenHost string `json:"raftListenHost"`
	EtcdListenHost string `json:"etcdListenHost"`

	RaftTLS TLSInfo `json:"raftTLS"`
	EtcdTLS TLSInfo `json:"etcdTLS"`
}

Info describes the non-mutable state of the server upon initialization. These fields cannot be changed without deleting the server fields and reinitializing.

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"`
}

The JoinCommand adds a node to the cluster.

func NewJoinCommand

func NewJoinCommand(minVersion int, maxVersion int, name, raftUrl, etcdUrl string) *JoinCommand

func (*JoinCommand) Apply

func (c *JoinCommand) Apply(server raft.Server) (interface{}, error)

Join a server 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 {
	MaxClusterSize int
	RetryTimes     int
	// contains filtered or unexported fields
}

func NewPeerServer

func NewPeerServer(name string, path string, url string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo, registry *Registry, store store.Store, snapCount int) *PeerServer

func (*PeerServer) AppendEntriesHttpHandler

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

Response to append entries request

func (*PeerServer) Close

func (s *PeerServer) Close()

Stops the server.

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) JoinHttpHandler

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

Response to the join request

func (*PeerServer) ListenAndServe

func (s *PeerServer) ListenAndServe(snapshot bool, cluster []string) error

Start the raft 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) 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) 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) Stats

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

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 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

Returns the number of nodes in the cluster.

func (*Registry) Invalidate

func (r *Registry) Invalidate(name string)

Removes a node from the cache.

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, url string) error

Adds a node to the registry.

func (*Registry) Unregister

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

Removes a node from the 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(server raft.Server) (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 {
	http.Server
	// contains filtered or unexported fields
}

This is the default implementation of the Server interface.

func New

func New(name string, urlStr string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo, peerServer *PeerServer, registry *Registry, store store.Store) *Server

Creates a new Server.

func (*Server) AllowOrigins

func (s *Server) AllowOrigins(origins []string) error

Sets a comma-delimited list of origins that are allowed.

func (*Server) Close

func (s *Server) Close()

Stops the server.

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) 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) GetMachinesHandler

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

Handler to return all the known machines 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) Leader

func (s *Server) Leader() string

The node name of the leader in the cluster.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

Start to listen and response etcd client command

func (*Server) OriginAllowed

func (s *Server) OriginAllowed(origin string) bool

Determines whether the server will allow a given CORS origin.

func (*Server) PeerURL

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

Retrives the Peer URL for a given node name.

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 TLSConfig

type TLSConfig struct {
	Scheme string
	Server tls.Config
	Client tls.Config
}

TLSConfig holds the TLS configuration.

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) Config

func (info TLSInfo) Config() (TLSConfig, error)

Generates a TLS configuration 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