Documentation ¶
Overview ¶
Emulate a "global" namespace across n zk quorums.
Index ¶
- Constants
- Variables
- func ChildrenRecursive(zconn Conn, zkPath string) ([]string, error)
- func CreateOrUpdate(zconn Conn, zkPath, value string, flags int, aclv []zookeeper.ACL, ...) (pathCreated string, err error)
- func CreatePidNode(zconn Conn, zkPath string, contents string, done chan struct{}) error
- func CreateRecursive(zconn Conn, zkPath, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error)
- func DeleteRecursive(zconn Conn, zkPath string, version int) error
- func GetZkSubprocessFlags() []string
- func GuessLocalCell() string
- func ObtainQueueLock(zconn Conn, zkPath string, wait time.Duration, interrupted chan struct{}) error
- func RegisterZkReader(zkReader ZkReader)
- func ResolveWildcards(zconn Conn, zkPaths []string) ([]string, error)
- func ZkCellFromZkPath(zkPath string) (string, error)
- func ZkKnownCells(useCache bool) []string
- func ZkPathToZkAddr(zkPath string, useCache bool) (string, error)
- type ChangeFunc
- type Conn
- type ConnCache
- type GlobalConn
- func (gzc *GlobalConn) Children(path string) (children []string, stat Stat, err error)
- func (gzc *GlobalConn) Close() (err error)
- func (gzc *GlobalConn) Create(path, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error)
- func (gzc *GlobalConn) Delete(path string, version int) (err error)
- func (gzc *GlobalConn) Get(path string) (data string, stat Stat, err error)
- func (gzc *GlobalConn) Set(path, value string, version int) (stat Stat, err error)
- type GlobalZookeeperError
- type MetaConn
- func (conn *MetaConn) ACL(path string) (acl []zookeeper.ACL, stat Stat, err error)
- func (conn *MetaConn) Children(path string) (children []string, stat Stat, err error)
- func (conn *MetaConn) ChildrenW(path string) (children []string, stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *MetaConn) Close() error
- func (conn *MetaConn) Create(path, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error)
- func (conn *MetaConn) Delete(path string, version int) (err error)
- func (conn *MetaConn) Exists(path string) (stat Stat, err error)
- func (conn *MetaConn) ExistsW(path string) (stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *MetaConn) Get(path string) (data string, stat Stat, err error)
- func (conn *MetaConn) GetW(path string) (data string, stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *MetaConn) RetryChange(path string, flags int, acl []zookeeper.ACL, changeFunc ChangeFunc) error
- func (conn *MetaConn) Set(path, value string, version int) (stat Stat, err error)
- func (conn *MetaConn) SetACL(path string, aclv []zookeeper.ACL, version int) (err error)
- func (conn *MetaConn) String() string
- type Stat
- type ZkConn
- func (conn *ZkConn) ACL(path string) (acls []zookeeper.ACL, stat Stat, err error)
- func (conn *ZkConn) Children(path string) (children []string, stat Stat, err error)
- func (conn *ZkConn) ChildrenW(path string) (children []string, stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *ZkConn) Close() error
- func (conn *ZkConn) Create(path, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error)
- func (conn *ZkConn) Delete(path string, version int) (err error)
- func (conn *ZkConn) Exists(path string) (stat Stat, err error)
- func (conn *ZkConn) ExistsW(path string) (stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *ZkConn) Get(path string) (data string, stat Stat, err error)
- func (conn *ZkConn) GetW(path string) (data string, stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *ZkConn) RetryChange(path string, flags int, acl []zookeeper.ACL, changeFunc ChangeFunc) error
- func (conn *ZkConn) Set(path, value string, version int) (stat Stat, err error)
- func (conn *ZkConn) SetACL(path string, aclv []zookeeper.ACL, version int) error
- type ZkNode
- type ZkNodeV
- type ZkPath
- type ZkPathV
- type ZkReader
- type ZkStat
- func (zkStat *ZkStat) AVersion() int
- func (zkStat *ZkStat) CTime() time.Time
- func (zkStat *ZkStat) CVersion() int
- func (zkStat *ZkStat) Czxid() int64
- func (zkStat *ZkStat) DataLength() int
- func (zkStat *ZkStat) EphemeralOwner() int64
- func (zkStat *ZkStat) FromZookeeperStat(zStat Stat)
- func (zkStat *ZkStat) MTime() time.Time
- func (zkStat *ZkStat) MarshalBson(buf *bytes2.ChunkedWriter)
- func (zkStat *ZkStat) Mzxid() int64
- func (zkStat *ZkStat) NumChildren() int
- func (zkStat *ZkStat) Pzxid() int64
- func (zkStat *ZkStat) UnmarshalBson(buf *bytes.Buffer)
- func (zkStat *ZkStat) Version() int
- type ZkoccConn
- func (conn *ZkoccConn) ACL(path string) ([]zookeeper.ACL, Stat, error)
- func (conn *ZkoccConn) Children(path string) (children []string, stat Stat, err error)
- func (conn *ZkoccConn) ChildrenW(path string) (children []string, stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *ZkoccConn) Close() error
- func (conn *ZkoccConn) Create(path, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error)
- func (conn *ZkoccConn) Delete(path string, version int) (err error)
- func (conn *ZkoccConn) Exists(path string) (stat Stat, err error)
- func (conn *ZkoccConn) ExistsW(path string) (stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *ZkoccConn) Get(path string) (data string, stat Stat, err error)
- func (conn *ZkoccConn) GetW(path string) (data string, stat Stat, watch <-chan zookeeper.Event, err error)
- func (conn *ZkoccConn) RetryChange(path string, flags int, acl []zookeeper.ACL, changeFunc ChangeFunc) error
- func (conn *ZkoccConn) Set(path, value string, version int) (stat Stat, err error)
- func (conn *ZkoccConn) SetACL(path string, aclv []zookeeper.ACL, version int) error
- type ZkoccUnimplementedError
Constants ¶
const ( DISCONNECTED = 0 CONNECTING = 1 CONNECTED = 2 )
const (
DEFAULT_BASE_TIMEOUT = 5 * time.Second
)
const (
DEFAULT_MAX_RETRIES = 3
)
Variables ¶
var ( // This error is returned by functions that wait for a result // when they are interrupted. ErrInterrupted = errors.New("zkutil: obtaining lock was interrupted") // This error is returned by functions that wait for a result // when the timeout value is reached. ErrTimeout = errors.New("zkutil: obtaining lock timed out") )
Functions ¶
func CreateOrUpdate ¶
func CreatePidNode ¶
Close done when you want to exit cleanly.
func CreateRecursive ¶
func CreateRecursive(zconn Conn, zkPath, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error)
Create a path and any pieces required, think mkdir -p. Intermediate znodes are always created empty.
func GetZkSubprocessFlags ¶
func GetZkSubprocessFlags() []string
GetZkSubprocessFlags returns the flags necessary to run a sub-process that would connect to the same zk servers as this process (assuming the environment of the sub-process is the same as ours)
func GuessLocalCell ¶
func GuessLocalCell() string
Read the cell from -zk.local-cell, or the environment ZK_CLIENT_LOCAL_CELL or guess the cell by the hostname. This is either the first two characters or the character before a dash '-'.
func ObtainQueueLock ¶
func ObtainQueueLock(zconn Conn, zkPath string, wait time.Duration, interrupted chan struct{}) error
The lexically lowest node is the lock holder - verify that this path holds the lock. Call this queue-lock because the semantics are a hybrid. Normal zookeeper locks make assumptions about sequential numbering that don't hold when the data in a lock is modified. if the provided 'interrupted' chan is closed, we'll just stop waiting and return an interruption error
func RegisterZkReader ¶
func RegisterZkReader(zkReader ZkReader)
helper method to register the server (does interface checking)
func ResolveWildcards ¶
resolve 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 ZkCellFromZkPath ¶
func ZkKnownCells ¶
returns all the known cells, alphabetically ordered. It will include 'global' if there is a dc-specific global cell or a global cell
Types ¶
type Conn ¶
type Conn interface { Get(path string) (data string, stat Stat, err error) GetW(path string) (data string, stat Stat, watch <-chan zookeeper.Event, err error) Children(path string) (children []string, stat Stat, err error) ChildrenW(path string) (children []string, stat Stat, watch <-chan zookeeper.Event, err error) Exists(path string) (stat Stat, err error) ExistsW(path string) (stat Stat, watch <-chan zookeeper.Event, err error) Create(path, value string, flags int, aclv []zookeeper.ACL) (pathCreated string, err error) Set(path, value string, version int) (stat Stat, err error) Delete(path string, version int) (err error) Close() error RetryChange(path string, flags int, acl []zookeeper.ACL, changeFunc ChangeFunc) error ACL(path string) ([]zookeeper.ACL, Stat, error) SetACL(path string, aclv []zookeeper.ACL, version int) error }
This interface is really close to the zookeeper connection interface. It uses the Stat interface defined here instead of the zookeeper.Stat structure for stats. Everything else is the same as in zookeeper. So refer to the zookeeper docs for the conventions used here (for instance, using -1 as version to specify any version)
type ConnCache ¶
type ConnCache struct {
// contains filtered or unexported fields
}
func NewConnCache ¶
func (*ConnCache) ConnForPath ¶
type GlobalConn ¶
type GlobalConn struct {
// contains filtered or unexported fields
}
func (*GlobalConn) Children ¶
func (gzc *GlobalConn) Children(path string) (children []string, stat Stat, err error)
func (*GlobalConn) Close ¶
func (gzc *GlobalConn) Close() (err error)
type GlobalZookeeperError ¶
type GlobalZookeeperError string
func (GlobalZookeeperError) Error ¶
func (e GlobalZookeeperError) Error() string
type MetaConn ¶
type MetaConn struct {
// contains filtered or unexported fields
}
func NewMetaConn ¶
func (*MetaConn) RetryChange ¶
type ZkConn ¶
type ZkConn struct {
// contains filtered or unexported fields
}
ZkConn is a client class that implements zk.Conn using a zookeeper.Conn
func DialZk ¶
Dial a ZK server and waits for connection event. Returns a ZkConn encapsulating the zookeeper.Conn, and the zookeeper session event channel to monitor the connection
The value for baseTimeout is used as a session timeout as well, and will be used to negotiate a 'good' value with the server. From reading the zookeeper source code, it has to be between 6 and 60 seconds (2x and 20x the tickTime by default, with default tick time being 3 seconds). min session time, max session time and ticktime can all be overwritten on the zookeeper server side, so these numbers may vary.
Then this baseTimeout is used to compute other related timeouts: - connect timeout is 1/3 of baseTimeout - recv timeout is 2/3 of baseTimeout minus a ping time - send timeout is 1/3 of baseTimeout - we try to send a ping a least every baseTimeout / 3
Note the baseTimeout has *nothing* to do with the time between we call Dial and the maximum time before we receive the event on the session. The library will actually try to re-connect in the background (after each timeout), and may *never* send an event if the TCP connections always fail. Use DialZkTimeout to enforce a timeout for the initial connect.
func DialZkTimeout ¶
func (*ZkConn) RetryChange ¶
type ZkNode ¶
type ZkNode struct { Path string Data string Stat ZkStat Children []string Cached bool // the response comes from the zkocc cache Stale bool // the response is stale because we're not connected }
func (*ZkNode) MarshalBson ¶
func (zkNode *ZkNode) MarshalBson(buf *bytes2.ChunkedWriter)
func (*ZkNode) UnmarshalBson ¶
type ZkNodeV ¶
type ZkNodeV struct {
Nodes []*ZkNode
}
func (*ZkNodeV) MarshalBson ¶
func (zkNodeV *ZkNodeV) MarshalBson(buf *bytes2.ChunkedWriter)
func (*ZkNodeV) UnmarshalBson ¶
type ZkPath ¶
type ZkPath struct {
Path string
}
func (*ZkPath) MarshalBson ¶
func (zkPath *ZkPath) MarshalBson(buf *bytes2.ChunkedWriter)
func (*ZkPath) UnmarshalBson ¶
type ZkPathV ¶
type ZkPathV struct {
Paths []string
}
func (*ZkPathV) MarshalBson ¶
func (zkPathV *ZkPathV) MarshalBson(buf *bytes2.ChunkedWriter)
func (*ZkPathV) UnmarshalBson ¶
type ZkReader ¶
type ZkReader interface { Get(req *ZkPath, reply *ZkNode) error GetV(req *ZkPathV, reply *ZkNodeV) error Children(req *ZkPath, reply *ZkNode) error }
defines the RPC services for zkocc the service name to use is 'ZkReader'
type ZkStat ¶
type ZkStat struct {
// contains filtered or unexported fields
}
func (*ZkStat) DataLength ¶
func (*ZkStat) EphemeralOwner ¶
func (*ZkStat) FromZookeeperStat ¶
helper method
func (*ZkStat) MarshalBson ¶
func (zkStat *ZkStat) MarshalBson(buf *bytes2.ChunkedWriter)
func (*ZkStat) NumChildren ¶
func (*ZkStat) UnmarshalBson ¶
type ZkoccConn ¶
type ZkoccConn struct {
// contains filtered or unexported fields
}
ZkoccConn is a client class that implements zk.Conn but uses a RPC client to talk to a zkocc process
func DialZkocc ¶
From the addr (of the form server1:port1,server2:port2,server3:port3:...) splits it on commas, randomizes the list, and tries to connect to the servers, stopping at the first successful connection
func (*ZkoccConn) Exists ¶
implement Exists using Get FIXME(alainjobart) Maybe we should add Exists in rpc API?
func (*ZkoccConn) RetryChange ¶
type ZkoccUnimplementedError ¶
type ZkoccUnimplementedError string
func (ZkoccUnimplementedError) Error ¶
func (e ZkoccUnimplementedError) Error() string