Documentation ¶
Overview ¶
Package zkutils provides ZooKeeper utility methods.
The functionality is implemented atop github.com/samuel/go-zookeeper/zk.
Index ¶
- Variables
- func AwaitExists(conn *zk.Conn, path string) <-chan error
- func CreateRecursively(conn *zk.Conn, path string, acl []zk.ACL) (err error)
- func CreateTestCluster(t *testing.T, size int) (testCluster *zk.TestCluster, serverAddrs []string)
- func DeleteSafely(conn *zk.Conn, path string)
- func IsErrorRecoverable(err error) bool
- func SortSequenceNodes(nodes []SequenceNode)
- func StartTestCluster(size int, stdout, stderr io.Writer) (*zk.TestCluster, error)
- type ConnMan
- type EventMultiplexer
- type SequenceNode
Constants ¶
This section is empty.
Variables ¶
var ( // Node is not a match. ErrNodeNotMatch = errors.New("node is not a match") // Timeout error. ErrTimeout = errors.New("timeout") )
Functions ¶
func AwaitExists ¶
Await the existence of a node.
Emits a nil object, or an error, on the channel, when the node at the given path exists or an error occurs.
func CreateRecursively ¶
Recursively create nodes with no data if they do not exist.
Does not return any error if the node path already exist.
func CreateTestCluster ¶
Create a test cluster of a given size.
func DeleteSafely ¶
Delete a node safely.
Will attempt to delete a node continuously until either an unrecoverable error is encountered, or the node is gone.
func IsErrorRecoverable ¶
Test if a ZooKeeper error is recoverable.
Takes a conservative approach, and only considers authentication failures etc. as unrecoverable.
func SortSequenceNodes ¶
func SortSequenceNodes(nodes []SequenceNode)
Sort a list of sequence nodes.
Sorts the sequence nodes in a semi-overflow safe manner. Sequence numbers will follow the following order:
0 .. 2147483647 -2147483648 .. -1 0 .. 2147483647 ..
Sorting makes the assumption, that sequence numbers will never be too far apart in the natural, overflowing sequence. Thus, the sorting is performed with the following ordering:
- Ordered ascendingly if the set of sequence numbers are in the range [0 ; 2147483647]
- Ordered ascendingly with negative sequence numbers ordered after the positive sequence numbers if the set of sequence numbers are in the range [0 ; 2147483647] and [-2147483648 ; -1073741824].
- Ordered ascendingly if the set of sequence numbers are in the range [-2147483648 ; 1073741824].
func StartTestCluster ¶
Types ¶
type ConnMan ¶
type ConnMan struct { Conn *zk.Conn SessionTimeout time.Duration RecvTimeout time.Duration PingInterval time.Duration // contains filtered or unexported fields }
ZooKeeper connection manager.
ZooKeeper connection wrapper that provides multiplexed access to events as well as information about session timeout.
func CreateTestClusterAndConnMan ¶
func CreateTestClusterAndConnMan(t *testing.T, size int) (testCluster *zk.TestCluster, connMan *ConnMan)
Create a test cluster of a given size and a connection to the cluster.
func (*ConnMan) WatchSessionLoss ¶
Watch for session loss.
Session loss is indicated if a session expires or connection to a cluster is lost for more than the time it is safe to assume that a session is still well and alive. If session loss is indicated, it is recommended that any caller strictly relying on ephemeral nodes attempt to remove the ephemeral node.
Returns a one-shot channel which will emit a boolean value indicating whether or not the session loss is due to explicit expiration.
type EventMultiplexer ¶
type EventMultiplexer struct {
// contains filtered or unexported fields
}
Event multiplexer.
func NewEventMultiplexer ¶
func NewEventMultiplexer(eventChan <-chan zk.Event) *EventMultiplexer
New event multiplexer.
func (*EventMultiplexer) Subscribe ¶
func (m *EventMultiplexer) Subscribe() <-chan zk.Event
Subscribe to events.
type SequenceNode ¶
Sequence node.
func ParseSequenceNode ¶
func ParseSequenceNode(name, prefix string) (SequenceNode, error)
Parse a sequence node.
Returns ErrNodeNotMatch if the node does not match the provided prefix or is not a sequence node.
func ParseSequenceNodes ¶
func ParseSequenceNodes(names []string, prefix string) (nodes []SequenceNode)
Parse a list of sequence nodes.
Ignores any node that is not a sequentially numbered node. If a prefix is provided, any node where the sequence number is not immediately preceeded by the prefix is also ignored.
func (SequenceNode) Equals ¶
func (n SequenceNode) Equals(b SequenceNode) bool