Documentation ¶
Index ¶
- Constants
- Variables
- func StartTracer(listenAddr, serverAddr string)
- type ACL
- type CheckVersionRequest
- type Conn
- func (c *Conn) AddAuth(scheme string, auth []byte) error
- func (c *Conn) Children(path string) ([]string, *Stat, error)
- func (c *Conn) ChildrenW(path string) ([]string, *Stat, <-chan Event, error)
- func (c *Conn) Close()
- func (c *Conn) Create(path string, data []byte, flags int32, acl []ACL) (string, error)
- func (c *Conn) CreateProtectedEphemeralSequential(path string, data []byte, acl []ACL) (string, error)
- func (c *Conn) Delete(path string, version int32) error
- func (c *Conn) Exists(path string) (bool, *Stat, error)
- func (c *Conn) ExistsW(path string) (bool, *Stat, <-chan Event, error)
- func (c *Conn) Get(path string) ([]byte, *Stat, error)
- func (c *Conn) GetACL(path string) ([]ACL, *Stat, error)
- func (c *Conn) GetW(path string) ([]byte, *Stat, <-chan Event, error)
- func (c *Conn) Multi(ops MultiOps) error
- func (c *Conn) NewLock(path string, acl []ACL) Locker
- func (c *Conn) Reconnect() error
- func (c *Conn) Set(path string, data []byte, version int32) (*Stat, error)
- func (c *Conn) SetACL(path string, acl []ACL, version int32) (*Stat, error)
- func (c *Conn) State() State
- func (c *Conn) Sync(path string) (string, error)
- func (c *Conn) UpdateAddrs(addrs []string) error
- type CreateRequest
- type DeleteRequest
- type Dialer
- type ErrCode
- type ErrMissingServerConfigField
- type Event
- type EventType
- type Lock
- type Locker
- type MultiOps
- type PathVersionRequest
- type Server
- type ServerConfig
- type ServerConfigServer
- type SetDataRequest
- type Stat
- type State
- type TestCluster
- type TestServer
Constants ¶
const ( EventNodeCreated = EventType(1) EventNodeDeleted = EventType(2) EventNodeDataChanged = EventType(3) EventNodeChildrenChanged = EventType(4) EventSession = EventType(-1) EventNotWatching = EventType(-2) )
const ( StateUnknown = State(-1) StateDisconnected = State(0) StateConnecting = State(1) StateSyncConnected = State(3) StateAuthFailed = State(4) StateConnectedReadOnly = State(5) StateSaslAuthenticated = State(6) StateExpired = State(-112) StateConnected = State(100) StateHasSession = State(101) )
const ( FlagEphemeral = 1 FlagSequence = 2 )
const ( PermRead = 1 << iota PermWrite PermCreate PermDelete PermAdmin PermAll = 0x1f )
Constants for ACL permissions
const ( DefaultServerTickTime = 2000 DefaultServerInitLimit = 10 DefaultServerSyncLimit = 5 DefaultServerAutoPurgeSnapRetainCount = 3 DefaultPeerPort = 2888 DefaultLeaderElectionPort = 3888 )
const (
DefaultPort = 2181
)
Variables ¶
var ( 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 responsees to process") ErrSessionMoved = errors.New("zk: session moved to another server, so operation is ignored") ErrRequestTimeout = errors.New("zk: request timed out") )
var ( ErrDeadlock = errors.New("zk: trying to acquire a lock twice") ErrNotLocked = errors.New("zk: not locked") ErrLockTimeout = errors.New("zk: timeout trying to acquire lock") )
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 ErrNoServer = errors.New("zk: could not connect to a server")
Functions ¶
func StartTracer ¶
func StartTracer(listenAddr, serverAddr string)
Types ¶
type ACL ¶
type CheckVersionRequest ¶
type CheckVersionRequest PathVersionRequest
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func ConnectWithDialer ¶
func (*Conn) CreateProtectedEphemeralSequential ¶
func (c *Conn) CreateProtectedEphemeralSequential(path string, data []byte, acl []ACL) (string, error)
CreateProtectedEphemeralSequential fixes a race condition if the server crashes after it creates the node. On reconnect the session may still be valid so the ephemeral node still exists. Therefore, on reconnect we need to check if a node with a GUID generated on create exists.
func (*Conn) Reconnect ¶
Reconnect closes the underlying network connection to zookeeper This will trigger both the send and recv loops to exit and requests to flush and then we will automatically attempt to reconnect
func (*Conn) UpdateAddrs ¶
type DeleteRequest ¶
type DeleteRequest PathVersionRequest
type ErrMissingServerConfigField ¶
type ErrMissingServerConfigField string
func (ErrMissingServerConfigField) Error ¶
func (e ErrMissingServerConfigField) Error() string
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
func (*Lock) Lock ¶
Lock attempts to acquire a lock. Uses the recipe http://zookeeper.apache.org/doc/trunk/recipes.html#sc_recipes_Locks. Timeout achieved by first creating the lock node and then waiting X secs. If lock not yet acquired it will delete and then return. Does not account for initial request taking too long
func (*Lock) SetTimeout ¶
SetTimeout sets the time we will wait to acquire the lock, bail out if time is exceeded
type MultiOps ¶
type MultiOps struct { Create []CreateRequest Delete []DeleteRequest SetData []SetDataRequest Check []CheckVersionRequest }
type PathVersionRequest ¶
type ServerConfig ¶
type ServerConfig struct { TickTime int // Number of milliseconds of each tick InitLimit int // Number of ticks that the initial synchronization phase can take SyncLimit int // Number of ticks that can pass between sending a request and getting an acknowledgement DataDir string // Direcrory where the snapshot is stored ClientPort int // Port at which clients will connect AutoPurgeSnapRetainCount int // Number of snapshots to retain in dataDir AutoPurgePurgeInterval int // Purge task internal in hours (0 to disable auto purge) Servers []ServerConfigServer }
type ServerConfigServer ¶
type SetDataRequest ¶
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 TestCluster ¶
type TestCluster struct { Path string Servers []TestServer }
func StartTestCluster ¶
func StartTestCluster(size int) (*TestCluster, error)
func (*TestCluster) ConnectAll ¶
func (ts *TestCluster) ConnectAll() (*Conn, error)
func (*TestCluster) Stop ¶
func (ts *TestCluster) Stop() error