Struct zookeeper_client::Client
source · [−]pub struct Client { /* private fields */ }
Expand description
Client encapsulates ZooKeeper session to interact with ZooKeeper cluster.
Besides semantic errors, node operations could also fail due to cluster availability and limitations, e.g. Error::ConnectionLoss, Error::QuotaExceeded and so on.
All remote operations will fail after session expired, failed or closed.
Notable behaviors
- All cloned clients share same authentication identities.
Implementations
sourceimpl Client
impl Client
sourcepub async fn connect(
cluster: &str,
timeout: Duration
) -> Result<Client, ConnectError>
pub async fn connect(
cluster: &str,
timeout: Duration
) -> Result<Client, ConnectError>
Connects to ZooKeeper cluster with specified session timeout.
sourcepub fn session_id(&self) -> SessionId
pub fn session_id(&self) -> SessionId
ZooKeeper session id.
sourcepub fn session_password(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
pub fn session_password(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
Session password.
sourcepub fn session_timeout(&self) -> Duration
pub fn session_timeout(&self) -> Duration
Negotiated session timeout.
sourcepub fn state(&self) -> SessionState
pub fn state(&self) -> SessionState
Latest session state.
sourcepub fn state_watcher(&self) -> StateWatcher
pub fn state_watcher(&self) -> StateWatcher
Creates a StateWatcher to track state updates.
sourcepub fn chroot(self, root: &str) -> Result<Client, Client>
pub fn chroot(self, root: &str) -> Result<Client, Client>
Changes root directory to given absolute path.
Errors
In case of bad root path, old client is wrapped in Result::Err.
Notable behaviors
- Existing watchers are not affected.
sourcepub async fn create(
&self,
path: &str,
data: &[u8],
options: &CreateOptions<'_>
) -> Result<(Stat, CreateSequence), Error>
pub async fn create(
&self,
path: &str,
data: &[u8],
options: &CreateOptions<'_>
) -> Result<(Stat, CreateSequence), Error>
Creates node with given path and data.
Notable errors
- Error::NodeExists if a node with same path already exists.
- Error::NoNode if parent node does not exist.
- Error::NoChildrenForEphemerals if parent node is ephemeral.
- Error::InvalidAcl if acl is invalid or empty.
sourcepub async fn delete(
&self,
path: &str,
expected_version: Option<i32>
) -> Result<(), Error>
pub async fn delete(
&self,
path: &str,
expected_version: Option<i32>
) -> Result<(), Error>
Deletes node with specified path.
Notable errors
- Error::NoNode if such node does not exist.
- Error::BadVersion if such node exists but has different version.
- Error::NotEmpty if such node exists but has children.
sourcepub async fn get_data(&self, path: &str) -> Result<(Vec<u8>, Stat), Error>
pub async fn get_data(&self, path: &str) -> Result<(Vec<u8>, Stat), Error>
Gets stat and data for node with given path.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn get_and_watch_data(
&self,
path: &str
) -> Result<(Vec<u8>, Stat, OneshotWatcher), Error>
pub async fn get_and_watch_data(
&self,
path: &str
) -> Result<(Vec<u8>, Stat, OneshotWatcher), Error>
Gets stat and data for node with given path, and watches node deletion and data change.
The watch will be triggered by:
- Data change.
- Node deletion.
- Session expiration.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn check_stat(&self, path: &str) -> Result<Option<Stat>, Error>
pub async fn check_stat(&self, path: &str) -> Result<Option<Stat>, Error>
Checks stat for node with given path.
sourcepub async fn check_and_watch_stat(
&self,
path: &str
) -> Result<(Option<Stat>, OneshotWatcher), Error>
pub async fn check_and_watch_stat(
&self,
path: &str
) -> Result<(Option<Stat>, OneshotWatcher), Error>
Checks stat for node with given path, and watches node creation, deletion and data change.
The watch will be triggered by:
- Data change.
- Node creation and deletion.
- Session expiration.
sourcepub async fn set_data(
&self,
path: &str,
data: &[u8],
expected_version: Option<i32>
) -> Result<Stat, Error>
pub async fn set_data(
&self,
path: &str,
data: &[u8],
expected_version: Option<i32>
) -> Result<Stat, Error>
Sets data for node with given path and returns updated stat.
Notable errors
- Error::NoNode if such node does not exist.
- Error::BadVersion if such node exists but has different version.
sourcepub async fn list_and_watch_children(
&self,
path: &str
) -> Result<(Vec<String>, OneshotWatcher), Error>
pub async fn list_and_watch_children(
&self,
path: &str
) -> Result<(Vec<String>, OneshotWatcher), Error>
Lists children for node with given path, and watches node deletion, children creation and deletion.
The watch will be triggered by:
- Children creation and deletion.
- Node deletion.
- Session expiration.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn get_children(
&self,
path: &str
) -> Result<(Vec<String>, Stat), Error>
pub async fn get_children(
&self,
path: &str
) -> Result<(Vec<String>, Stat), Error>
Gets stat and children for node with given path.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn get_and_watch_children(
&self,
path: &str
) -> Result<(Vec<String>, Stat, OneshotWatcher), Error>
pub async fn get_and_watch_children(
&self,
path: &str
) -> Result<(Vec<String>, Stat, OneshotWatcher), Error>
Gets stat and children for node with given path, and watches node deletion, children creation and deletion.
The watch will be triggered by:
- Children creation and deletion.
- Node deletion.
- Session expiration.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn count_descendants_number(&self, path: &str) -> Result<usize, Error>
pub async fn count_descendants_number(&self, path: &str) -> Result<usize, Error>
Counts descendants number for node with given path.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn list_ephemerals(&self, path: &str) -> Result<Vec<String>, Error>
pub async fn list_ephemerals(&self, path: &str) -> Result<Vec<String>, Error>
Lists all ephemerals nodes that created by current session and starts with given path.
Notable behaviors
- No Error::NoNode if node with give path does not exist.
- Result will include given path if that node is ephemeral.
- Returned paths are located at chroot but not ZooKeeper root.
sourcepub async fn get_acl(&self, path: &str) -> Result<(Vec<Acl>, Stat), Error>
pub async fn get_acl(&self, path: &str) -> Result<(Vec<Acl>, Stat), Error>
Gets acl and stat for node with given path.
Notable errors
- Error::NoNode if such node does not exist.
sourcepub async fn set_acl(
&self,
path: &str,
acl: &[Acl],
expected_acl_version: Option<i32>
) -> Result<Stat, Error>
pub async fn set_acl(
&self,
path: &str,
acl: &[Acl],
expected_acl_version: Option<i32>
) -> Result<Stat, Error>
Sets acl for node with given path and returns updated stat.
Notable errors
- Error::NoNode if such node does not exist.
- Error::BadVersion if such node exists but has different acl version.
sourcepub async fn watch(
&self,
path: &str,
mode: AddWatchMode
) -> Result<PersistentWatcher, Error>
pub async fn watch(
&self,
path: &str,
mode: AddWatchMode
) -> Result<PersistentWatcher, Error>
Watches possible nonexistent path using specified mode.
The watch will be triggered by:
- Data change, children creation and deletion.
- Session activities.
Cautions
- Holds returned watcher without polling events may result in memory burst.
- See ZOOKEEPER-4466 for interferences among different watch modes for same path or paths with parent-child relationship.
sourcepub async fn sync(&self, path: &str) -> Result<(), Error>
pub async fn sync(&self, path: &str) -> Result<(), Error>
Syncs with ZooKeeper leader.
Cautions
sync + read
could not guarantee linearizable semantics as sync
is not quorum acked and
leader could change in between.
See ZOOKEEPER-1675 and ZOOKEEPER-2136 for reference.
sourcepub async fn auth(&self, scheme: String, auth: Vec<u8>) -> Result<(), Error>
pub async fn auth(&self, scheme: String, auth: Vec<u8>) -> Result<(), Error>
Authenticates session using given scheme and auth identication.
Errors
- Error::AuthFailed if authentication failed.
- Other terminal session errors.
Notable behaviors
- Same auth will be resubmitted for authentication after session reestablished.
- This method is resistent to temporary session unavailability, that means SessionState::Disconnected will not end authentication.
sourcepub async fn list_auth_users(&self) -> Result<Vec<AuthUser>, Error>
pub async fn list_auth_users(&self) -> Result<Vec<AuthUser>, Error>
Gets all authentication informations attached to current session.
Requirements
- ZooKeeper 3.7.0 and above
References
- ZOOKEEPER-3969 Add whoami API and Cli command.
sourcepub async fn get_config(&self) -> Result<(Vec<u8>, Stat), Error>
pub async fn get_config(&self) -> Result<(Vec<u8>, Stat), Error>
Gets data for ZooKeeper config node, that is node with path “/zookeeper/config”.
sourcepub async fn get_and_watch_config(
&self
) -> Result<(Vec<u8>, Stat, OneshotWatcher), Error>
pub async fn get_and_watch_config(
&self
) -> Result<(Vec<u8>, Stat, OneshotWatcher), Error>
Gets stat and data for ZooKeeper config node, that is node with path “/zookeeper/config”.
sourcepub async fn update_ensemble<'a, I: Iterator<Item = &'a str> + Clone>(
&self,
update: EnsembleUpdate<'a, I>,
expected_version: Option<i32>
) -> Result<(Vec<u8>, Stat), Error>
pub async fn update_ensemble<'a, I: Iterator<Item = &'a str> + Clone>(
&self,
update: EnsembleUpdate<'a, I>,
expected_version: Option<i32>
) -> Result<(Vec<u8>, Stat), Error>
Updates ZooKeeper ensemble.
Notable errors
- Error::ReconfigDisabled if ZooKeeper reconfiguration is disabled.
References
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more