zkutils

package
v0.0.0-...-171db1f Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2015 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package zkutils provides ZooKeeper utility methods.

The functionality is implemented atop github.com/samuel/go-zookeeper/zk.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Node is not a match.
	ErrNodeNotMatch = errors.New("node is not a match")

	// Timeout error.
	ErrTimeout = errors.New("timeout")
)

Functions

func AwaitExists

func AwaitExists(conn *zk.Conn, path string) <-chan error

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

func CreateRecursively(conn *zk.Conn, path string, acl []zk.ACL) (err error)

Recursively create nodes with no data if they do not exist.

Does not return any error if the node path already exist.

func CreateTestCluster

func CreateTestCluster(t *testing.T, size int) (testCluster *zk.TestCluster, serverAddrs []string)

Create a test cluster of a given size.

func DeleteSafely

func DeleteSafely(conn *zk.Conn, path string)

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

func IsErrorRecoverable(err error) bool

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

func StartTestCluster(size int, stdout, stderr io.Writer) (*zk.TestCluster, error)

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 Connect

func Connect(servers []string, sessionTimeout time.Duration) (*ConnMan, error)

Connect as connection manager.

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) Close

func (m *ConnMan) Close()

Close connection.

func (*ConnMan) Subscribe

func (m *ConnMan) Subscribe() <-chan zk.Event

Subscribe to all events for the connection.

func (*ConnMan) WatchSessionLoss

func (m *ConnMan) WatchSessionLoss() <-chan bool

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

type SequenceNode struct {
	// Name.
	Name string

	// Sequence number.
	SequenceNumber int32
}

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

Jump to

Keyboard shortcuts

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