Documentation
¶
Index ¶
- Constants
- Variables
- func SpewableWrapper(config *spew.ConfigState, a ...interface{}) string
- type ChildCache
- func (l *ChildCache) Add(nodes ...*Znode) (err error)
- func (l *ChildCache) Cache() (nodesMap map[string]Znode)
- func (l *ChildCache) Clear() (err error)
- func (l *ChildCache) Contains(name string) bool
- func (l *ChildCache) Get(name string) (node *Znode)
- func (l *ChildCache) LoadCache() (err error)
- func (l *ChildCache) Remove(nodes ...*Znode) (err error)
- func (l *ChildCache) Size() int
- func (l *ChildCache) ToSlice() (nodes []Znode)
- type ChildWatch
- type Client
- type Curator
- func (c *Curator) AllPlugins() (plugins []Plugin)
- func (c *Curator) ClearPlugins()
- func (c *Curator) FindPlugin(f func(int, Plugin) bool) (index int, plugin Plugin)
- func (c *Curator) FireEvent(event Event)
- func (c *Curator) LoadPlugin(plugin Plugin)
- func (c *Curator) LogEntry(suffix string) *logrus.Entry
- func (c *Curator) Logger() *logrus.Logger
- func (c *Curator) Start() (err error)
- func (c *Curator) Stop() (err error)
- func (c *Curator) UnloadPlugin(plugin Plugin)
- type Event
- type EventType
- type NullLogger
- type Plugin
- type Settings
- type Spewable
- type Znode
Constants ¶
const MaxWaitToExistTime = 2 * time.Minute
Variables ¶
var ErrConnectionTimedOut = errors.New("connection to zookeeper timed out")
ErrConnectionTimedOut occurs when initial connection attempt to zk fails
var ErrInvalidPath = errors.New("provided path is invalid")
ErrInvalidPath occurs when the provided path in zk is malformed
var ErrNodeNotInCache = errors.New("node not in cache")
var ErrWatchStopped = errors.New("the watch was stopped")
ErrWatchStopped occurs when two calls to StopWatching are performed
Functions ¶
func SpewableWrapper ¶
func SpewableWrapper(config *spew.ConfigState, a ...interface{}) string
Types ¶
type ChildCache ¶
ChildCache provides a cached list, whose nodes are the children of a single path within zookeeper. In other words, all the items in the cache would share the same parent.
For example, supposing a zookeeper structure as follows:
/services/birdhouse/work /services/birdhouse/work/123 /services/birdhouse/work/124 /services/birdhouse/work/125 /services/birdhouse/work/126
ChildCache provides operations on /services/birdhouse/work path to manipulate its children: {123,124,125,126}.
The underlying list is stored as a map. Just like a filesystem structure in unix, the children of a znode have unique names.
Some notes:
* Does not observe state changes in zk * Thread safe * Does not require or use channels
func NewChildCache ¶
func NewChildCache(client *Client, path string) *ChildCache
func (*ChildCache) Add ¶
func (l *ChildCache) Add(nodes ...*Znode) (err error)
Add new nodes to underlying store, only if the node does not already exist in cache. If the underlying node exists in Zk, its loaded into the cache (and not considered an error). It's not considered an error to add a node that is already in the cache.
func (*ChildCache) Cache ¶
func (l *ChildCache) Cache() (nodesMap map[string]Znode)
Shallow copy of cache that can be used for RO operations.
func (*ChildCache) Clear ¶
func (l *ChildCache) Clear() (err error)
Clear all nodes from underlying store, but only if the node exists in the cache.
func (*ChildCache) Contains ¶
func (l *ChildCache) Contains(name string) bool
Determine if a node exists by node name.
func (*ChildCache) Get ¶
func (l *ChildCache) Get(name string) (node *Znode)
Retrieves a node from the cache if it exists, nil otherwise.
func (*ChildCache) LoadCache ¶
func (l *ChildCache) LoadCache() (err error)
Wipes local cache and reloads it directly from zk.
func (*ChildCache) Remove ¶
func (l *ChildCache) Remove(nodes ...*Znode) (err error)
Delete nodes from underlying store, only if the node already exists in the cache. If the node does not exist in the cache, an error is returned.
func (*ChildCache) ToSlice ¶
func (l *ChildCache) ToSlice() (nodes []Znode)
List of children nodes for the path provided in the constructor.
type ChildWatch ¶
type ChildWatch struct { Path string MaxRetryElapsedTime time.Duration RetrieveData bool // contains filtered or unexported fields }
ChildWatch observes the children of a path in zookeeper for changes and maintains a cached list of those nodes. Only changes in the children are tracked, not changes in the data of the children. Some advantages over the children watch in go-zookeeper include:
* tracks removals and additions for you in an easy to use map * automatically restarts the watch when child watch events occur * xmits events with nodes observed to have been added and/or removed * returns data as proper Znode structures instead of a string * stops a watch somewhat more cleanly than go-zookeeper * can automatically retrieve child data (use carefully as a list of size n would introduce n calls to retrieve data from zookeeper)
The children are stored as a map, with the Znode name as the key, and the Znode as the value.
A ChildWatch is not re-usable and can only be started and stopped once. If you need a to re-use a ChildWatch, create a new one with the same path. Due to limitations in go-zookeeper a created ChildWatch will not free its goroutine until a zookeeper connection or child watch event occurs.
func NewChildWatch ¶
func NewChildWatch(client *Client, path string) *ChildWatch
NewChildWatch creates a watch on the provided path.
func (*ChildWatch) GetChildren ¶
func (w *ChildWatch) GetChildren() map[string]Znode
GetChildren returns a copy of all child Znodes of Path. Note that after you get the list it could immediately change. Using the channel returned by WatchChildren is usually what you want.
func (*ChildWatch) StopWatching ¶
func (w *ChildWatch) StopWatching() (err error)
StopWatching is a bit tricky because go-zookeeper doesn't cleanup child watches nicely. In fact, its for this reason that a ChildWatch can only be started and stopped once. When a ChildWatch is stopped the goroutine can't exit until a watch event from zookeeper is received (again a limitation imposed by go-zookeeper)
func (*ChildWatch) WatchChildren ¶
func (w *ChildWatch) WatchChildren() (chan Event, error)
WatchChildren starts watching the specified path and loads the intial set of items.
type Client ¶
Client connects to and interacts with zk.
func (*Client) Connect ¶
func (c *Client) Connect(settings *Settings, options ...zk.ConnOption) (evnt <-chan zk.Event, err error)
Connect creates a connection to zookeeper for the client
func (*Client) CreatePath ¶
CreatePath will create the full path in zookeeper (emulates 'mkdir -p'). Each node will be assigned the same data and acl permissions. Only non-ephemeral nodes can have children.
The path parameter must begin with '/'
type Curator ¶
func (*Curator) AllPlugins ¶
func (*Curator) ClearPlugins ¶
func (c *Curator) ClearPlugins()
func (*Curator) FindPlugin ¶
func (*Curator) LoadPlugin ¶
func (*Curator) UnloadPlugin ¶
type Event ¶
type Event struct { Type EventType Node *Znode Source *zk.Event Error error Data map[string]interface{} }
Event represents an event that occurs within the components in curator
func (Event) IsConnectedEvent ¶
IsConnectedEvent is a shortcut for determing if the event is a ConnectionEvent and represents an underlying zk.StateHasSession
func (Event) IsDisconnectedEvent ¶
IsDisConnectedEvent is a shortcut for determing if the event is a ConnectionEvent and represents anything except an underlying zk.StateHasSession (which means we are not reliably connected and ready to process typical zk API requests)
func (Event) IsValidSessionEvent ¶
IsValidSessionEvent determines if the event type is a ConnectionEvent and there is a valid and associated zk event of type zk.EventSession.
type EventType ¶
type EventType uint64
EventType describes the type of event that occured
const ( AnyEvent EventType = 1 << iota ConnectionEvent ChildrenWatchLoadedEvent ChildrenWatchChangedEvent ChildrenWatchStoppedEvent LeaderEventElected LeaderEventCandidate LeaderEventResigned MemberEventRegistered MemberEventUnregistered DiscoveryEventActive DiscoveryEventInactive WorkCollectorEventChangeset WorkCollectorEventLoaded WorkLeaderChangeset WorkLeaderActive WorkLeaderInactive )
Limited to 64 event types
type NullLogger ¶
type NullLogger struct{}
NullLogger can be used to silence output from the client connection. Only recommended for tests.
func (NullLogger) Printf ¶
func (NullLogger) Printf(format string, a ...interface{})
Printf is the only method that is part of the connection logger interface