server

package
v0.2.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2013 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

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

func Usage

func Usage() string

Usage returns the usage message for etcd.

Types

type Config

type Config struct {
	SystemPath string

	Addr             string `toml:"addr" env:"ETCD_ADDR"`
	BindAddr         string `toml:"bind_addr" env:"ETCD_BIND_ADDR"`
	CAFile           string `toml:"ca_file" env:"ETCD_CA_FILE"`
	CertFile         string `toml:"cert_file" env:"ETCD_CERT_FILE"`
	CPUProfileFile   string
	CorsOrigins      []string `toml:"cors" env:"ETCD_CORS"`
	DataDir          string   `toml:"data_dir" env:"ETCD_DATA_DIR"`
	Force            bool
	KeyFile          string   `toml:"key_file" env:"ETCD_KEY_FILE"`
	Peers            []string `toml:"peers" env:"ETCD_PEERS"`
	PeersFile        string   `toml:"peers_file" env:"ETCD_PEERS_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"`
	SnapshotCount    int      `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
	ShowHelp         bool
	ShowVersion      bool
	Verbose          bool `toml:"verbose" env:"ETCD_VERBOSE"`
	VeryVerbose      bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
	Peer             struct {
		Addr             string `toml:"addr" env:"ETCD_PEER_ADDR"`
		BindAddr         string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"`
		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"`
		HeartbeatTimeout int    `toml:"heartbeat_timeout" env:"ETCD_PEER_HEARTBEAT_TIMEOUT"`
		ElectionTimeout  int    `toml:"election_timeout" env:"ETCD_PEER_ELECTION_TIMEOUT"`
	}
}

Config represents the server configuration.

func NewConfig

func NewConfig() *Config

NewConfig returns a Config initialized with default values.

func (*Config) DataDirFromName

func (c *Config) DataDirFromName()

DataDirFromName sets the data dir from a machine name and issue a warning that etcd is guessing.

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

func (c *Config) LoadPeersFile() error

LoadPeersFile loads the peers listed in the peers file.

func (*Config) LoadSystemFile

func (c *Config) LoadSystemFile() error

Loads from the system etcd configuration file if it exists.

func (*Config) NameFromHostname

func (c *Config) NameFromHostname()

NameFromHostname sets the machine name from the hostname. This is to help people get started without thinking up a name.

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

	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
	HeartbeatTimeout time.Duration
	ElectionTimeout  time.Duration
	// contains filtered or unexported fields
}

func NewPeerServer

func NewPeerServer(name string, path string, url string, bindAddr string, tlsConf *TLSConfig, tlsInfo *TLSInfo, registry *Registry, store store.Store, snapshotCount 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, machURL 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, bindAddr 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

AllowOrigins sets a comma-delimited list of origins that are allowed.

func (*Server) ClientURL

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

ClientURL retrieves the Client URL for a given node name.

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

OriginAllowed 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