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