Struct tokio_zookeeper::ZooKeeper

source ·
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

source

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.

See ZooKeeperBuilder::connect.

source

pub async fn create<D, A>( &self, path: &str, data: D, acl: A, mode: CreateMode ) -> Result<Result<String, Create>, Error>
where D: Into<Cow<'static, [u8]>>, A: Into<Cow<'static, [Acl]>>,

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).

source

pub async fn set_data<D>( &self, path: &str, version: Option<i32>, data: D ) -> Result<Result<Stat, SetData>, Error>
where D: Into<Cow<'static, [u8]>>,

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).

source

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.

source

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.

source

pub async fn set_acl<A>( &self, path: &str, acl: A, version: Option<i32> ) -> Result<Result<Stat, SetAcl>, Error>
where A: Into<Cow<'static, [Acl]>>,

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

source

pub fn watch(&self) -> WatchGlobally<'_>

Add a global watch for the next chained operation.

source

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.

source

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.

source

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.

source

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.

source

pub fn multi(&self) -> MultiBuilder<'_>

Start building a multi request. Multi requests batch several operations into one atomic unit.

Trait Implementations§

source§

impl Clone for ZooKeeper

source§

fn clone(&self) -> ZooKeeper

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ZooKeeper

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more