serversets

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SOH control character
	SOH = "\x01"
)

Variables

View Source
var (
	// BaseDirectory is the Zookeeper namespace that all nodes made by this package will live.
	// This path must begin with '/'
	BaseDirectory = "/aurora"

	// MemberPrefix is prefix for the Zookeeper sequential ephemeral nodes.
	// member_ is used by Finagle server sets.
	MemberPrefix = "member_"
)
View Source
var BaseZnodePath = func(role, environment, service string) string {
	return BaseDirectory + "/" + role + "/" + environment + "/" + service
}

BaseZnodePath allows for a custom Zookeeper directory structure. This function should return the path where you want the service's members to live. Default is `BaseDirectory + "/" + environment + "/" + service` where the default base directory is `/aurora`

View Source
var DefaultZKTimeout = 5 * time.Second

DefaultZKTimeout is the zookeeper timeout used if it is not overwritten.

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	*ServerSet
	PingRate   time.Duration // default/initial is 1 second
	CloseEvent chan struct{}
	// contains filtered or unexported fields
}

An Endpoint is a service (host and port) registered on Zookeeper to be discovered by clients/watchers.

func (*Endpoint) Close

func (ep *Endpoint) Close()

Close blocks until the client connection to Zookeeper is closed. If already called, will simply return, even if in the process of closing.

type FinagleFmt

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

FinagleFmt provides Finagle style path/data formats.

func NewFinagleFmt

func NewFinagleFmt(role, environment, service string) FinagleFmt

NewFinagleFmt creates a new FinagleFmt.

func (FinagleFmt) Create

func (FinagleFmt) Create(host string, port int) ZKRecord

Create creates an alive endpoint record from host and port.

func (FinagleFmt) Path

func (f FinagleFmt) Path() string

Path returns the znode path where all service members reside.

func (FinagleFmt) Prefix

func (f FinagleFmt) Prefix() string

Prefix returns the service member name prefix.

func (FinagleFmt) Unmarshal

func (FinagleFmt) Unmarshal(data []byte) (ZKRecord, error)

Unmarshal decodes zk record from JSON format.

type FinagleRecord

type FinagleRecord struct {
	ServiceEndpoint     endpoint            `json:"serviceEndpoint"`
	AdditionalEndpoints map[string]endpoint `json:"additionalEndpoints"`
	Shard               int64               `json:"shard"`
	Status              string              `json:"status"`
}

FinagleRecord is structure of the data in each member znode. It mimics finagle serverset structure.

func (*FinagleRecord) Endpoint

func (f *FinagleRecord) Endpoint() string

Endpoint returns host:port.

func (*FinagleRecord) IsAlive

func (f *FinagleRecord) IsAlive() bool

IsAlive returns true if this endpoint is to be discovered by user.

func (*FinagleRecord) Marshal

func (f *FinagleRecord) Marshal() ([]byte, error)

Marshal encodes zk record in JSON format.

type ServerSet

type ServerSet struct {
	ZKTimeout time.Duration
	ZKFmt     ZKFmt
	// contains filtered or unexported fields
}

A ServerSet represents a service with a set of servers that may change over time. The master lists of servers is kept as ephemeral nodes in Zookeeper.

func New

func New(role string, environment string, service string, zookeepers []string) *ServerSet

New creates a new ServerSet object that can then be watched or have an endpoint added to. The service name must not contain any slashes. Will panic if it does.

func NewP

func NewP(zookeepers []string, zkfmt ZKFmt) *ServerSet

NewP creates a new ServerSet with customized path/data formatter.

func (*ServerSet) RegisterEndpoint

func (ss *ServerSet) RegisterEndpoint(host string, port int, ping func() error) (*Endpoint, error)

RegisterEndpoint registers a host and port as alive. It creates the appropriate Zookeeper nodes and watchers will be notified this server/endpoint is available.

func (*ServerSet) Watch

func (ss *ServerSet) Watch() (*Watch, error)

Watch starts a zookeeper connection and starts watching changes in the service members znode.

func (*ServerSet) ZookeeperServers

func (ss *ServerSet) ZookeeperServers() []string

ZookeeperServers returns the Zookeeper servers this set is using. Useful to check if everything is configured correctly.

type Watch

type Watch struct {
	LastEvent  time.Time
	EventCount int
	// contains filtered or unexported fields
}

A Watch keeps tabs on a server set in Zookeeper and notifies via the Event() channel when the list of servers changes. The list of servers is updated automatically and will be up to date when the Event is sent.

func (*Watch) Close

func (w *Watch) Close()

Close blocks until the underlying Zookeeper connection is closed.

func (*Watch) Endpoints

func (w *Watch) Endpoints() []string

Endpoints returns a slice of the current list of servers/endpoints associated with this watch.

func (*Watch) Event

func (w *Watch) Event() <-chan struct{}

Event returns the event channel. This channel will get an object whenever something changes with the list of endpoints.

func (*Watch) IsClosed

func (w *Watch) IsClosed() bool

IsClosed returns if this watch has been closed. This is a way for libraries wrapping this package to know if their underlying watch is closed and should stop looking for events.

type ZKFmt

type ZKFmt interface {
	// Path returns the zokeeper full path to service members.
	Path() string
	// Prefix returns the znode name prefix for service members.
	Prefix() string
	// CreateRecord creates a new endpoint record from host and port.
	Create(host string, port int) ZKRecord
	// Unmarshal decodes encoded endpoint data a ZKrecord.
	Unmarshal([]byte) (ZKRecord, error)
}

ZKFmt defines the APIs for endpoint's zookeeper path and data formats.

type ZKRecord

type ZKRecord interface {
	// Marshal encodes data to be stored in zookeeper.
	Marshal() ([]byte, error)
	// Endpoint returns the endpoint as host:port string
	Endpoint() string
	// IsAlive returns true if znode has liveness information stored.
	IsAlive() bool
}

ZKRecord defines the APIs an endpoint record in zookeeper should provide.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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