Documentation ¶
Index ¶
- Constants
- Variables
- func IsNotFound(err error) bool
- func IsServiceExists(err error) bool
- func ValidServiceName(service string) error
- type DNSServer
- type DNSStore
- type Handler
- type NotFoundError
- type ProxyStore
- type ServiceExistsError
- type Store
- func (s *Store) AddInstance(service string, inst *discoverd.Instance) error
- func (s *Store) AddPeer(peer string) error
- func (s *Store) AddService(service string, config *discoverd.ServiceConfig) error
- func (s *Store) Apply(l *raft.Log) interface{}
- func (s *Store) Close() (lastIdx uint64, err error)
- func (s *Store) Config(service string) *discoverd.ServiceConfig
- func (s *Store) EnforceExpiry() error
- func (s *Store) GetPeers() ([]string, error)
- func (s *Store) Instances(service string) ([]*discoverd.Instance, error)
- func (s *Store) IsLeader() bool
- func (s *Store) LastIndex() uint64
- func (s *Store) Leader() string
- func (s *Store) LeaderCh() <-chan bool
- func (s *Store) Open() error
- func (s *Store) Path() string
- func (s *Store) RemoveInstance(service, id string) error
- func (s *Store) RemovePeer(peer string) error
- func (s *Store) RemoveService(service string) error
- func (s *Store) Restore(r io.ReadCloser) error
- func (s *Store) ServiceLeader(service string) (*discoverd.Instance, error)
- func (s *Store) ServiceMeta(service string) *discoverd.ServiceMeta
- func (s *Store) ServiceNames() []string
- func (s *Store) SetPeers(peers []string) error
- func (s *Store) SetServiceLeader(service, id string) error
- func (s *Store) SetServiceMeta(service string, meta *discoverd.ServiceMeta) error
- func (s *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) Subscribe(service string, sendCurrent bool, kinds discoverd.EventKind, ...) stream.Stream
Constants ¶
const ( // DefaultInstanceTTL is the length of time after a heartbeat from an instance before it expires. DefaultInstanceTTL = 10 * time.Second // DefaultExpiryCheckInterval is the default interval between checks for expired instances. DefaultExpiryCheckInterval = 1 * time.Second )
const StoreHdr = byte('\xff')
StoreHdr is the header byte used by the multiplexer.
const StreamBufferSize = 64 // TODO: Figure out how big this buffer should be.
StreamBufferSize is the size of the channel buffer used for event subscription.
Variables ¶
var ( ErrUnsetService = errors.New("discoverd: service name must not be empty") ErrInvalidService = errors.New("discoverd: service must be lowercase alphanumeric plus dash") ErrSendBlocked = errors.New("discoverd: channel send failed due to blocked receiver") ErrListenerRequired = errors.New("discoverd: listener required") ErrAdvertiseRequired = errors.New("discoverd: advertised address required") // ErrNotLeader is returned when performing an operation on the store when // it is not the current cluster leader. ErrNotLeader = errors.New("discoverd: not leader") // ErrNoKnownLeader is returned when there is not a current know cluster leader. ErrNoKnownLeader = errors.New("discoverd: no known leader") // ErrLeaderWait is returned when trying to expire instances when the store // hasn't been leader for long enough. ErrLeaderWait = errors.New("discoverd: new leader, waiting for 2x TTL") ErrShutdown = errors.New("discoverd: shutting down") )
var DefaultServiceConfig = &discoverd.ServiceConfig{
LeaderType: discoverd.LeaderTypeOldest,
}
DefaultServiceConfig is the default configuration for a service when one is not specified.
Functions ¶
func IsNotFound ¶
func IsServiceExists ¶
func ValidServiceName ¶
ValidServiceName returns nil if service is valid. Otherwise returns an error.
Types ¶
type DNSServer ¶
type DNSServer struct { UDPAddr string TCPAddr string Domain string Recursors []string // contains filtered or unexported fields }
func (*DNSServer) ListenAndServe ¶
type Handler ¶
type Handler struct { http.Handler Shutdown atomic.Value // bool Proxy atomic.Value // bool Main interface { Close() (dt.TargetLogIndex, error) Promote() error Demote() error } Store interface { Leader() string IsLeader() bool AddService(service string, config *discoverd.ServiceConfig) error RemoveService(service string) error SetServiceMeta(service string, meta *discoverd.ServiceMeta) error ServiceMeta(service string) *discoverd.ServiceMeta AddInstance(service string, inst *discoverd.Instance) error RemoveInstance(service, id string) error Instances(service string) ([]*discoverd.Instance, error) Config(service string) *discoverd.ServiceConfig SetServiceLeader(service, id string) error ServiceLeader(service string) (*discoverd.Instance, error) Subscribe(service string, sendCurrent bool, kinds discoverd.EventKind, ch chan *discoverd.Event) stream.Stream AddPeer(peer string) error RemovePeer(peer string) error GetPeers() ([]string, error) LastIndex() uint64 } Peers []string }
Handler represents an HTTP handler for the Store.
func NewHandler ¶
NewHandler returns a new instance of Handler.
type NotFoundError ¶
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type ProxyStore ¶
type ProxyStore struct {
Peers []string
}
ProxyStore implements some of the Store methods as proxy calls. Only the subset of methods required for DNSServer.Store are implemented.
func (*ProxyStore) Instances ¶
func (s *ProxyStore) Instances(service string) ([]*discoverd.Instance, error)
Instances returns a list of instances for a service.
func (*ProxyStore) ServiceLeader ¶
func (s *ProxyStore) ServiceLeader(service string) (*discoverd.Instance, error)
ServiceLeader returns the leader for a service.
type ServiceExistsError ¶
type ServiceExistsError string
func (ServiceExistsError) Error ¶
func (e ServiceExistsError) Error() string
type Store ¶
type Store struct { // The underlying network listener. Listener net.Listener // The address the raft server uses to represent itself in the peer list. Advertise net.Addr // Raft settings. HeartbeatTimeout time.Duration ElectionTimeout time.Duration LeaderLeaseTimeout time.Duration CommitTimeout time.Duration EnableSingleNode bool // The writer where logs are written to. LogOutput io.Writer // The duration without a heartbeat before an instance is expired. InstanceTTL time.Duration // The interval between checks for instance expiry on the leader. ExpiryCheckInterval time.Duration // Returns the current time. // This defaults to time.Now and can be changed for mocking. Now func() time.Time // contains filtered or unexported fields }
Store represents a storage backend using the raft protocol.
func (*Store) AddInstance ¶
func (*Store) AddService ¶
AddService creates a service with a configuration. Returns an error if the service already exists.
func (*Store) EnforceExpiry ¶
EnforceExpiry checks all instances for expiration and issues an expiration command, if necessary. This function returns raft.ErrNotLeader if this store is not the current leader.
func (*Store) Leader ¶
Leader returns the host of the current leader. Returns empty string if there is no leader. Panic if called before store is opened.
func (*Store) LeaderCh ¶
LeaderCh returns a channel that signals leadership change. Panic if called before store is opened.
func (*Store) RemoveInstance ¶
func (*Store) RemovePeer ¶
RemovePeer removes a peer from the raft cluster. Panic if store is not open yet.
func (*Store) RemoveService ¶
RemoveService deletes the service from the store.
func (*Store) ServiceLeader ¶
func (*Store) ServiceMeta ¶
ServiceMeta returns the meta data for a service.
func (*Store) ServiceNames ¶
ServiceNames returns a sorted list of existing service names.
func (*Store) SetPeers ¶
SetPeers sets a list of peers in the raft cluster. Panic if store is not open yet.
func (*Store) SetServiceLeader ¶
SetServiceLeader manually sets the leader for a service.