zookeeper

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0 Imports: 14 Imported by: 18

Documentation

Overview

Package to interface Hailo systems and config with Zookeeper

NOTE: All path parameters should be formated like below. Slashes for the separator and the leading slash are required.

path := "/path/to/my/data"

Index

Constants

View Source
const (
	HealthCheckId  = "com.hailocab.service.zookeeper"
	MaxConnCheckId = "com.hailocab.service.zookeeper.maxconns"
)

Variables

View Source
var (

	// The connection function used when creating a new ZK connection. Replace this with a mock function during tests
	// that test ZooKeeper integration
	Connector func(servers []string, recvTimeout time.Duration) (ZookeeperClient, <-chan gozk.Event, error) = DefaultConnector
)

Functions

func Children

func Children(path string) ([]string, *gozk.Stat, error)

func ChildrenW

func ChildrenW(path string) ([]string, *gozk.Stat, <-chan gozk.Event, error)

func CloseConnection

func CloseConnection() error

CloseConnection closes the underlying network connection to zookeeper This will trigger both the send and recv loops to exit and requests to flush and then we will automatically attempt to reconnect

Needless to say, this is the nuclear option, and should only be used as a part of higher level constructs in the event of a near fatal error

func Create

func Create(path string, data []byte, flags int32, acl []gozk.ACL) (string, error)

func CreateParents

func CreateParents(path string) error

CreateParents creates any parent nodes for the given path if required. If all the parent nodes already exist then no error is returned.

func CreateProtectedEphemeralSequential

func CreateProtectedEphemeralSequential(path string, data []byte, acl []gozk.ACL) (string, error)

func Delete

func Delete(path string, version int32) error

func Exists

func Exists(path string) (bool, *gozk.Stat, error)

func ExistsW

func ExistsW(path string) (bool, *gozk.Stat, <-chan gozk.Event, error)

func Get

func Get(path string) ([]byte, *gozk.Stat, error)

func GetACL

func GetACL(path string) ([]gozk.ACL, *gozk.Stat, error)

func GetW

func GetW(path string) ([]byte, *gozk.Stat, <-chan gozk.Event, error)

func HealthCheck

func HealthCheck() healthcheck.Checker

HealthCheck asserts we can talk to ZK

func MaxConnHealthCheck

func MaxConnHealthCheck(maxconns int) healthcheck.Checker

MaxConnHealthCheck asserts that the total number of established connections to all zookeeper nodes falls below a given max threshold.

func Multi

func Multi(ops gozk.MultiOps) error

func NewLock

func NewLock(path string, acl []gozk.ACL) gozk.Locker

func Set

func Set(path string, data []byte, version int32) (*gozk.Stat, error)

func SetACL

func SetACL(path string, acl []gozk.ACL, version int32) (*gozk.Stat, error)

func State

func State() gozk.State

func Sync

func Sync(path string) (string, error)

func TearDown

func TearDown()

Close and remove the connection, WITHOUT attempting to automatically reconnect

func WaitForConnect

func WaitForConnect(d time.Duration) error

WaitForConnect will wait until we are connected to ZK successfully for duration N

Types

type MockLock

type MockLock struct {
	mock.Mock
}

func (*MockLock) Lock

func (l *MockLock) Lock() error

func (*MockLock) SetTTL

func (l *MockLock) SetTTL(d time.Duration)

func (*MockLock) SetTimeout

func (l *MockLock) SetTimeout(d time.Duration)

func (*MockLock) Unlock

func (l *MockLock) Unlock() error

type MockZookeeperClient

type MockZookeeperClient struct {
	mock.Mock
}

Implements the ZookeeperClient interface

var ActiveMockZookeeperClient *MockZookeeperClient = nil

This must be set to an instance of MockZookeeperClient before tests begin. MockConnector will always return this pointer

func (*MockZookeeperClient) Children

func (c *MockZookeeperClient) Children(path string) ([]string, *gozk.Stat, error)

func (*MockZookeeperClient) ChildrenW

func (c *MockZookeeperClient) ChildrenW(path string) ([]string, *gozk.Stat, <-chan gozk.Event, error)

func (*MockZookeeperClient) Close

func (c *MockZookeeperClient) Close()

