zk

package
v0.0.0-...-e9ca0f2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: BSD-3-Clause Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	EventNodeCreated         = EventType(1)
	EventNodeDeleted         = EventType(2)
	EventNodeDataChanged     = EventType(3)
	EventNodeChildrenChanged = EventType(4)

	EventSession     = EventType(-1)
	EventNotWatching = EventType(-2)
)
View Source
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)
)
View Source
const (
	PermRead = 1 << iota
	PermWrite
	PermCreate
	PermDelete
	PermAdmin
	PermAll = 0x1f
)

Constants for ACL permissions

View Source
const (
	DefaultPort = 2181
)

Variables

View Source
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")
)
View Source
var (
	ErrDeadlock  = errors.New("zk: trying to acquire a lock twice")
	ErrNotLocked = errors.New("zk: not locked")
)
View Source
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")
)
View Source
var ErrNoServer = errors.New("zk: could not connect to a server")

Functions

func StartTracer

func StartTracer(listenAddr, serverAddr string)

Types

type ACL

type ACL struct {
	Perms  int32
	Scheme string
	ID     string
}

func AuthACL

func AuthACL(perms int32) []ACL

AuthACL produces an ACL list containing a single ACL which uses the provided permissions, with the scheme "auth", and ID "", which is used by ZooKeeper to represent any authenticated user.

func DigestACL

func DigestACL(perms int32, user, password string) []ACL

func WorldACL

func WorldACL(perms int32) []ACL

WorldACL produces an ACL list containing a single ACL which uses the provided permissions, with the scheme "world", and ID "anyone", which is used by ZooKeeper to represent any user at all.

type CheckVersionRequest

type CheckVersionRequest PathVersionRequest

type Conn

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

func Connect

func Connect(servers []string, recvTimeout time.Duration) (*Conn, <-chan Event, error)

func ConnectWithDialer

func ConnectWithDialer(servers []string, recvTimeout time.Duration, dialer Dialer) (*Conn, <-chan Event, error)

func (*Conn) AddAuth

func (c *Conn) AddAuth(scheme string, auth []byte) error

func (*Conn) Children

func (c *Conn) Children(path string) ([]string, *Stat, error)

func (*Conn) ChildrenW

func (c *Conn) ChildrenW(path string) ([]string, *Stat, <-chan Event, error)

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) Create

func (c *Conn) Create(path string, data []byte, flags CreateType, acl []ACL) (string, error)

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) Delete

func (c *Conn) Delete(path string, version int32) error

func (*Conn) Exists

func (c *Conn) Exists(path string) (bool, *Stat, error)

func (*Conn) ExistsW

func (c *Conn) ExistsW(path string) (bool, *Stat, <-chan Event, error)

func (*Conn) Get

func (c *Conn) Get(path string) ([]byte, *Stat, error)

func (*Conn) GetACL

func (c *Conn) GetACL(path string) ([]ACL, *Stat, error)

func (*Conn) GetW

func (c *Conn) GetW(path string) ([]byte, *Stat, <-chan Event, error)

GetW returns the contents of a znode and sets a watch

func (*Conn) Multi

func (c *Conn) Multi(ops MultiOps) error

func (*Conn) Set

func (c *Conn) Set(path string, data []byte, version int32) (*Stat, error)

func (*Conn) SetACL

func (c *Conn) SetACL(path string, acl []ACL, version int32) (*Stat, error)

func (*Conn) State

func (c *Conn) State() State

func (*Conn) Sync

func (c *Conn) Sync(path string) (string, error)

type CreateRequest

type CreateRequest struct {
	Path  string
	Data  []byte
	Acl   []ACL
	Flags int32
}

type CreateType

type CreateType int32
const (
	CreatePersistent CreateType = 0 // Node remains after session expires
	CreateEphemeral  CreateType = 1 // Node deletes when the creator session expires
	CreateSequence   CreateType = 2 // Sequence number is appended to the node path
)

func (CreateType) String

func (c CreateType) String() string

type DeleteRequest

type DeleteRequest PathVersionRequest

type Dialer

type Dialer func(network, address string, timeout time.Duration) (net.Conn, error)

type ErrCode

type ErrCode int32

type Event

type Event struct {
	Type  EventType
	State State
	Path  string // For non-session events, the path of the watched node.
	Err   error
}

type EventType

type EventType int32

func (EventType) String

func (t EventType) String() string

type Lock

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

func NewLock

func NewLock(c *Conn, path string, acl []ACL) *Lock

func (*Lock) Lock

func (l *Lock) Lock() error

func (*Lock) Unlock

func (l *Lock) Unlock() error

type MultiOps

type MultiOps struct {
	Create  []CreateRequest
	Delete  []DeleteRequest
	SetData []SetDataRequest
	Check   []CheckVersionRequest
}

type PathVersionRequest

type PathVersionRequest struct {
	Path    string
	Version int32
}

type SetDataRequest

type SetDataRequest struct {
	Path    string
	Data    []byte
	Version int32
}

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

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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