zk2topo

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// PermDirectory are default permissions for a node.
	PermDirectory = zk.PermAdmin | zk.PermCreate | zk.PermDelete | zk.PermRead | zk.PermWrite

	// PermFile allows a zk node to emulate file behavior by
	// disallowing child nodes.
	PermFile = zk.PermAdmin | zk.PermRead | zk.PermWrite
)

Variables

This section is empty.

Functions

func ChildrenRecursive

func ChildrenRecursive(ctx context.Context, zconn *ZkConn, zkPath string) ([]string, error)

ChildrenRecursive returns the relative path of all the children of the provided node.

func CreateRecursive

func CreateRecursive(ctx context.Context, conn *ZkConn, zkPath string, value []byte, flags int32, aclv []zk.ACL, maxCreationDepth int) (string, error)

CreateRecursive is a helper function on top of Create. It will create a path and any pieces required, think mkdir -p. Intermediate znodes are always created empty. Pass maxCreationDepth=-1 to create all nodes to the top.

func DeleteRecursive

func DeleteRecursive(ctx context.Context, zconn *ZkConn, zkPath string, version int32) error

DeleteRecursive will delete all children of the given path.

func ResolveWildcards

func ResolveWildcards(ctx context.Context, zconn *ZkConn, zkPaths []string) ([]string, error)

ResolveWildcards resolves paths like: /zk/nyc/vt/tablets/*/action /zk/global/vt/keyspaces/*/shards/*/action /zk/*/vt/tablets/*/action into real existing paths

If you send paths that don't contain any wildcard and don't exist, this function will return an empty array.

func Time

func Time(i int64) time.Time

Time returns a time.Time from a ZK int64 milliseconds since Epoch time.

func ZkTime

func ZkTime(t time.Time) int64

ZkTime returns a ZK time (int64) from a time.Time

Types

type Factory

type Factory struct{}

Factory is the zookeeper topo.Factory implementation.

func (Factory) Create

func (f Factory) Create(cell, serverAddr, root string) (topo.Conn, error)

Create is part of the topo.Factory interface.

func (Factory) HasGlobalReadOnlyCell

func (f Factory) HasGlobalReadOnlyCell(serverAddr, root string) bool

HasGlobalReadOnlyCell is part of the topo.Factory interface.

Further implementation design note: Zookeeper supports Observers: https://zookeeper.apache.org/doc/trunk/zookeeperObservers.html To use them, follow these instructions:

  • setup your observer servers as described in the previous link.
  • specify a second set of servers in serverAddr, after a '|', like: global1:port1,global2:port2|observer1:port1,observer2:port2
  • if HasGlobalReadOnlyCell detects that the serverAddr has both lists, it returns true.
  • the Create method below also splits the values, and if cell is GlobalCell, use the left side, if cell is GlobalReadOnlyCell, use the right side.

type Server

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

Server is the zookeeper topo.Conn implementation.

func NewServer

func NewServer(serverAddr, root string) *Server

NewServer returns a topo.Conn connecting to real Zookeeper processes.

func (*Server) Close

func (zs *Server) Close()

Close is part of topo.Conn interface.

func (*Server) Create

func (zs *Server) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error)

Create is part of the topo.Conn interface.

func (*Server) Delete

func (zs *Server) Delete(ctx context.Context, filePath string, version topo.Version) error

Delete is part of the topo.Conn interface.

func (*Server) Get

func (zs *Server) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error)

Get is part of the topo.Conn interface.

func (*Server) ListDir

func (zs *Server) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error)

ListDir is part of the topo.Conn interface.

func (*Server) Lock

func (zs *Server) Lock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)

Lock is part of the topo.Conn interface.

func (*Server) NewMasterParticipation

func (zs *Server) NewMasterParticipation(name, id string) (topo.MasterParticipation, error)

NewMasterParticipation is part of the topo.Server interface. We use the full path: <root path>/election/<name>

func (*Server) Update

func (zs *Server) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error)

Update is part of the topo.Conn interface.

func (*Server) Watch

func (zs *Server) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, topo.CancelFunc)

Watch is part of the topo.Conn interface.

type ZKVersion

type ZKVersion int32

ZKVersion is zookeeper's idea of a version. It implements topo.Version. We use the native zookeeper.Stat.Version type, int32.

func (ZKVersion) String

func (v ZKVersion) String() string

String is part of the topo.Version interface.

type ZkConn

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

ZkConn is a wrapper class on top of a zk.Conn. It will do a few things for us:

  • add the context parameter. However, we do not enforce its deadlines necessarily.
  • enforce a max concurrency of access to Zookeeper. We just don't want to make too many calls concurrently, to not take too many resources.
  • retry some calls to Zookeeper. If we were disconnected from the server, we want to try connecting again before failing.

func Connect

func Connect(addr string) *ZkConn

Connect to the Zookeeper servers specified in addr addr can be a comma separated list of servers and each server can be a DNS entry with multiple values. Connects to the endpoints in a randomized order to avoid hot spots.

func (*ZkConn) Children

func (c *ZkConn) Children(ctx context.Context, path string) (children []string, stat *zk.Stat, err error)

Children is part of the Conn interface.

func (*ZkConn) ChildrenW

func (c *ZkConn) ChildrenW(ctx context.Context, path string) (children []string, stat *zk.Stat, watch <-chan zk.Event, err error)

ChildrenW is part of the Conn interface.

func (*ZkConn) Close

func (c *ZkConn) Close() error

Close is part of the Conn interface.

func (*ZkConn) Create

func (c *ZkConn) Create(ctx context.Context, path string, value []byte, flags int32, aclv []zk.ACL) (pathCreated string, err error)

Create is part of the Conn interface.

func (*ZkConn) Delete

func (c *ZkConn) Delete(ctx context.Context, path string, version int32) error

Delete is part of the Conn interface.

func (*ZkConn) Exists

func (c *ZkConn) Exists(ctx context.Context, path string) (exists bool, stat *zk.Stat, err error)

Exists is part of the Conn interface.

func (*ZkConn) ExistsW

func (c *ZkConn) ExistsW(ctx context.Context, path string) (exists bool, stat *zk.Stat, watch <-chan zk.Event, err error)

ExistsW is part of the Conn interface.

func (*ZkConn) Get

func (c *ZkConn) Get(ctx context.Context, path string) (data []byte, stat *zk.Stat, err error)

Get is part of the Conn interface.

func (*ZkConn) GetACL

func (c *ZkConn) GetACL(ctx context.Context, path string) (aclv []zk.ACL, stat *zk.Stat, err error)

GetACL is part of the Conn interface.

func (*ZkConn) GetW

func (c *ZkConn) GetW(ctx context.Context, path string) (data []byte, stat *zk.Stat, watch <-chan zk.Event, err error)

GetW is part of the Conn interface.

func (*ZkConn) Set

func (c *ZkConn) Set(ctx context.Context, path string, value []byte, version int32) (stat *zk.Stat, err error)

Set is part of the Conn interface.

func (*ZkConn) SetACL

func (c *ZkConn) SetACL(ctx context.Context, path string, aclv []zk.ACL, version int32) error

SetACL is part of the Conn interface.

Jump to

Keyboard shortcuts

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