zookeeper/consts.rs
1use std::error::Error;
2use std::fmt;
3
4/// Basic type for errors returned from the server.
5#[derive(Clone, Copy, Debug, EnumConvertFromInt, EnumError, PartialEq)]
6#[EnumConvertFromIntFallback = "Unimplemented"]
7pub enum ZkError {
8 /// This code is never returned from the server. It should not be used other than to indicate a
9 /// range. Specifically error codes greater than this value are API errors (while values less
10 /// than this indicate a system error).
11 APIError = -100,
12 /// Client authentication failed.
13 AuthFailed = -115,
14 /// Invalid arguments.
15 BadArguments = -8,
16 /// Version conflict in `set` operation. In case of reconfiguration: reconfig requested from
17 /// config version X but last seen config has a different version Y.
18 BadVersion = -103,
19 /// Connection to the server has been lost.
20 ConnectionLoss = -4,
21 /// A data inconsistency was found.
22 DataInconsistency = -3,
23 /// Attempt to create ephemeral node on a local session.
24 EphemeralOnLocalSession = -120,
25 /// Invalid `Acl` specified.
26 InvalidACL = -114,
27 /// Invalid callback specified.
28 InvalidCallback = -113,
29 /// Error while marshalling or unmarshalling data.
30 MarshallingError = -5,
31 /// Not authenticated.
32 NoAuth = -102,
33 /// Ephemeral nodes may not have children.
34 NoChildrenForEphemerals = -108,
35 /// Request to create node that already exists.
36 NodeExists = -110,
37 /// Attempted to read a node that does not exist.
38 NoNode = -101,
39 /// The node has children.
40 NotEmpty = -111,
41 /// State-changing request is passed to read-only server.
42 NotReadOnly = -119,
43 /// Attempt to remove a non-existing watcher.
44 NoWatcher = -121,
45 /// Operation timeout.
46 OperationTimeout = -7,
47 /// A runtime inconsistency was found.
48 RuntimeInconsistency = -2,
49 /// The session has been expired by the server.
50 SessionExpired = -112,
51 /// Session moved to another server, so operation is ignored.
52 SessionMoved = -118,
53 /// System and server-side errors. This is never thrown by the server, it shouldn't be used
54 /// other than to indicate a range. Specifically error codes greater than this value, but lesser
55 /// than `APIError`, are system errors.
56 SystemError = -1,
57 /// Operation is unimplemented.
58 Unimplemented = -6
59}
60
61impl fmt::Display for ZkError {
62 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63 write!(f, "Zookeeper Error: {}", self.description())
64 }
65}
66
67/// CreateMode value determines how the znode is created on ZooKeeper.
68#[derive(Clone, Copy, Debug, PartialEq)]
69pub enum CreateMode {
70 /// The znode will not be automatically deleted upon client's disconnect.
71 Persistent = 0,
72 /// The znode will be deleted upon the client's disconnect.
73 Ephemeral = 1,
74 /// The name of the znode will be appended with a monotonically increasing number. The actual
75 /// path name of a sequential node will be the given path plus a suffix `"i"` where *i* is the
76 /// current sequential number of the node. The sequence number is always fixed length of 10
77 /// digits, 0 padded. Once such a node is created, the sequential number will be incremented by
78 /// one.
79 PersistentSequential = 2,
80 /// The znode will be deleted upon the client's disconnect, and its name will be appended with a
81 /// monotonically increasing number.
82 EphemeralSequential = 3,
83 /// Container nodes are special purpose nodes useful for recipes such as leader, lock, etc. When
84 /// the last child of a container is deleted, the container becomes a candidate to be deleted by
85 /// the server at some point in the future. Given this property, you should be prepared to get
86 /// `ZkError::NoNode` when creating children inside of this container node.
87 Container = 4,
88}
89
90/// Enumeration of states the client may be at a Watcher Event. It represents the state of the
91/// server at the time the event was generated.
92#[derive(Clone, Copy, Debug, EnumConvertFromInt, PartialEq)]
93pub enum KeeperState {
94 /// The client is in the disconnected state - it is not connected to any server in the ensemble.
95 Disconnected = 0,
96 /// The client is in the connected state - it is connected to a server in the ensemble (one of
97 /// the servers specified in the host connection parameter during ZooKeeper client creation).
98 SyncConnected = 3,
99 /// Authentication has failed -- connection requires a new `ZooKeeper` instance.
100 AuthFailed = 4,
101 /// The client is connected to a read-only server, that is the server which is not currently
102 /// connected to the majority. The only operations allowed after receiving this state is read
103 /// operations. This state is generated for read-only clients only since read/write clients
104 /// aren't allowed to connect to read-only servers.
105 ConnectedReadOnly = 5,
106 /// Used to notify clients that they are SASL-authenticated, so that they can perform ZooKeeper
107 /// actions with their SASL-authorized permissions.
108 SaslAuthenticated = 6,
109 /// The serving cluster has expired this session. The ZooKeeper client connection (the session)
110 /// is no longer valid. You must create a new client connection (instantiate a new `ZooKeeper`
111 /// instance) if you with to access the ensemble.
112 Expired = -112
113}
114
115/// Enumeration of types of events that may occur on the znode.
116#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumConvertFromInt)]
117pub enum WatchedEventType {
118 /// Nothing known has occurred on the znode. This value is issued as part of a `WatchedEvent`
119 /// when the `KeeperState` changes.
120 None = -1,
121 /// Issued when a znode at a given path is created.
122 NodeCreated = 1,
123 /// Issued when a znode at a given path is deleted.
124 NodeDeleted = 2,
125 /// Issued when the data of a watched znode are altered. This event value is issued whenever a
126 /// *set* operation occurs without an actual contents check, so there is no guarantee the data
127 /// actually changed.
128 NodeDataChanged = 3,
129 /// Issued when the children of a watched znode are created or deleted. This event is not issued
130 /// when the data within children is altered.
131 NodeChildrenChanged = 4,
132 /// Issued when the client removes a data watcher.
133 DataWatchRemoved = 5,
134 /// Issued when the client removes a child watcher.
135 ChildWatchRemoved = 6
136}
137
138/// The mode of watch.
139#[derive(Clone, Copy, Debug, EnumConvertFromInt)]
140pub enum AddWatchMode {
141 /// Set a watcher on the given path that does not get removed when triggered (i.e. it stays active
142 /// until it is removed). This watcher
143 /// is triggered for both data and child events. To remove the watcher, use
144 /// remove_watches. The watcher behaves as if you placed an exists() watch and
145 /// a get_data() watch on the ZNode at the given path.
146 /// Requires Zookeeper 3.6.0
147 Persistent = 0,
148 /// Like a Persistent watcher but applies not only to the registered path but all child
149 /// paths recursively. This watcher is triggered for both data and child events.
150 /// To remove the watcher, use remove_watches().
151 /// Requires Zookeeper 3.6.0
152 PersistentRecursive = 1,
153}
154
155/// The type of watcher.
156#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumConvertFromInt)]
157pub enum WatcherType {
158 Children = 1,
159 Data = 2,
160 Any = 3,
161 Persistent = 4,
162 PersistentRecursive = 5,
163}
164
165impl From<AddWatchMode> for WatcherType {
166 fn from(watch_mode: AddWatchMode) -> Self {
167 match watch_mode {
168 AddWatchMode::Persistent => Self::Persistent,
169 AddWatchMode::PersistentRecursive => Self::PersistentRecursive,
170 }
171 }
172}
173
174impl WatcherType {
175 pub fn is_persistent(&self) -> bool {
176 self == &Self::Persistent || self == &Self::PersistentRecursive
177 }
178}
179
180/// Enumeration of states the client may be at any time.
181#[derive(Clone, Copy, Debug, PartialEq)]
182pub enum ZkState {
183 /// Previously used to represent a state between connection (as in connected to a server) and
184 /// authenticated. This is no longer used.
185 #[deprecated]
186 Associating,
187 /// Authentication has failed. Operations will return `ZkError::AuthFailed`.
188 AuthFailed,
189 /// The session has ended. Operations will return `ZkError::SessionExpired`.
190 Closed,
191 /// Session has been fully established. Operations will proceed as normal.
192 Connected,
193 /// Connected to a read-only server. See `KeeperState::ConnectedReadOnly`.
194 ConnectedReadOnly,
195 /// Currently attempting to connect with an ensemble member. Operations are queued until a
196 /// session is established.
197 Connecting,
198 /// Theoretically used as a special state to represent `ZkError::ConnectionLoss` for expected
199 /// reasons (ensemble reconfiguration), but `Closed` has proven less error-prone. This is no
200 /// longer used.
201 #[deprecated]
202 NotConnected,
203}