zk

package
v0.0.0-...-9c3719e Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2015 License: BSD-3-Clause Imports: 21 Imported by: 111

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

Constants for ACL permissions

View Source
const (
	DefaultServerTickTime                 = 2000
	DefaultServerInitLimit                = 10
	DefaultServerSyncLimit                = 5
	DefaultServerAutoPurgeSnapRetainCount = 3
	DefaultPeerPort                       = 2888
	DefaultLeaderElectionPort             = 3888
)
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 int32, 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 DeleteRequest

type DeleteRequest PathVersionRequest

type Dialer

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

type ErrCode

type ErrCode int32

type ErrMissingServerConfigField

type ErrMissingServerConfigField string

func (ErrMissingServerConfigField) Error

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 Server

type Server struct {
	JarPath    string
	ConfigPath string
	// contains filtered or unexported fields
}

func (*Server) Start

func (srv *Server) Start() error

func (*Server) Stop

func (srv *Server) Stop() error

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
}

func (ServerConfig) Marshall

func (sc ServerConfig) Marshall(w io.Writer) error

type ServerConfigServer

type ServerConfigServer struct {
	ID                 int
	Host               string
	PeerPort           int
	LeaderElectionPort int
}

type SetDataRequest

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

type Stat

type Stat interface {
	Czxid() int64
	Mzxid() int64
	CTime() time.Time
	MTime() time.Time
	Version() int
	CVersion() int
	AVersion() int
	EphemeralOwner() int64
	DataLength() int
	NumChildren() int
	Pzxid() int64
}

type State

type State int32

func (State) String

func (s State) String() string

type TestCluster

type TestCluster struct {
	Path    string
	Servers []TestServer
}

func StartTestCluster

func StartTestCluster(size int) (*TestCluster, error)

func (*TestCluster) Connect

func (ts *TestCluster) Connect(idx int) (*Conn, error)

func (*TestCluster) ConnectAll

func (ts *TestCluster) ConnectAll() (*Conn, error)

func (*TestCluster) Stop

func (ts *TestCluster) Stop() error

type TestServer

type TestServer struct {
	Port int
	Path string
	Srv  *Server
}

Jump to

Keyboard shortcuts

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