etcdserver

package
v0.4.7-0...-09e9618 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2014 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSnapCount = 10000

	StoreAdminPrefix = "/0"
	StoreKeysPrefix  = "/1"
)
View Source
const (
	ClusterStateValueNew = "new"
)

Variables

View Source
var (
	ErrUnknownMethod = errors.New("etcdserver: unknown method")
	ErrStopped       = errors.New("etcdserver: server stopped")
	ErrRemoved       = errors.New("etcdserver: server removed")
	ErrIDRemoved     = errors.New("etcdserver: ID removed")
	ErrIDExists      = errors.New("etcdserver: ID exists")
	ErrIDNotFound    = errors.New("etcdserver: ID not found")
)
View Source
var (
	ClusterStateValues = []string{
		ClusterStateValueNew,
	}
)

Functions

func GenID

func GenID() (n uint64)

TODO: move the function to /id pkg maybe? GenID generates a random id that is not equal to 0.

func Sender

func Sender(t *http.Transport, cls ClusterStore, ss *stats.ServerStats, ls *stats.LeaderStats) func(msgs []raftpb.Message)

Sender creates the default production sender used to transport raft messages in the cluster. The returned sender will update the given ServerStats and LeaderStats appropriately.

Types

type Attributes

type Attributes struct {
	Name       string   `json:",omitempty"`
	ClientURLs []string `json:",omitempty"`
}

Attributes represents all the non-raft related attributes of an etcd member.

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

Cluster is a list of Members that belong to the same raft cluster

func NewCluster

func NewCluster(clusterName string) *Cluster

func (Cluster) Add

func (c Cluster) Add(m Member) error

func (*Cluster) AddMemberFromURLs

func (c *Cluster) AddMemberFromURLs(name string, urls types.URLs) (*Member, error)

func (*Cluster) AddSlice

func (c *Cluster) AddSlice(mems []Member) error

func (Cluster) ClientURLs

func (c Cluster) ClientURLs() []string

ClientURLs returns a list of all client addresses. Each address is prefixed with the scheme (currently "http://"). The returned list is sorted in ascending lexicographical order.

func (Cluster) FindID

func (c Cluster) FindID(id uint64) *Member

func (Cluster) FindName

func (c Cluster) FindName(name string) *Member

func (*Cluster) GenID

func (c *Cluster) GenID(salt []byte)

func (Cluster) ID

func (c Cluster) ID() uint64

func (Cluster) MemberIDs

func (c Cluster) MemberIDs() []uint64

func (Cluster) Members

func (c Cluster) Members() map[uint64]*Member

func (Cluster) PeerURLs

func (c Cluster) PeerURLs() []string

PeerURLs returns a list of all peer addresses. Each address is prefixed with the scheme (currently "http://"). The returned list is sorted in ascending lexicographical order.

func (Cluster) Pick

func (c Cluster) Pick(id uint64) string

Pick chooses a random address from a given Member's addresses, and returns it as an addressible URI. If the given member does not exist, an empty string is returned.

func (*Cluster) SetMembersFromString

func (c *Cluster) SetMembersFromString(s string) error

SetMembersFromString parses a sets of names to IPs either from the command line or discovery formatted like: mach0=http://1.1.1.1,mach0=http://2.2.2.2,mach0=http://1.1.1.1,mach1=http://2.2.2.2,mach1=http://3.3.3.3

func (Cluster) String

func (c Cluster) String() string

type ClusterState

type ClusterState string

ClusterState implements the flag.Value interface.

func (*ClusterState) Set

func (cs *ClusterState) Set(s string) error

Set verifies the argument to be a valid member of ClusterStateFlagValues before setting the underlying flag value.

func (*ClusterState) String

func (cs *ClusterState) String() string

type ClusterStore

type ClusterStore interface {
	Add(m Member)
	Get() Cluster
	Remove(id uint64)
	IsRemoved(id uint64) bool
}

type EtcdServer

type EtcdServer struct {
	ClusterStore ClusterStore

	Ticker     <-chan time.Time
	SyncTicker <-chan time.Time
	// contains filtered or unexported fields
}

EtcdServer is the production implementation of the Server interface

func NewServer

func NewServer(cfg *ServerConfig) *EtcdServer

NewServer creates a new EtcdServer from the supplied configuration. The configuration is considered static for the lifetime of the EtcdServer.

func (*EtcdServer) AddMember

func (s *EtcdServer) AddMember(ctx context.Context, memb Member) error

func (*EtcdServer) Do

func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error)

Do interprets r and performs an operation on s.store according to r.Method and other fields. If r.Method is "POST", "PUT", "DELETE", or a "GET" with Quorum == true, r will be sent through consensus before performing its respective operation. Do will block until an action is performed or there is an error.

func (*EtcdServer) Index

func (s *EtcdServer) Index() uint64

Implement the RaftTimer interface

func (*EtcdServer) LeaderStats

func (s *EtcdServer) LeaderStats() []byte

func (*EtcdServer) Process

func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error

func (*EtcdServer) RemoveMember

func (s *EtcdServer) RemoveMember(ctx context.Context, id uint64) error

