zk

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNode

func CreateNode(t *testing.T, zkConn *szk.Conn, path string, obj interface{})

CreateNode creates a single node at the argument path. For testing purposes only.

func CreateNodes

func CreateNodes(t *testing.T, zkConn *szk.Conn, pathTuples []PathTuple)

CreateNodes creates nodes according to the argument PathTuples. For testing purposes only.

Types

type Client

type Client interface {
	// Read-only operations
	Get(ctx context.Context, path string) ([]byte, *szk.Stat, error)
	GetJSON(ctx context.Context, path string, obj interface{}) (*szk.Stat, error)
	Children(ctx context.Context, path string) ([]string, *szk.Stat, error)
	Exists(
		ctx context.Context,
		path string,
	) (bool, *szk.Stat, error)

	// Write operations
	Create(ctx context.Context, path string, data []byte, sequential bool) error
	CreateJSON(ctx context.Context, path string, obj interface{}, sequential bool) error
	Set(
		ctx context.Context,
		path string,
		data []byte,
		version int32,
	) (*szk.Stat, error)
	SetJSON(
		ctx context.Context,
		path string,
		obj interface{},
		version int32,
	) (*szk.Stat, error)

	// Lock operations
	AcquireLock(ctx context.Context, path string) (Lock, error)

	Close() error
}

Client exposes some common, zk operations. Unlike the underlying samuel zk client, it allows passing a context into most calls.

type DebugLogger added in v1.3.0

type DebugLogger struct{}

DebugLogger is a logger that satisfies the szk.Logger interface.

func (*DebugLogger) Printf added in v1.3.0

func (l *DebugLogger) Printf(format string, args ...interface{})

Printf sends samuel zk log messages to logrus at the debug level.

type Lock

type Lock interface {
	Unlock() error
}

Lock is a lock interface that's satified by the samuel zk Lock struct.

type PathTuple

type PathTuple struct {
	Path string
	Obj  interface{}
}

PathTuple is a <path, object> combination used for generating nodes in zk. For testing purposes only.

type PooledClient

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

PooledClient is a Client implementation that uses a pool of connections instead of a single one for read-only operations. It can be subtantially faster than the base samuel client, particularly when getting zookeeper nodes from multiple goroutines.

func NewPooledClient

func NewPooledClient(
	zkAddrs []string,
	timeout time.Duration,
	logger szk.Logger,
	poolSize int,
	readOnly bool,
) (*PooledClient, error)

NewPooledClient returns a new PooledClient instance.

func (*PooledClient) AcquireLock

func (c *PooledClient) AcquireLock(ctx context.Context, path string) (Lock, error)

AcquireLock tries to acquire a lock using the argument zk path.

func (*PooledClient) Children

func (c *PooledClient) Children(
	ctx context.Context,
	path string,
) ([]string, *szk.Stat, error)

Children gets all children of the node at the argument zk path.

func (*PooledClient) Close

func (c *PooledClient) Close() error

Close closes the current client and frees the associated resources.

func (*PooledClient) Create

func (c *PooledClient) Create(
	ctx context.Context,
	path string,
	data []byte,
	sequential bool,
) error

Create adds a new node at the argument zk path.

func (*PooledClient) CreateJSON

func (c *PooledClient) CreateJSON(
	ctx context.Context,
	path string,
	obj interface{},
	sequential bool,
) error

CreateJSON creates a new node at the argument zk path using the JSON-marshalled contents of the argument object.

func (*PooledClient) Exists

func (c *PooledClient) Exists(
	ctx context.Context,
	path string,
) (bool, *szk.Stat, error)

Exists returns whether a node exists at the argument zk path.

func (*PooledClient) Get

func (c *PooledClient) Get(
	ctx context.Context,
	path string,
) ([]byte, *szk.Stat, error)

Get returns the value at the argument zk path.

func (*PooledClient) GetJSON

func (c *PooledClient) GetJSON(
	ctx context.Context,
	path string,
	obj interface{},
) (*szk.Stat, error)

GetJSON unmarshals the JSON content at the argument zk path into an object.

func (*PooledClient) Set

func (c *PooledClient) Set(
	ctx context.Context,
	path string,
	data []byte,
	version int32,
) (*szk.Stat, error)

Set updates the contents of the node at the argument zk path.

func (*PooledClient) SetJSON

func (c *PooledClient) SetJSON(
	ctx context.Context,
	path string,
	obj interface{},
	version int32,
) (*szk.Stat, error)

SetJSON updates the contents of the node at the argument zk path using the JSON marshalling of the argument object.

Jump to

Keyboard shortcuts

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