Struct etcd_client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

Asynchronous etcd client using v3 API.

Implementations§

source§

impl Client

source

pub async fn connect<E: AsRef<str>, S: AsRef<[E]>>( endpoints: S, options: Option<ConnectOptions> ) -> Result<Self, Error>

Connect to etcd servers from given endpoints.

source

pub async fn add_endpoint<E: AsRef<str>>( &self, endpoint: E ) -> Result<(), Error>

Dynamically add an endpoint to the client.

Which can be used to add a new member to the underlying balance cache. The typical scenario is that application can use a services discovery to discover the member list changes and add/remove them to/from the client.

Note that the Client doesn’t check the authentication before added. So the etcd member of the added endpoint REQUIRES to use the same auth token as when create the client. Otherwise, the underlying balance services will not be able to connect to the new endpoint.

source

pub async fn remove_endpoint<E: AsRef<str>>( &self, endpoint: E ) -> Result<(), Error>

Dynamically remove an endpoint from the client.

Note that the endpoint str should be the same as it was added. And the underlying balance services cache used the hash from the Uri, which was parsed from endpoint str, to do the equality comparisons.

source

pub fn kv_client(&self) -> KvClient

Gets a KV client.

source

pub fn watch_client(&self) -> WatchClient

Gets a watch client.

source

pub fn lease_client(&self) -> LeaseClient

Gets a lease client.

source

pub fn auth_client(&self) -> AuthClient

Gets an auth client.

source

pub fn maintenance_client(&self) -> MaintenanceClient

Gets a maintenance client.

source

pub fn cluster_client(&self) -> ClusterClient

Gets a cluster client.

source

pub fn lock_client(&self) -> LockClient

Gets a lock client.

source

pub fn election_client(&self) -> ElectionClient

Gets a election client.

source

pub async fn put( &mut self, key: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>, options: Option<PutOptions> ) -> Result<PutResponse, Error>

Put the given key into the key-value store. A put request increments the revision of the key-value store and generates one event in the event history.

source

pub async fn get( &mut self, key: impl Into<Vec<u8>>, options: Option<GetOptions> ) -> Result<GetResponse, Error>

Gets the key from the key-value store.

source

pub async fn delete( &mut self, key: impl Into<Vec<u8>>, options: Option<DeleteOptions> ) -> Result<DeleteResponse, Error>

Deletes the given key from the key-value store.

source

pub async fn compact( &mut self, revision: i64, options: Option<CompactionOptions> ) -> Result<CompactionResponse, Error>

Compacts the event history in the etcd key-value store. The key-value store should be periodically compacted or the event history will continue to grow indefinitely.

source

pub async fn txn(&mut self, txn: Txn) -> Result<TxnResponse, Error>

Processes multiple operations in a single transaction. A txn request increments the revision of the key-value store and generates events with the same revision for every completed operation. It is not allowed to modify the same key several times within one txn.

source

pub async fn watch( &mut self, key: impl Into<Vec<u8>>, options: Option<WatchOptions> ) -> Result<(Watcher, WatchStream), Error>

Watches for events happening or that have happened. Both input and output are streams; the input stream is for creating and canceling watcher and the output stream sends events. The entire event history can be watched starting from the last compaction revision.

source

pub async fn lease_grant( &mut self, ttl: i64, options: Option<LeaseGrantOptions> ) -> Result<LeaseGrantResponse, Error>

Creates a lease which expires if the server does not receive a keepAlive within a given time to live period. All keys attached to the lease will be expired and deleted if the lease expires. Each expired key generates a delete event in the event history.

source

pub async fn lease_revoke( &mut self, id: i64 ) -> Result<LeaseRevokeResponse, Error>

Revokes a lease. All keys attached to the lease will expire and be deleted.

source

pub async fn lease_keep_alive( &mut self, id: i64 ) -> Result<(LeaseKeeper, LeaseKeepAliveStream), Error>

Keeps the lease alive by streaming keep alive requests from the client to the server and streaming keep alive responses from the server to the client.

source

pub async fn lease_time_to_live( &mut self, id: i64, options: Option<LeaseTimeToLiveOptions> ) -> Result<LeaseTimeToLiveResponse, Error>

Retrieves lease information.

source

pub async fn leases(&mut self) -> Result<LeaseLeasesResponse, Error>

Lists all existing leases.

source

pub async fn lock( &mut self, name: impl Into<Vec<u8>>, options: Option<LockOptions> ) -> Result<LockResponse, Error>

Lock acquires a distributed shared lock on a given named lock. On success, it will return a unique key that exists so long as the lock is held by the caller. This key can be used in conjunction with transactions to safely ensure updates to etcd only occur while holding lock ownership. The lock is held until Unlock is called on the key or the lease associate with the owner expires.

source

pub async fn unlock( &mut self, key: impl Into<Vec<u8>> ) -> Result<UnlockResponse, Error>

Unlock takes a key returned by Lock and releases the hold on lock. The next Lock caller waiting for the lock will then be woken up and given ownership of the lock.

source

pub async fn auth_enable(&mut self) -> Result<AuthEnableResponse, Error>

