Documentation ¶
Overview ¶
Package etcdserver defines how etcd servers interact and store their states.
Index ¶
- Constants
- Variables
- func GetClusterFromRemotePeers(urls []string, rt http.RoundTripper) (*cluster, error)
- func MemberAttributesStorePath(id types.ID) string
- func MustDetectDowngrade(cv *semver.Version)
- func ValidateClusterAndAssignIDs(local *cluster, existing *cluster) error
- type Attributes
- type Cluster
- type DiscoveryError
- type EtcdServer
- func (s *EtcdServer) AddMember(ctx context.Context, memb Member) error
- func (s *EtcdServer) Cluster() Cluster
- func (s *EtcdServer) ClusterVersion() *semver.Version
- func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error)
- func (s *EtcdServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error)
- func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error)
- func (s *EtcdServer) ID() types.ID
- func (s *EtcdServer) Index() uint64
- func (s *EtcdServer) IsIDRemoved(id uint64) bool
- func (s *EtcdServer) IsPprofEnabled() bool
- func (s *EtcdServer) Lead() uint64
- func (s *EtcdServer) Leader() types.ID
- func (s *EtcdServer) LeaderStats() []byte
- func (s *EtcdServer) LeaseCreate(ctx context.Context, r *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error)
- func (s *EtcdServer) LeaseRenew(id lease.LeaseID) (int64, error)
- func (s *EtcdServer) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error)
- func (s *EtcdServer) Lessor() lease.Lessor
- func (s *EtcdServer) PauseSending()
- func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error
- func (s *EtcdServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error)
- func (s *EtcdServer) RaftHandler() http.Handler
- func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error)
- func (s *EtcdServer) RemoveMember(ctx context.Context, id uint64) error
- func (s *EtcdServer) ReportSnapshot(id uint64, status raft.SnapshotStatus)
- func (s *EtcdServer) ReportUnreachable(id uint64)
- func (s *EtcdServer) ResumeSending()
- func (s *EtcdServer) SelfStats() []byte
- func (s *EtcdServer) Start()
- func (s *EtcdServer) Stop()
- func (s *EtcdServer) StopNotify() <-chan struct{}
- func (s *EtcdServer) StoreStats() []byte
- func (s *EtcdServer) Term() uint64
- func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error)
- func (s *EtcdServer) UpdateMember(ctx context.Context, memb Member) error
- func (s *EtcdServer) Watchable() dstorage.Watchable
- type Lessor
- type Member
- type MembersByID
- type MembersByPeerURLs
- type RaftAttributes
- type RaftKV
- type RaftTimer
- type Response
- type Server
- type ServerConfig
- func (c *ServerConfig) MemberDir() string
- func (c *ServerConfig) Print()
- func (c *ServerConfig) PrintWithInitial()
- func (c *ServerConfig) ReqTimeout() time.Duration
- func (c *ServerConfig) ShouldDiscover() bool
- func (c *ServerConfig) SnapDir() string
- func (c *ServerConfig) VerifyBootstrap() error
- func (c *ServerConfig) VerifyJoinExisting() error
- func (c *ServerConfig) WALDir() string
- type Storage
Constants ¶
const ( DefaultSnapCount = 10000 StoreClusterPrefix = "/0" StoreKeysPrefix = "/1" )
Variables ¶
var ( ErrUnknownMethod = errors.New("etcdserver: unknown method") ErrStopped = errors.New("etcdserver: server stopped") ErrIDRemoved = errors.New("etcdserver: ID removed") ErrIDExists = errors.New("etcdserver: ID exists") ErrIDNotFound = errors.New("etcdserver: ID not found") ErrPeerURLexists = errors.New("etcdserver: peerURL exists") ErrCanceled = errors.New("etcdserver: request cancelled") ErrTimeout = errors.New("etcdserver: request timed out") ErrTimeoutDueToLeaderFail = errors.New("etcdserver: request timed out, possibly due to previous leader failure") ErrTimeoutDueToConnectionLost = errors.New("etcdserver: request timed out, possibly due to connection lost") ErrNotEnoughStartedMembers = errors.New("etcdserver: re-configuration failed due to not enough started members") ErrNoLeader = errors.New("etcdserver: no leader") )
Functions ¶
func GetClusterFromRemotePeers ¶
func GetClusterFromRemotePeers(urls []string, rt http.RoundTripper) (*cluster, error)
GetClusterFromRemotePeers takes a set of URLs representing etcd peers, and attempts to construct a Cluster by accessing the members endpoint on one of these URLs. The first URL to provide a response is used. If no URLs provide a response, or a Cluster cannot be successfully created from a received response, an error is returned. Each request has a 10-second timeout. Because the upper limit of TTL is 5s, 10 second is enough for building connection and finishing request.
func MustDetectDowngrade ¶
func ValidateClusterAndAssignIDs ¶
func ValidateClusterAndAssignIDs(local *cluster, existing *cluster) error
ValidateClusterAndAssignIDs validates the local cluster by matching the PeerURLs with the existing cluster. If the validation succeeds, it assigns the IDs from the existing cluster to the local cluster. If the validation fails, an error will be returned.
Types ¶
type Attributes ¶
type Attributes struct { Name string `json:"name,omitempty"` ClientURLs []string `json:"clientURLs,omitempty"` }
Attributes represents all the non-raft related attributes of an etcd member.
type Cluster ¶
type Cluster interface { // ID returns the cluster ID ID() types.ID // ClientURLs returns an aggregate set of all URLs on which this // cluster is listening for client requests ClientURLs() []string // Members returns a slice of members sorted by their ID Members() []*Member // Member retrieves a particular member based on ID, or nil if the // member does not exist in the cluster Member(id types.ID) *Member // IsIDRemoved checks whether the given ID has been removed from this // cluster at some point in the past IsIDRemoved(id types.ID) bool // ClusterVersion is the cluster-wide minimum major.minor version. Version() *semver.Version }
type DiscoveryError ¶
func (DiscoveryError) Error ¶
func (e DiscoveryError) Error() string
type EtcdServer ¶
EtcdServer is the production implementation of the Server interface
func NewServer ¶
func NewServer(cfg *ServerConfig) (*EtcdServer, error)
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) Cluster ¶
func (s *EtcdServer) Cluster() Cluster
func (*EtcdServer) ClusterVersion ¶
func (s *EtcdServer) ClusterVersion() *semver.Version
func (*EtcdServer) Compact ¶
func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error)
func (*EtcdServer) DeleteRange ¶
func (s *EtcdServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error)
func (*EtcdServer) Do ¶
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) ID ¶
func (s *EtcdServer) ID() types.ID
func (*EtcdServer) IsIDRemoved ¶
func (s *EtcdServer) IsIDRemoved(id uint64) bool
func (*EtcdServer) IsPprofEnabled ¶
func (s *EtcdServer) IsPprofEnabled() bool
func (*EtcdServer) Lead ¶
func (s *EtcdServer) Lead() uint64
Only for testing purpose TODO: add Raft server interface to expose raft related info: Index, Term, Lead, Committed, Applied, LastIndex, etc.
func (*EtcdServer) Leader ¶
func (s *EtcdServer) Leader() types.ID
func (*EtcdServer) LeaderStats ¶
func (s *EtcdServer) LeaderStats() []byte
func (*EtcdServer) LeaseCreate ¶
func (s *EtcdServer) LeaseCreate(ctx context.Context, r *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error)
func (*EtcdServer) LeaseRenew ¶
func (s *EtcdServer) LeaseRenew(id lease.LeaseID) (int64, error)
func (*EtcdServer) LeaseRevoke ¶
func (s *EtcdServer) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error)
func (*EtcdServer) Lessor ¶
func (s *EtcdServer) Lessor() lease.Lessor
func (*EtcdServer) PauseSending ¶
func (s *EtcdServer) PauseSending()
func (*EtcdServer) Put ¶
func (s *EtcdServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error)
func (*EtcdServer) RaftHandler ¶
func (s *EtcdServer) RaftHandler() http.Handler
func (*EtcdServer) Range ¶
func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error)
func (*EtcdServer) RemoveMember ¶
func (s *EtcdServer) RemoveMember(ctx context.Context, id uint64) error
func (*EtcdServer) ReportSnapshot ¶
func (s *EtcdServer) ReportSnapshot(id uint64, status raft.SnapshotStatus)
ReportSnapshot reports snapshot sent status to the raft state machine, and clears the used snapshot from the snapshot store.
func (*EtcdServer) ReportUnreachable ¶
func (s *EtcdServer) ReportUnreachable(id uint64)
func (*EtcdServer) ResumeSending ¶
func (s *EtcdServer) ResumeSending()
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) StopNotify ¶
func (s *EtcdServer) StopNotify() <-chan struct{}
StopNotify returns a channel that receives a empty struct when the server is stopped.
func (*EtcdServer) StoreStats ¶
func (s *EtcdServer) StoreStats() []byte
func (*EtcdServer) Term ¶
func (s *EtcdServer) Term() uint64
func (*EtcdServer) Txn ¶
func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error)
func (*EtcdServer) UpdateMember ¶
func (s *EtcdServer) UpdateMember(ctx context.Context, memb Member) error
func (*EtcdServer) Watchable ¶
func (s *EtcdServer) Watchable() dstorage.Watchable
Watchable returns a watchable interface attached to the etcdserver.
type Lessor ¶
type Lessor interface { // LeaseCreate sends LeaseCreate request to raft and apply it after committed. LeaseCreate(ctx context.Context, r *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error) // LeaseRevoke sends LeaseRevoke request to raft and apply it after committed. LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) // LeaseRenew renews the lease with given ID. The renewed TTL is returned. Or an error // is returned. LeaseRenew(id lease.LeaseID) (int64, error) }
type Member ¶
type Member struct { ID types.ID `json:"id"` RaftAttributes Attributes }
func NewMember ¶
NewMember creates a Member without an ID and generates one based on the name, peer URLs. This is used for bootstrapping/adding new member.
func (*Member) PickPeerURL ¶
PickPeerURL chooses a random address from a given Member's PeerURLs. It will panic if there is no PeerURLs available in Member.
type MembersByID ¶
type MembersByID []*Member
implement sort by ID interface
func (MembersByID) Len ¶
func (ms MembersByID) Len() int
func (MembersByID) Less ¶
func (ms MembersByID) Less(i, j int) bool
func (MembersByID) Swap ¶
func (ms MembersByID) Swap(i, j int)
type MembersByPeerURLs ¶
type MembersByPeerURLs []*Member
implement sort by peer urls interface
func (MembersByPeerURLs) Len ¶
func (ms MembersByPeerURLs) Len() int
func (MembersByPeerURLs) Less ¶
func (ms MembersByPeerURLs) Less(i, j int) bool
func (MembersByPeerURLs) Swap ¶
func (ms MembersByPeerURLs) Swap(i, j int)
type RaftAttributes ¶
type RaftAttributes struct { // TODO(philips): ensure these are URLs PeerURLs []string `json:"peerURLs"` }
RaftAttributes represents the raft related attributes of an etcd member.
type RaftKV ¶
type RaftKV interface { Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) }
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() // ID returns the ID of the Server. ID() types.ID // Leader returns the ID of the leader Server. Leader() types.ID // Do takes a request and attempts to fulfill 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 // UpdateMember attempts to update an existing member in the cluster. It will // return ErrIDNotFound if the member ID does not exist. UpdateMember(ctx context.Context, updateMemb Member) error // ClusterVersion is the cluster-wide minimum major.minor version. // Cluster version is set to the min version that a etcd member is // compatible with when first bootstrap. // // ClusterVersion is nil until the cluster is bootstrapped (has a quorum). // // During a rolling upgrades, the ClusterVersion will be updated // automatically after a sync. (5 second by default) // // The API/raft component can utilize ClusterVersion to determine if // it can accept a client request or a raft RPC. // NOTE: ClusterVersion might be nil when etcd 2.1 works with etcd 2.0 and // the leader is etcd 2.0. etcd 2.0 leader will not update clusterVersion since // this feature is introduced post 2.0. ClusterVersion() *semver.Version }
type ServerConfig ¶
type ServerConfig struct { Name string DiscoveryURL string DiscoveryProxy string ClientURLs types.URLs PeerURLs types.URLs DataDir string // DedicatedWALDir config will make the etcd to write the WAL to the WALDir // rather than the dataDir/member/wal. DedicatedWALDir string SnapCount uint64 MaxSnapFiles uint MaxWALFiles uint InitialPeerURLsMap types.URLsMap InitialClusterToken string NewCluster bool ForceNewCluster bool PeerTLSInfo transport.TLSInfo TickMs uint ElectionTicks int V3demo bool StrictReconfigCheck bool EnablePprof bool }
ServerConfig holds the configuration of etcd as taken from the command line or discovery.
func (*ServerConfig) MemberDir ¶
func (c *ServerConfig) MemberDir() string
func (*ServerConfig) Print ¶
func (c *ServerConfig) Print()
func (*ServerConfig) PrintWithInitial ¶
func (c *ServerConfig) PrintWithInitial()
func (*ServerConfig) ReqTimeout ¶
func (c *ServerConfig) ReqTimeout() time.Duration
ReqTimeout returns timeout for request to finish.
func (*ServerConfig) ShouldDiscover ¶
func (c *ServerConfig) ShouldDiscover() bool
func (*ServerConfig) SnapDir ¶
func (c *ServerConfig) SnapDir() string
func (*ServerConfig) VerifyBootstrap ¶
func (c *ServerConfig) VerifyBootstrap() error
VerifyBootstrapConfig sanity-checks the initial config for bootstrap case and returns an error for things that should never happen.
func (*ServerConfig) VerifyJoinExisting ¶
func (c *ServerConfig) VerifyJoinExisting() error
VerifyJoinExisting sanity-checks the initial config for join existing cluster case and returns an error for things that should never happen.
func (*ServerConfig) WALDir ¶
func (c *ServerConfig) WALDir() string
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) error // SaveSnap function saves snapshot to the underlying stable storage. SaveSnap(snap raftpb.Snapshot) error // DBFilePath returns the file path of database snapshot saved with given // id. DBFilePath(id uint64) (string, error) // Close closes the Storage and performs finalization. Close() error }
func NewStorage ¶
func NewStorage(w *wal.WAL, s *snap.Snapshotter) Storage
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
api
|
|
v3rpc
Package v3rpc implements etcd v3 RPC system based on gRPC.
|
Package v3rpc implements etcd v3 RPC system based on gRPC. |
Package auth implements etcd authentication.
|
Package auth implements etcd authentication. |
Package etcdhttp provides etcd client and server implementations.
|
Package etcdhttp provides etcd client and server implementations. |
httptypes
Package httptypes defines how etcd's HTTP API entities are serialized to and deserialized from JSON.
|
Package httptypes defines how etcd's HTTP API entities are serialized to and deserialized from JSON. |
Package etcdserverpb is a generated protocol buffer package.
|
Package etcdserverpb is a generated protocol buffer package. |
Package stats defines a standard interface for etcd cluster statistics.
|
Package stats defines a standard interface for etcd cluster statistics. |