pub struct LocalKvClient { /* private fields */ }Expand description
Zero-overhead KV client for embedded mode.
Directly calls Raft core without gRPC overhead.
Implementations§
Source§impl LocalKvClient
impl LocalKvClient
Sourcepub async fn put(
&self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<(), LocalClientError>
pub async fn put( &self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<(), LocalClientError>
Store a key-value pair with strong consistency.
Sourcepub async fn get_linearizable(
&self,
key: impl AsRef<[u8]>,
) -> Result<Option<Bytes>, LocalClientError>
pub async fn get_linearizable( &self, key: impl AsRef<[u8]>, ) -> Result<Option<Bytes>, LocalClientError>
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 = node.local_client();
let value = client.get_linearizable(b"critical-config").await?;Sourcepub async fn get_eventual(
&self,
key: impl AsRef<[u8]>,
) -> Result<Option<Bytes>, LocalClientError>
pub async fn get_eventual( &self, key: impl AsRef<[u8]>, ) -> Result<Option<Bytes>, LocalClientError>
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 = node.local_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>, LocalClientError>
pub async fn get_with_consistency( &self, key: impl AsRef<[u8]>, consistency: ReadConsistencyPolicy, ) -> Result<Option<Bytes>, LocalClientError>
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>>, LocalClientError>
pub async fn get_multi_linearizable( &self, keys: &[Bytes], ) -> Result<Vec<Option<Bytes>>, LocalClientError>
Sourcepub async fn get_multi_eventual(
&self,
keys: &[Bytes],
) -> Result<Vec<Option<Bytes>>, LocalClientError>
pub async fn get_multi_eventual( &self, keys: &[Bytes], ) -> Result<Vec<Option<Bytes>>, LocalClientError>
Sourcepub async fn get_multi_with_consistency(
&self,
keys: &[Bytes],
consistency: ReadConsistencyPolicy,
) -> Result<Vec<Option<Bytes>>, LocalClientError>
pub async fn get_multi_with_consistency( &self, keys: &[Bytes], consistency: ReadConsistencyPolicy, ) -> Result<Vec<Option<Bytes>>, LocalClientError>
Advanced: Get multiple keys with explicit consistency policy.
Trait Implementations§
Source§impl Clone for LocalKvClient
impl Clone for LocalKvClient
Source§fn clone(&self) -> LocalKvClient
fn clone(&self) -> LocalKvClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LocalKvClient
impl Debug for LocalKvClient
Source§impl KvClient for LocalKvClient
impl KvClient for LocalKvClient
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<(), KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalKvClient: '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<(), KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalKvClient: 'async_trait,
Stores a key-value pair with strong consistency. Read more
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<(), KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalKvClient: '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<(), KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalKvClient: 'async_trait,
Stores a key-value pair with time-to-live (TTL). Read more
Source§fn get<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalKvClient: 'async_trait,
fn get<'life0, 'async_trait>(
&'life0 self,
key: impl AsRef<[u8]> + Send + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalKvClient: 'async_trait,
Retrieves the value associated with a key. Read more
Source§fn get_multi<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Bytes],
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Bytes>>, KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalKvClient: 'async_trait,
fn get_multi<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Bytes],
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Bytes>>, KvClientError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalKvClient: 'async_trait,
Retrieves multiple keys in a single request. Read more
Auto Trait Implementations§
impl Freeze for LocalKvClient
impl RefUnwindSafe for LocalKvClient
impl Send for LocalKvClient
impl Sync for LocalKvClient
impl Unpin for LocalKvClient
impl UnwindSafe for LocalKvClient
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
Mutably borrows from an owned value. Read more
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>
Wrap the input message
T in a tonic::Request