zookeeper

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Overview

Copyright 2016 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDeadlock is returned when a lock is aquired twice on the same object.
	ErrDeadlock = errors.New("zk: trying to acquire a lock twice")

	// ErrNotLocked is returned when a caller attempts to release a lock that
	// has not been aquired
	ErrNotLocked = errors.New("zk: not locked")

	// ErrNoLeaderFound is returned when a leader has not been elected
	ErrNoLeaderFound = errors.New("zk: no leader found")
)

Functions

func GetLowestSequence

func GetLowestSequence(ch []string) (string, error)

GetLowestSequence returns the lowest sequenced value ephemeral node from the list.

func RegisterZKLogger

func RegisterZKLogger()

Register a logger for the Zookeeper library which will messages from their library to our application log

Types

type Connection

type Connection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Connection is a Zookeeper based implementation of client.Connection.

func (*Connection) Children

func (c *Connection) Children(path string) ([]string, error)

Children returns the children of the node at the given path.

func (*Connection) ChildrenW

func (c *Connection) ChildrenW(path string, cancel <-chan struct{}) ([]string, <-chan client.Event, error)

ChildrenW returns the children of the node at the given path as well as a channel to watch for events on that node.

func (*Connection) Close

func (c *Connection) Close()

Close closes the client connection to zookeeper. Calling close twice will result in a no-op.

func (*Connection) Create

func (c *Connection) Create(path string, node client.Node) error

Create adds a node at the specified path

func (*Connection) CreateDir

func (c *Connection) CreateDir(path string) error

CreateDir adds a dir at the specified path

func (*Connection) CreateEphemeral

func (c *Connection) CreateEphemeral(path string, node client.Node) (string, error)

CreateEphemeral creates a node whose existance depends on the persistence of the connection.

func (*Connection) CreateEphemeralIfExists

func (c *Connection) CreateEphemeralIfExists(path string, node client.Node) (string, error)

CreateEphemeralIfExists creates an ephemeral node at the given path if it exists.

func (*Connection) CreateIfExists

func (c *Connection) CreateIfExists(path string, node client.Node) error

CreateIfExists adds a node at the specified path if the dirpath already exists.

func (*Connection) Delete

func (c *Connection) Delete(path string) error

Delete recursively removes a path and its children

func (*Connection) Exists

func (c *Connection) Exists(path string) (bool, error)

Exists returns true if the path exists

func (*Connection) ExistsW

func (c *Connection) ExistsW(path string, cancel <-chan struct{}) (bool, <-chan client.Event, error)

ExistsW sets a watch on a node and alerts whenever it is added or removed.

func (*Connection) Get

func (c *Connection) Get(path string, node client.Node) error

Get returns the node at the given path.

func (*Connection) GetW

func (c *Connection) GetW(path string, node client.Node, cancel <-chan struct{}) (<-chan client.Event, error)

GetW returns the node at the given path as well as a channel to watch for events on that node.

func (*Connection) ID

func (c *Connection) ID() int

ID gets the connection ID

func (*Connection) NewLeader

func (c *Connection) NewLeader(p string) (client.Leader, error)

NewLeader returns a managed leader object at the given path bound to the current connection.

func (*Connection) NewLock

func (c *Connection) NewLock(p string) (client.Lock, error)

NewLock creates a new lock object

func (*Connection) NewTransaction

func (c *Connection) NewTransaction() client.Transaction

NewTransaction creates a new transaction object

func (*Connection) Set

func (c *Connection) Set(path string, node client.Node) error

Set assigns a value to an existing node at a given path

func (*Connection) SetID

func (c *Connection) SetID(i int)

SetID sets the connection ID

func (*Connection) SetOnClose

func (c *Connection) SetOnClose(onClose func(int))

SetOnClose performs cleanup when a connection is closed

type DSN

type DSN struct {
	Servers             []string
	SessionTimeout      time.Duration
	ConnectTimeout      time.Duration
	PerHostConnectDelay time.Duration
	ReconnectStartDelay time.Duration
	ReconnectMaxDelay   time.Duration
}

DSN is a Zookeeper specific struct used for connections. It can be serialized.

func NewDSN

func NewDSN(servers []string,
	sessionTimeout time.Duration,
	connectTimeout time.Duration,
	perHostConnectDelay time.Duration,
	reconnectStartDelay time.Duration,
	reconnectMaxDelay time.Duration) DSN

NewDSN returns a new DSN object from servers and timeout.

func ParseDSN

func ParseDSN(dsn string) (val DSN, err error)

ParseDSN decodes a string (JSON) represnation of a DSN object.

func (DSN) String

func (dsn DSN) String() string

String creates a parsable (JSON) string represenation of this DSN.

type Driver

type Driver struct{}

Driver implements a Zookeeper based client.Driver interface

func (*Driver) GetConnection

func (driver *Driver) GetConnection(dsn, basePath string) (client.Connection, error)

GetConnection returns a Zookeeper connection given the dsn. The caller is responsible for closing the returned connection.

type Leader

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

Leader is an object to facilitate creating an election in zookeeper.

func NewLeader

func NewLeader(conn *zklib.Conn, path string, acl []zklib.ACL) *Leader

NewLeader instantiates a new leader for a given path

func (*Leader) Current

func (l *Leader) Current(node client.Node) error

Current returns the currect elected leader and deserializes it in to node. It will return ErrNoLeaderFound if no leader has been elected.

func (*Leader) ReleaseLead

func (l *Leader) ReleaseLead() error

ReleaseLead release the current leader role. It will return ErrNotLocked if the current object is not locked.

func (*Leader) TakeLead

func (l *Leader) TakeLead(node client.Node, cancel <-chan struct{}) (<-chan client.Event, error)

TakeLead attempts to aquire the leader role. When aquired it returns a channel on the leader node so the caller can react to changes in zookeeper

type Lock

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

Lock creates a object to facilitate create a locking pattern in zookeeper.

func (*Lock) Lock

func (l *Lock) Lock() error

Lock attempts to acquire the lock.

func (*Lock) Unlock

func (l *Lock) Unlock() error

Unlock attempts to release the lock.

type Transaction

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

func (*Transaction) Commit

func (t *Transaction) Commit() error

func (*Transaction) Create

func (t *Transaction) Create(path string, node client.Node) client.Transaction

func (*Transaction) Delete

func (t *Transaction) Delete(path string) client.Transaction

func (*Transaction) Set

func (t *Transaction) Set(path string, node client.Node) client.Transaction

Jump to

Keyboard shortcuts

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