func (*EtcdServer) SelfStats

func (s *EtcdServer) SelfStats() []byte

func (*EtcdServer) Start

func (s *EtcdServer) Start()

Start prepares and starts server in a new goroutine. It is no longer safe to modify a server's fields after it has been sent to Start. It also starts a goroutine to publish its server information.

func (*EtcdServer) Stop

func (s *EtcdServer) Stop()

Stop stops the server gracefully, and shuts down the running goroutine. Stop should be called after a Start(s), otherwise it will block forever.

func (*EtcdServer) StoreStats

func (s *EtcdServer) StoreStats() []byte

func (*EtcdServer) Term

func (s *EtcdServer) Term() uint64

func (*EtcdServer) UpdateRecvApp

func (s *EtcdServer) UpdateRecvApp(from uint64, length int64)

type Member

type Member struct {
	ID uint64
	RaftAttributes
	Attributes
}

func NewMember

func NewMember(name string, peerURLs types.URLs, clusterName string, now *time.Time) *Member

newMember creates a Member without an ID and generates one based on the name, peer URLs. This is used for bootstrapping/adding new member.

type RaftAttributes

type RaftAttributes struct {
	// TODO(philips): ensure these are URLs
	PeerURLs []string
}

RaftAttributes represents the raft related attributes of an etcd member.

type RaftTimer

type RaftTimer interface {
	Index() uint64
	Term() uint64
}

type Response

type Response struct {
	Event   *store.Event
	Watcher store.Watcher
	// contains filtered or unexported fields
}

type Server

type Server interface {
	// Start performs any initialization of the Server necessary for it to
	// begin serving requests. It must be called before Do or Process.
	// Start must be non-blocking; any long-running server functionality
	// should be implemented in goroutines.
	Start()
	// Stop terminates the Server and performs any necessary finalization.
	// Do and Process cannot be called after Stop has been invoked.
	Stop()
	// Do takes a request and attempts to fulfil it, returning a Response.
	Do(ctx context.Context, r pb.Request) (Response, error)
	// Process takes a raft message and applies it to the server's raft state
	// machine, respecting any timeout of the given context.
	Process(ctx context.Context, m raftpb.Message) error
	// AddMember attempts to add a member into the cluster. It will return
	// ErrIDRemoved if member ID is removed from the cluster, or return
	// ErrIDExists if member ID exists in the cluster.
	AddMember(ctx context.Context, memb Member) error
	// RemoveMember attempts to remove a member from the cluster. It will
	// return ErrIDRemoved if member ID is removed from the cluster, or return
	// ErrIDNotFound if member ID is not in the cluster.
	RemoveMember(ctx context.Context, id uint64) error
}

type ServerConfig

type ServerConfig struct {
	Name         string
	DiscoveryURL string
	ClientURLs   types.URLs
	DataDir      string
	SnapCount    uint64
	Cluster      *Cluster
	ClusterState ClusterState
	Transport    *http.Transport
}

ServerConfig holds the configuration of etcd as taken from the command line or discovery.

func (*ServerConfig) ShouldDiscover

func (c *ServerConfig) ShouldDiscover() bool

func (*ServerConfig) SnapDir

func (c *ServerConfig) SnapDir() string

func (*ServerConfig) VerifyBootstrapConfig

func (c *ServerConfig) VerifyBootstrapConfig() error

VerifyBootstrapConfig sanity-checks the initial config and returns an error for things that should never happen.

func (*ServerConfig) WALDir

func (c *ServerConfig) WALDir() string

type Stats

type Stats interface {
	// SelfStats returns the struct representing statistics of this server
	SelfStats() []byte
	// LeaderStats returns the statistics of all followers in the cluster
	// if this server is leader. Otherwise, nil is returned.
	LeaderStats() []byte
	// StoreStats returns statistics of the store backing this EtcdServer
	StoreStats() []byte
	// UpdateRecvApp updates the underlying statistics in response to a receiving an Append request
	UpdateRecvApp(from uint64, length int64)
}

type Storage

type Storage interface {
	// Save function saves ents and state to the underlying stable storage.
	// Save MUST block until st and ents are on stable storage.
	Save(st raftpb.HardState, ents []raftpb.Entry)
	// SaveSnap function saves snapshot to the underlying stable storage.
	SaveSnap(snap raftpb.Snapshot)

	// TODO: WAL should be able to control cut itself. After implement self-controled cut,
	// remove it in this interface.
	// Cut cuts out a new wal file for saving new state and entries.
	Cut() error
}

Directories

Path Synopsis
## Add Member ### Request `curl http://${remote_client_url}/v2/admin/members/{$id} -XPUT -d 'PeerURLs=${peer_url_1}&PeerURLs=${peer_url_2}'` Parameter `remote_client_url` is serving client url of the cluster.
## Add Member ### Request `curl http://${remote_client_url}/v2/admin/members/{$id} -XPUT -d 'PeerURLs=${peer_url_1}&PeerURLs=${peer_url_2}'` Parameter `remote_client_url` is serving client url of the cluster.
Package etcdserverpb is a generated protocol buffer package.
Package etcdserverpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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