Enables authentication.

source

pub async fn auth_disable(&mut self) -> Result<AuthDisableResponse, Error>

Disables authentication.

source

pub async fn role_add( &mut self, name: impl Into<String> ) -> Result<RoleAddResponse, Error>

Adds role.

source

pub async fn role_delete( &mut self, name: impl Into<String> ) -> Result<RoleDeleteResponse, Error>

Deletes role.

source

pub async fn role_get( &mut self, name: impl Into<String> ) -> Result<RoleGetResponse, Error>

Gets role.

source

pub async fn role_list(&mut self) -> Result<RoleListResponse, Error>

Lists role.

source

pub async fn role_grant_permission( &mut self, name: impl Into<String>, perm: Permission ) -> Result<RoleGrantPermissionResponse, Error>

Grants role permission.

source

pub async fn role_revoke_permission( &mut self, name: impl Into<String>, key: impl Into<Vec<u8>>, options: Option<RoleRevokePermissionOptions> ) -> Result<RoleRevokePermissionResponse, Error>

Revokes role permission.

source

pub async fn user_add( &mut self, name: impl Into<String>, password: impl Into<String>, options: Option<UserAddOptions> ) -> Result<UserAddResponse, Error>

Add an user.

source

pub async fn user_get( &mut self, name: impl Into<String> ) -> Result<UserGetResponse, Error>

Gets the user info by the user name.

source

pub async fn user_list(&mut self) -> Result<UserListResponse, Error>

Lists all users.

source

pub async fn user_delete( &mut self, name: impl Into<String> ) -> Result<UserDeleteResponse, Error>

Deletes the given key from the key-value store.

source

pub async fn user_change_password( &mut self, name: impl Into<String>, password: impl Into<String> ) -> Result<UserChangePasswordResponse, Error>

Change password for an user.

source

pub async fn user_grant_role( &mut self, user: impl Into<String>, role: impl Into<String> ) -> Result<UserGrantRoleResponse, Error>

Grant role for an user.

source

pub async fn user_revoke_role( &mut self, user: impl Into<String>, role: impl Into<String> ) -> Result<UserRevokeRoleResponse, Error>

Revoke role for an user.

source

pub async fn alarm( &mut self, alarm_action: AlarmAction, alarm_type: AlarmType, options: Option<AlarmOptions> ) -> Result<AlarmResponse, Error>

Maintain(get, active or inactive) alarms of members.

source

pub async fn status(&mut self) -> Result<StatusResponse, Error>

Gets the status of a member.

source

pub async fn defragment(&mut self) -> Result<DefragmentResponse, Error>

Defragments a member’s backend database to recover storage space.

source

pub async fn hash(&mut self) -> Result<HashResponse, Error>

Computes the hash of whole backend keyspace. including key, lease, and other buckets in storage. This is designed for testing ONLY!

source

pub async fn hash_kv(&mut self, revision: i64) -> Result<HashKvResponse, Error>

Computes the hash of all MVCC keys up to a given revision. It only iterates "key" bucket in backend storage.

source

pub async fn snapshot(&mut self) -> Result<SnapshotStreaming, Error>

Gets a snapshot of the entire backend from a member over a stream to a client.

source

pub async fn member_add<E: AsRef<str>, S: AsRef<[E]>>( &mut self, urls: S, options: Option<MemberAddOptions> ) -> Result<MemberAddResponse, Error>

Adds current connected server as a member.

source

pub async fn member_remove( &mut self, id: u64 ) -> Result<MemberRemoveResponse, Error>

Remove a member.

source

pub async fn member_update( &mut self, id: u64, url: impl Into<Vec<String>> ) -> Result<MemberUpdateResponse, Error>

Updates the member.

source

pub async fn member_promote( &mut self, id: u64 ) -> Result<MemberPromoteResponse, Error>

Promotes the member.

source

pub async fn member_list(&mut self) -> Result<MemberListResponse, Error>

Lists members.

source

pub async fn move_leader( &mut self, target_id: u64 ) -> Result<MoveLeaderResponse, Error>

Moves the current leader node to target node.

source

pub async fn campaign( &mut self, name: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>, lease: i64 ) -> Result<CampaignResponse, Error>

Puts a value as eligible for the election on the prefix key. Multiple sessions can participate in the election for the same prefix, but only one can be the leader at a time.

source

pub async fn proclaim( &mut self, value: impl Into<Vec<u8>>, options: Option<ProclaimOptions> ) -> Result<ProclaimResponse, Error>

Lets the leader announce a new value without another election.

source

pub async fn leader( &mut self, name: impl Into<Vec<u8>> ) -> Result<LeaderResponse, Error>

Returns the leader value for the current election.

source

pub async fn observe( &mut self, name: impl Into<Vec<u8>> ) -> Result<ObserveStream, Error>

Returns a channel that reliably observes ordered leader proposals as GetResponse values on every current elected leader key.

source

pub async fn resign( &mut self, option: Option<ResignOptions> ) -> Result<ResignResponse, Error>

Releases election leadership and then start a new election

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

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

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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 Twhere 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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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