func (*MockZookeeperClient) Create

func (c *MockZookeeperClient) Create(path string, data []byte, flags int32, acl []gozk.ACL) (string, error)

func (*MockZookeeperClient) CreateProtectedEphemeralSequential

func (c *MockZookeeperClient) CreateProtectedEphemeralSequential(path string, data []byte, acl []gozk.ACL) (string, error)

func (*MockZookeeperClient) Delete

func (c *MockZookeeperClient) Delete(path string, version int32) error

func (*MockZookeeperClient) Exists

func (c *MockZookeeperClient) Exists(path string) (bool, *gozk.Stat, error)

func (*MockZookeeperClient) ExistsW

func (c *MockZookeeperClient) ExistsW(path string) (bool, *gozk.Stat, <-chan gozk.Event, error)

func (*MockZookeeperClient) Get

func (c *MockZookeeperClient) Get(path string) ([]byte, *gozk.Stat, error)

func (*MockZookeeperClient) GetACL

func (c *MockZookeeperClient) GetACL(path string) ([]gozk.ACL, *gozk.Stat, error)

func (*MockZookeeperClient) GetW

func (c *MockZookeeperClient) GetW(path string) ([]byte, *gozk.Stat, <-chan gozk.Event, error)

func (*MockZookeeperClient) Multi

func (c *MockZookeeperClient) Multi(ops gozk.MultiOps) error

func (*MockZookeeperClient) NewLock

func (c *MockZookeeperClient) NewLock(path string, acl []gozk.ACL) gozk.Locker

func (*MockZookeeperClient) Reconnect

func (c *MockZookeeperClient) Reconnect() error

func (*MockZookeeperClient) Set

func (c *MockZookeeperClient) Set(path string, data []byte, version int32) (*gozk.Stat, error)

func (*MockZookeeperClient) SetACL

func (c *MockZookeeperClient) SetACL(path string, acl []gozk.ACL, version int32) (*gozk.Stat, error)

func (*MockZookeeperClient) State

func (c *MockZookeeperClient) State() gozk.State

func (*MockZookeeperClient) Sync

func (c *MockZookeeperClient) Sync(path string) (string, error)

func (*MockZookeeperClient) UpdateAddrs

func (c *MockZookeeperClient) UpdateAddrs(addrs []string) error

type ZookeeperClient

type ZookeeperClient interface {
	Children(path string) ([]string, *gozk.Stat, error)
	ChildrenW(path string) ([]string, *gozk.Stat, <-chan gozk.Event, error)
	Close()
	Create(path string, data []byte, flags int32, acl []gozk.ACL) (string, error)
	CreateProtectedEphemeralSequential(path string, data []byte, acl []gozk.ACL) (string, error)
	Delete(path string, version int32) error
	Exists(path string) (bool, *gozk.Stat, error)
	ExistsW(path string) (bool, *gozk.Stat, <-chan gozk.Event, error)
	Get(path string) ([]byte, *gozk.Stat, error)
	GetACL(path string) ([]gozk.ACL, *gozk.Stat, error)
	GetW(path string) ([]byte, *gozk.Stat, <-chan gozk.Event, error)
	Multi(ops gozk.MultiOps) error
	Reconnect() error
	Set(path string, data []byte, version int32) (*gozk.Stat, error)
	SetACL(path string, acl []gozk.ACL, version int32) (*gozk.Stat, error)
	State() gozk.State
	Sync(path string) (string, error)
	UpdateAddrs(addrs []string) error
	NewLock(path string, acl []gozk.ACL) gozk.Locker
}

func DefaultConnector

func DefaultConnector(servers []string, recvTimeout time.Duration) (ZookeeperClient, <-chan gozk.Event, error)

The default connection function used; replace the Connector value with this when you finish testing (if you mocked ZooKeeper)

func MockConnector

func MockConnector(servers []string, recvTimeout time.Duration) (ZookeeperClient, <-chan gozk.Event, error)

Connector which returns a MockZooKeeperClient. To use a ZK mock during testing, replace zookeeper.Connector with this function (and be sure to set it back to zookeeper.DefaultConnector when the test exits [via a deferred call])

Jump to

Keyboard shortcuts

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