Documentation ¶
Index ¶
- Constants
- func ChildrenRecursive(ctx context.Context, zconn *ZkConn, zkPath string) ([]string, error)
- func CreateRecursive(ctx context.Context, conn *ZkConn, zkPath string, value []byte, flags int32, ...) (string, error)
- func DeleteRecursive(ctx context.Context, zconn *ZkConn, zkPath string, version int32) error
- func ResolveWildcards(ctx context.Context, zconn *ZkConn, zkPaths []string) ([]string, error)
- func Time(i int64) time.Time
- type Factory
- type Server
- func (zs *Server) Close()
- func (zs *Server) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error)
- func (zs *Server) Delete(ctx context.Context, filePath string, version topo.Version) error
- func (zs *Server) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error)
- func (zs *Server) GetVersion(ctx context.Context, filePath string, version int64) ([]byte, error)
- func (zs *Server) List(ctx context.Context, filePathPrefix string) ([]topo.KVInfo, error)
- func (zs *Server) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error)
- func (zs *Server) Lock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
- func (zs *Server) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
- func (zs *Server) TryLock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
- func (zs *Server) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error)
- func (zs *Server) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, error)
- func (zs *Server) WatchRecursive(_ context.Context, path string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error)
- type ZKVersion
- type ZkConn
- func (c *ZkConn) AddAuth(ctx context.Context, scheme string, auth []byte) error
- func (c *ZkConn) Children(ctx context.Context, path string) (children []string, stat *zk.Stat, err error)
- func (c *ZkConn) ChildrenW(ctx context.Context, path string) (children []string, stat *zk.Stat, watch <-chan zk.Event, err error)
- func (c *ZkConn) Close() error
- func (c *ZkConn) Create(ctx context.Context, path string, value []byte, flags int32, aclv []zk.ACL) (pathCreated string, err error)
- func (c *ZkConn) Delete(ctx context.Context, path string, version int32) error
- func (c *ZkConn) Exists(ctx context.Context, path string) (exists bool, stat *zk.Stat, err error)
- func (c *ZkConn) ExistsW(ctx context.Context, path string) (exists bool, stat *zk.Stat, watch <-chan zk.Event, err error)
- func (c *ZkConn) Get(ctx context.Context, path string) (data []byte, stat *zk.Stat, err error)
- func (c *ZkConn) GetACL(ctx context.Context, path string) (aclv []zk.ACL, stat *zk.Stat, err error)
- func (c *ZkConn) GetW(ctx context.Context, path string) (data []byte, stat *zk.Stat, watch <-chan zk.Event, err error)
- func (c *ZkConn) Set(ctx context.Context, path string, value []byte, version int32) (stat *zk.Stat, err error)
- func (c *ZkConn) SetACL(ctx context.Context, path string, aclv []zk.ACL, version int32) error
Constants ¶
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 ¶
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 ¶
DeleteRecursive will delete all children of the given path.
func ResolveWildcards ¶
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.
Types ¶
type Factory ¶
type Factory struct{}
Factory is the zookeeper topo.Factory implementation.
func (Factory) HasGlobalReadOnlyCell ¶
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 (*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) GetVersion ¶ added in v0.20.0
GetVersion is part of topo.Conn interface.
func (*Server) NewLeaderParticipation ¶ added in v0.13.0
func (zs *Server) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
NewLeaderParticipation is part of the topo.Server interface. We use the full path: <root path>/election/<name>
func (*Server) TryLock ¶ added in v0.16.0
func (zs *Server) TryLock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
TryLock is part of the topo.Conn interface.
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, error)
Watch is part of the topo.Conn interface.
func (*Server) WatchRecursive ¶ added in v0.15.0
func (zs *Server) WatchRecursive(_ context.Context, path string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error)
WatchRecursive 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.
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 ¶
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) 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) 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) 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.