Documentation ¶
Overview ¶
Package zk is a native Go client library for the ZooKeeper orchestration service.
Index ¶
- Constants
- Variables
- func FormatServers(servers []string) []string
- func ValidatePath(path string, isSequential bool) error
- type ACL
- type AddAuthResponse
- type CheckVersionRequest
- type ChildrenOption
- type ChildrenResponse
- type Client
- func (c *Client) AddAuth(scheme string, auth []byte, callback func(resp AddAuthResponse, err error))
- func (c *Client) Children(path string, callback func(resp ChildrenResponse, err error), ...)
- func (c *Client) Close()
- func (c *Client) Create(path string, data []byte, flags int32, acl []ACL, ...)
- func (c *Client) Delete(path string, version int32, callback func(resp DeleteResponse, err error))
- func (c *Client) Exists(path string, callback func(resp ExistsResponse, err error), ...)
- func (c *Client) Get(path string, callback func(resp GetResponse, err error), options ...GetOption)
- func (c *Client) GetACL(path string, callback func(resp GetACLResponse, err error))
- func (c *Client) Set(path string, data []byte, version int32, ...)
- func (c *Client) SetACL(path string, acl []ACL, version int32, ...)
- type CreateContainerRequest
- type CreateRequest
- type CreateResponse
- type CreateTTLRequest
- type DeleteRequest
- type DeleteResponse
- type ErrCode
- type Event
- type EventType
- type ExistsOption
- type ExistsResponse
- type GetACLResponse
- type GetOption
- type GetResponse
- type Logger
- type Mode
- type NetworkConn
- type Option
- func WithDialRetryDuration(d time.Duration) Option
- func WithDialTimeoutFunc(dialFunc func(addr string, timeout time.Duration) (NetworkConn, error)) Option
- func WithLogger(l Logger) Option
- func WithReconnectingCallback(callback func(c *Client)) Option
- func WithServerSelector(selector ServerSelector) Option
- func WithSessionEstablishedCallback(callback func(c *Client)) Option
- func WithSessionExpiredCallback(callback func(c *Client)) Option
- type PathVersionRequest
- type SelectNextOutput
- type ServerClient
- type ServerClients
- type ServerListSelector
- type ServerSelector
- type ServerStats
- type SetACLResponse
- type SetDataRequest
- type SetResponse
- type Stat
- type State
Constants ¶
const ( // FlagEphemeral means the node is ephemeral. FlagEphemeral = 1 FlagSequence = 2 FlagTTL = 4 )
const ( // PermRead represents the permission needed to read a znode. PermRead = 1 << iota PermWrite PermCreate PermDelete PermAdmin PermAll = 0x1f )
Constants for ACL permissions
const (
// DefaultPort is the default port listened by server.
DefaultPort = 2181
)
Variables ¶
var ( // ErrConnectionClosed means the connection has been closed. ErrConnectionClosed = errors.New("zk: connection closed") ErrUnknown = errors.New("zk: unknown error") ErrAPIError = errors.New("zk: api error") ErrNoNode = errors.New("zk: node does not exist") ErrNoAuth = errors.New("zk: not authenticated") ErrBadVersion = errors.New("zk: version conflict") ErrNoChildrenForEphemerals = errors.New("zk: ephemeral nodes may not have children") ErrNodeExists = errors.New("zk: node already exists") ErrNotEmpty = errors.New("zk: node has children") ErrSessionExpired = errors.New("zk: session has been expired by the server") ErrInvalidACL = errors.New("zk: invalid ACL specified") ErrAuthFailed = errors.New("zk: client authentication failed") ErrClosing = errors.New("zk: zookeeper is closing") ErrNothing = errors.New("zk: no server responses to process") ErrSessionMoved = errors.New("zk: session moved to another server, so operation is ignored") ErrReconfigDisabled = errors.New("attempts to perform a reconfiguration operation when reconfiguration feature is disabled") ErrBadArguments = errors.New("invalid arguments") )
var ( ErrUnhandledFieldType = errors.New("zk: unhandled field type") ErrPtrExpected = errors.New("zk: encode/decode expect a non-nil pointer to struct") ErrShortBuffer = errors.New("zk: buffer too small") )
var ErrInvalidPath = errors.New("zk: invalid path")
ErrInvalidPath indicates that an operation was being attempted on an invalid path. (e.g. empty path).
Functions ¶
func FormatServers ¶
FormatServers takes a slice of addresses, and makes sure they are in a format that resembles <addr>:<port>. If the server has no port provided, the DefaultPort constant is added to the end.
func ValidatePath ¶
ValidatePath will make sure a path is valid before sending the request
Types ¶
type ACL ¶
type AddAuthResponse ¶
type AddAuthResponse struct {
Zxid int64
}
type CheckVersionRequest ¶
type CheckVersionRequest PathVersionRequest
type ChildrenOption ¶
type ChildrenOption func(opts *childrenOpts)
func WithChildrenWatch ¶
func WithChildrenWatch(callback func(ev Event)) ChildrenOption
type ChildrenResponse ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client ...
func (*Client) AddAuth ¶
func (c *Client) AddAuth( scheme string, auth []byte, callback func(resp AddAuthResponse, err error), )
AddAuth often used with "digest" scheme and auth = "username:password" (password is not hashed)
func (*Client) Children ¶
func (c *Client) Children( path string, callback func(resp ChildrenResponse, err error), options ...ChildrenOption, )
func (*Client) Create ¶
func (c *Client) Create( path string, data []byte, flags int32, acl []ACL, callback func(resp CreateResponse, err error), )
Create ...
func (*Client) Delete ¶
func (c *Client) Delete( path string, version int32, callback func(resp DeleteResponse, err error), )
func (*Client) Exists ¶
func (c *Client) Exists( path string, callback func(resp ExistsResponse, err error), options ...ExistsOption, )
func (*Client) Get ¶
func (c *Client) Get( path string, callback func(resp GetResponse, err error), options ...GetOption, )
func (*Client) GetACL ¶
func (c *Client) GetACL( path string, callback func(resp GetACLResponse, err error), )
GetACL returns ACL for a znode
type CreateContainerRequest ¶
type CreateContainerRequest CreateRequest
type CreateResponse ¶
type CreateTTLRequest ¶
type DeleteRequest ¶
type DeleteRequest PathVersionRequest
type DeleteResponse ¶
type DeleteResponse struct {
Zxid int64
}
type ErrCode ¶
type ErrCode int32
ErrCode is the error code defined by server. Refer to ZK documentations for more specifics.
type Event ¶
type Event struct { Type EventType State State Path string // For non-session events, the path of the watched node. }
Event is a Znode event sent by the server. Refer to EventType for more details.
type ExistsOption ¶
type ExistsOption func(opts *existsOpts)
func WithExistsWatch ¶
func WithExistsWatch(callback func(ev Event)) ExistsOption
type ExistsResponse ¶
type GetACLResponse ¶
type GetResponse ¶
type NetworkConn ¶
type NetworkConn interface { io.Reader io.Writer io.Closer // SetReadDeadline sets the deadline for future Read calls // and any currently-blocked Read call. // A zero value for t means Read will not time out. SetReadDeadline(d time.Duration) error // SetWriteDeadline sets the deadline for future Write calls // and any currently-blocked Write call. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means Write will not time out. SetWriteDeadline(d time.Duration) error }
func NewTCPConn ¶
func NewTCPConn(conn net.Conn) NetworkConn
type Option ¶
type Option func(c *Client)
Option ...
func WithDialRetryDuration ¶
func WithDialTimeoutFunc ¶
func WithLogger ¶
func WithServerSelector ¶
func WithServerSelector(selector ServerSelector) Option
type PathVersionRequest ¶
type SelectNextOutput ¶
type ServerClient ¶
type ServerClient struct { Queued int64 Received int64 Sent int64 SessionID int64 Lcxid int64 Lzxid int64 Timeout int32 LastLatency int32 MinLatency int32 AvgLatency int32 MaxLatency int32 Established time.Time LastResponse time.Time Addr string LastOperation string // maybe? Error error }
ServerClient is the information for a single Zookeeper client and its session. This is used to parse/extract the output fo the `cons` command.
type ServerClients ¶
type ServerClients struct { Clients []*ServerClient Error error }
ServerClients is a struct for the FLWCons() function. It's used to provide the list of Clients.
This is needed because FLWCons() takes multiple servers.
type ServerListSelector ¶
type ServerListSelector struct {
// contains filtered or unexported fields
}
func (*ServerListSelector) Init ¶
func (s *ServerListSelector) Init(servers []string)
func (*ServerListSelector) Next ¶
func (s *ServerListSelector) Next() SelectNextOutput
func (*ServerListSelector) NotifyConnected ¶
func (s *ServerListSelector) NotifyConnected()
type ServerSelector ¶
type ServerSelector interface { Init(servers []string) Next() SelectNextOutput NotifyConnected() }
func NewServerListSelector ¶
func NewServerListSelector(seed int64) ServerSelector
type ServerStats ¶
type ServerStats struct { Server string Sent int64 Received int64 NodeCount int64 MinLatency int64 AvgLatency float64 MaxLatency int64 Connections int64 Outstanding int64 Epoch int32 Counter int32 BuildTime time.Time Mode Mode Version string Error error }
ServerStats is the information pulled from the Zookeeper `stat` command.
type SetACLResponse ¶
type SetDataRequest ¶
type SetResponse ¶
type Stat ¶
type Stat struct { Czxid int64 // The zxid of the change that caused this znode to be created. Mzxid int64 // The zxid of the change that last modified this znode. Ctime int64 // The time in milliseconds from epoch when this znode was created. Mtime int64 // The time in milliseconds from epoch when this znode was last modified. Version int32 // The number of changes to the data of this znode. Cversion int32 // The number of changes to the children of this znode. Aversion int32 // The number of changes to the ACL of this znode. EphemeralOwner int64 // The session id of the owner of this znode if the znode is an ephemeral node. If it is not an ephemeral node, it will be zero. DataLength int32 // The length of the data field of this znode. NumChildren int32 // The number of children of this znode. Pzxid int64 // last modified children }
type State ¶
type State int32
State is the session state.
const ( // StateUnknown means the session state is unknown. StateUnknown State = -1 StateDisconnected State = 0 StateConnecting State = 1 StateAuthFailed State = 4 StateConnectedReadOnly State = 5 StateSaslAuthenticated State = 6 StateExpired State = -112 StateConnected = State(100) StateHasSession = State(101) )