pub struct EmbeddedClient { /* private fields */ }Expand description
Zero-overhead KV client for embedded mode.
Directly calls Raft core without gRPC overhead.
Implementations§
Source§impl EmbeddedClient
impl EmbeddedClient
Sourcepub async fn put(
&self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<(), ClientApiError>
pub async fn put( &self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<(), ClientApiError>
Store a key-value pair with strong consistency.
Sourcepub async fn get_linearizable(
&self,
key: impl AsRef<[u8]>,
) -> Result<Option<Bytes>, ClientApiError>
pub async fn get_linearizable( &self, key: impl AsRef<[u8]>, ) -> Result<Option<Bytes>, ClientApiError>
Strongly consistent read (linearizable).
Guarantees reading the latest committed value by querying the Leader. Use for critical reads where staleness is unacceptable.
§Performance
- Latency: ~1-5ms (network RTT to Leader)
- Throughput: Limited by Leader capacity
§Raft Protocol
Implements linearizable read per Raft §8.
§Example
let client = engine.client();
let value = client.get_linearizable(b"critical-config").await?;Sourcepub async fn get_eventual(
&self,
key: impl AsRef<[u8]>,
) -> Result<Option<Bytes>, ClientApiError>
pub async fn get_eventual( &self, key: impl AsRef<[u8]>, ) -> Result<Option<Bytes>, ClientApiError>
Eventually consistent read (stale OK).
Reads from local state machine without Leader coordination. Fast but may return stale data if replication is lagging.
§Performance
- Latency: ~0.1ms (local memory access)
- Throughput: High (no Leader bottleneck)
§Use Cases
- Read-heavy workloads
- Analytics/reporting (staleness acceptable)
- Caching scenarios
§Example
let client = engine.client();
let cached_value = client.get_eventual(b"user-preference").await?;Sourcepub async fn get_with_consistency(
&self,
key: impl AsRef<[u8]>,
consistency: ReadConsistencyPolicy,
) -> Result<Option<Bytes>, ClientApiError>
pub async fn get_with_consistency( &self, key: impl AsRef<[u8]>, consistency: ReadConsistencyPolicy, ) -> Result<Option<Bytes>, ClientApiError>
Advanced: Read with explicit consistency policy.
For fine-grained control over read consistency vs performance trade-off.
§Consistency Policies
LinearizableRead: Read from Leader (strong consistency, may be slower)EventualConsistency: Read from local node (fast, may be stale)LeaseRead: Optimized Leader read using lease mechanism
§Example
use d_engine_proto::client::ReadConsistencyPolicy;
let value = client.get_with_consistency(
b"key",
ReadConsistencyPolicy::LeaseRead,
).await?;Sourcepub async fn get_multi_linearizable(
&self,
keys: &[Bytes],
) -> Result<Vec<Option<Bytes>>, ClientApiError>
pub async fn get_multi_linearizable( &self, keys: &[Bytes], ) -> Result<Vec<Option<Bytes>>, ClientApiError>
Sourcepub async fn get_multi_eventual(
&self,
keys: &[Bytes],
) -> Result<Vec<Option<Bytes>>, ClientApiError>
pub async fn get_multi_eventual( &self, keys: &[Bytes], ) -> Result<Vec<Option<Bytes>>, ClientApiError>
Sourcepub async fn get_multi_with_consistency(
&self,
keys: &[Bytes],
consistency: ReadConsistencyPolicy,
) -> Result<Vec<Option<Bytes>>, ClientApiError>
pub async fn get_multi_with_consistency( &self, keys: &[Bytes], consistency: ReadConsistencyPolicy, ) -> Result<Vec<Option<Bytes>>, ClientApiError>
Advanced: Get multiple keys with explicit consistency policy.
Sourcepub async fn delete(&self, key: impl AsRef<[u8]>) -> Result<(), ClientApiError>
pub async fn delete(&self, key: impl AsRef<[u8]>) -> Result<(), ClientApiError>
Delete a key-value pair.
Sourcepub fn watch(
&self,
key: impl AsRef<[u8]>,
) -> Result<WatcherHandle, ClientApiError>
pub fn watch( &self, key: impl AsRef<[u8]>, ) -> Result<WatcherHandle, ClientApiError>
Watch for changes to a specific key
Returns a WatcherHandle that yields watch events when the key’s value changes.
The stream will continue until explicitly dropped or a connection error occurs.
§Arguments
key- The key to watch
§Returns
A WatcherHandle that can be used to receive watch events
§Errors
Returns error if watch feature is not enabled or WatchRegistry not initialized
§Example
let client = engine.client();
let mut watcher = client.watch(b"config/timeout").await?;
while let Some(event) = watcher.next().await {
println!("Value changed: {:?}", event);
}Trait Implementations§
Source§impl ClientApi for EmbeddedClient
impl ClientApi for EmbeddedClient
Source§fn put<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
value: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<(), ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn put<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
value: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<(), ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn put_with_ttl<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
value: impl AsRef<[u8]> + Send + 'async_trait,
ttl_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<(), ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn put_with_ttl<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
value: impl AsRef<[u8]> + Send + 'async_trait,
ttl_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<(), ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn get<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get_multi<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Bytes],
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Bytes>>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
EmbeddedClient: 'async_trait,
fn get_multi<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Bytes],
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Bytes>>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn delete<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<(), ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn delete<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<(), ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn compare_and_swap<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
expected_value: Option<impl AsRef<[u8]> + Send + 'async_trait>,
new_value: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<bool, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn compare_and_swap<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
expected_value: Option<impl AsRef<[u8]> + Send + 'async_trait>,
new_value: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<bool, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn list_members<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<NodeMeta>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn list_members<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<NodeMeta>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get_leader_id<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<u32>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn get_leader_id<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<u32>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get_multi_with_policy<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Bytes],
consistency_policy: Option<ReadConsistencyPolicy>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Bytes>>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
EmbeddedClient: 'async_trait,
fn get_multi_with_policy<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Bytes],
consistency_policy: Option<ReadConsistencyPolicy>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Bytes>>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get_linearizable<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn get_linearizable<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get_lease<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn get_lease<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§fn get_eventual<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
fn get_eventual<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, ClientApiError>> + Send + 'async_trait>>where
'life0: 'async_trait,
EmbeddedClient: 'async_trait,
Source§impl Clone for EmbeddedClient
impl Clone for EmbeddedClient
Source§fn clone(&self) -> EmbeddedClient
fn clone(&self) -> EmbeddedClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EmbeddedClient
impl !RefUnwindSafe for EmbeddedClient
impl Send for EmbeddedClient
impl Sync for EmbeddedClient
impl Unpin for EmbeddedClient
impl UnsafeUnpin for EmbeddedClient
impl !UnwindSafe for EmbeddedClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request