pub struct ZooKeeper { /* private fields */ }
Expand description
A connection to ZooKeeper.
All interactions with ZooKeeper are performed by calling the methods of a ZooKeeper
instance.
All clones of the same ZooKeeper
instance use the same underlying connection. Once a
connection to a server is established, a session ID is assigned to the client. The client will
send heart beats to the server periodically to keep the session valid.
The application can call ZooKeeper APIs through a client as long as the session ID of the
client remains valid. If for some reason, the client fails to send heart beats to the server
for a prolonged period of time (exceeding the session timeout value, for instance), the server
will expire the session, and the session ID will become invalid. The ZooKeeper
instance will
then no longer be usable, and all futures will resolve with a protocol-level error. To make
further ZooKeeper API calls, the application must create a new ZooKeeper
instance.
If the ZooKeeper server the client currently connects to fails or otherwise does not respond, the client will automatically try to connect to another server before its session ID expires. If successful, the application can continue to use the client.
Some successful ZooKeeper API calls can leave watches on the “data nodes” in the ZooKeeper server. Other successful ZooKeeper API calls can trigger those watches. Once a watch is triggered, an event will be delivered to the client which left the watch at the first place. Each watch can be triggered only once. Thus, up to one event will be delivered to a client for every watch it leaves.
Implementations§
Source§impl ZooKeeper
impl ZooKeeper
Sourcepub async fn connect(
addr: &SocketAddr,
) -> Result<(Self, impl Stream<Item = WatchedEvent>), Error>
pub async fn connect( addr: &SocketAddr, ) -> Result<(Self, impl Stream<Item = WatchedEvent>), Error>
Connect to a ZooKeeper server instance at the given address with default parameters.
Sourcepub async fn create<D, A>(
&self,
path: &str,
data: D,
acl: A,
mode: CreateMode,
) -> Result<Result<String, Create>, Error>
pub async fn create<D, A>( &self, path: &str, data: D, acl: A, mode: CreateMode, ) -> Result<Result<String, Create>, Error>
Create a node with the given path
with data
as its contents.
The mode
argument specifies additional options for the newly created node.
If mode
is set to CreateMode::Ephemeral
(or CreateMode::EphemeralSequential
), the
node will be removed by the ZooKeeper automatically when the session associated with the
creation of the node expires.
If mode
is set to CreateMode::PersistentSequential
or
CreateMode::EphemeralSequential
, the actual path name of a sequential node will be the
given path
plus a suffix i
where i
is the current sequential number of the node. The
sequence number is always fixed length of 10 digits, 0 padded. Once such a node is created,
the sequential number will be incremented by one. The newly created node’s full name is
returned when the future is resolved.
If a node with the same actual path already exists in the ZooKeeper, the returned future
resolves with an error of error::Create::NodeExists
. Note that since a different actual
path is used for each invocation of creating sequential nodes with the same path
argument, calls with sequential modes will never return NodeExists
.
Ephemeral nodes cannot have children in ZooKeeper. Therefore, if the parent node of the
given path
is ephemeral, the return future resolves to
error::Create::NoChildrenForEphemerals
.
If a node is created successfully, the ZooKeeper server will trigger the watches on the
path
left by exists
calls, and the watches on the parent of the node by get_children
calls.
The maximum allowable size of the data array is 1 MB (1,048,576 bytes).
Sourcepub async fn set_data<D>(
&self,
path: &str,
version: Option<i32>,
data: D,
) -> Result<Result<Stat, SetData>, Error>
pub async fn set_data<D>( &self, path: &str, version: Option<i32>, data: D, ) -> Result<Result<Stat, SetData>, Error>
Set the data for the node at the given path
.
The call will succeed if such a node exists, and the given version
matches the version of
the node (if the given version
is None
, it matches any version). On success, the
updated Stat
of the node is returned.
This operation, if successful, will trigger all the watches on the node of the given path
left by get_data
calls.
The maximum allowable size of the data array is 1 MB (1,048,576 bytes).
Sourcepub async fn delete(
&self,
path: &str,
version: Option<i32>,
) -> Result<Result<(), Delete>, Error>
pub async fn delete( &self, path: &str, version: Option<i32>, ) -> Result<Result<(), Delete>, Error>
Delete the node at the given path
.
The call will succeed if such a node exists, and the given version
matches the node’s
version (if the given version
is None
, it matches any versions).
This operation, if successful, will trigger all the watches on the node of the given path
left by exists
API calls, and the watches on the parent node left by get_children
API
calls.
Sourcepub async fn get_acl(
&self,
path: &str,
) -> Result<Result<(Vec<Acl>, Stat), GetAcl>, Error>
pub async fn get_acl( &self, path: &str, ) -> Result<Result<(Vec<Acl>, Stat), GetAcl>, Error>
Return the ACL
and Stat of the node at the given path
.
If no node exists for the given path, the returned future resolves with an error of
error::GetAcl::NoNode
.
Sourcepub async fn set_acl<A>(
&self,
path: &str,
acl: A,
version: Option<i32>,
) -> Result<Result<Stat, SetAcl>, Error>
pub async fn set_acl<A>( &self, path: &str, acl: A, version: Option<i32>, ) -> Result<Result<Stat, SetAcl>, Error>
Set the ACL
for the node of the given path
.
The call will succeed if such a node exists and the given version
matches the ACL version
of the node. On success, the updated Stat
of the node is returned.
If no node exists for the given path, the returned future resolves with an error of
error::SetAcl::NoNode
. If the given version
does not match the ACL version, the
returned future resolves with an error of error::SetAcl::BadVersion
.
Source§impl ZooKeeper
impl ZooKeeper
Sourcepub fn watch(&self) -> WatchGlobally<'_>
pub fn watch(&self) -> WatchGlobally<'_>
Add a global watch for the next chained operation.
Sourcepub fn with_watcher(&self) -> WithWatcher<'_>
pub fn with_watcher(&self) -> WithWatcher<'_>
Add a watch for the next chained operation, and return a future for any received event along with the operation’s (successful) result.
Sourcepub async fn exists(&self, path: &str) -> Result<Option<Stat>, Error>
pub async fn exists(&self, path: &str) -> Result<Option<Stat>, Error>
Return the Stat
of the node of the given path
, or None
if the node does not exist.
Sourcepub async fn get_children(
&self,
path: &str,
) -> Result<Option<Vec<String>>, Error>
pub async fn get_children( &self, path: &str, ) -> Result<Option<Vec<String>>, Error>
Return the names of the children of the node at the given path
, or None
if the node
does not exist.
The returned list of children is not sorted and no guarantee is provided as to its natural or lexical order.
Sourcepub async fn get_data(
&self,
path: &str,
) -> Result<Option<(Vec<u8>, Stat)>, Error>
pub async fn get_data( &self, path: &str, ) -> Result<Option<(Vec<u8>, Stat)>, Error>
Return the data and the Stat
of the node at the given path
, or None
if it does not
exist.
Sourcepub fn multi(&self) -> MultiBuilder<'_>
pub fn multi(&self) -> MultiBuilder<'_>
Start building a multi request. Multi requests batch several operations into one atomic unit.