This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
/
constants.go
151 lines (128 loc) · 4.17 KB
/
constants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2016 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package zetcd
import (
"errors"
)
const (
DefaultPort = 2181
)
const (
opCreate = 1
opDelete = 2
opExists = 3
opGetData = 4
opSetData = 5
opGetAcl = 6
opSetAcl = 7
opGetChildren = 8
opSync = 9
opPing = 11
opGetChildren2 = 12
opCheck = 13
opMulti = 14
opClose = -11
opSetAuth = 100
opSetWatches = 101
// Not in protocol, used internally
opInvalid = -100000
)
type EventType int32
const (
EventNodeCreated EventType = iota + 1
EventNodeDeleted
EventNodeDataChanged
EventNodeChildrenChanged
EventSession = EventType(-1)
EventNotWatching = EventType(-2)
)
const (
FlagEphemeral = 1
FlagSequence = 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)
// StateAuthFailed = State(-113)
StateConnected = State(100)
StateHasSession = State(101)
)
type State int32
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")
ErrBadArguments = errors.New("zk: bad arguments")
errorToErrCode = map[error]ErrCode{
ErrBadArguments: errBadArguments,
ErrNoNode: errNoNode,
ErrNodeExists: errNodeExists,
ErrInvalidACL: errInvalidAcl,
ErrBadVersion: errBadVersion,
ErrAPIError: errAPIError,
ErrNotEmpty: errNotEmpty,
}
)
type ErrCode int32
const (
errOk ErrCode = 0
// System and server-side errors
errSystemError = ErrCode(-1)
// errRuntimeInconsistency = ErrCode(-2)
// errDataInconsistency = ErrCode(-3)
// errConnectionLoss = ErrCode(-4)
// errMarshallingError = ErrCode(-5)
// errUnimplemented = ErrCode(-6)
// errOperationTimeout = ErrCode(-7)
errBadArguments = ErrCode(-8)
// errInvalidState = ErrCode(-9)
// API errors
errAPIError = ErrCode(-100)
errNoNode = ErrCode(-101) // *
// errNoAuth = ErrCode(-102)
errBadVersion = ErrCode(-103) // *
// errNoChildrenForEphemerals = ErrCode(-108)
errNodeExists = ErrCode(-110) // *
errNotEmpty = ErrCode(-111)
// errSessionExpired = ErrCode(-112)
// errInvalidCallback = ErrCode(-113)
errInvalidAcl = ErrCode(-114)
// errAuthFailed = ErrCode(-115)
// errClosing = ErrCode(-116)
// errNothing = ErrCode(-117)
// errSessionMoved = ErrCode(-118)
)
// four letter word commands / responses
const (
flwRUOK = "ruok"
flwIMOK = "imok"
)