MCPcopy Create free account
hub / github.com/deventlab/d-engine / get_with_consistency

Method get_with_consistency

d-engine-server/src/api/embedded_client.rs:289–325  ·  view source on GitHub ↗

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 ```ignore use d_engine_proto::client::Rea

(
        &self,
        key: impl AsRef<[u8]>,
        consistency: ReadConsistencyPolicy,
    )

Source from the content-addressed store, hash-verified

287 /// ).await?;
288 /// ```
289 pub async fn get_with_consistency(
290 &self,
291 key: impl AsRef<[u8]>,
292 consistency: ReadConsistencyPolicy,
293 ) -> ClientApiResult<Option<Bytes>> {
294 let request = ClientReadRequest {
295 client_id: self.client_id,
296 keys: vec![Bytes::copy_from_slice(key.as_ref())],
297 consistency_policy: Some(consistency),
298 };
299
300 let (resp_tx, resp_rx) = MaybeCloneOneshot::new();
301
302 self.cmd_tx
303 .send(d_engine_core::ClientCmd::Read(request, resp_tx))
304 .await
305 .map_err(|_| channel_closed_error())?;
306
307 let result = tokio::time::timeout(self.timeout, resp_rx)
308 .await
309 .map_err(|_| timeout_error(self.timeout))?
310 .map_err(|_| channel_closed_error())?;
311
312 let response =
313 result.map_err(|status| server_error(format!("RPC error: {}", status.message())))?;
314
315 if response.error != ErrorCode::Success {
316 return Err(Self::map_error_response(
317 response.error,
318 response.leader_hint,
319 response.retry_after_ms,
320 ));
321 }
322
323 let read_results = extract_read_payload(response.result)?;
324 Ok(read_results.entries.first().map(|e| e.value.clone()))
325 }
326
327 /// Get multiple keys with linearizable consistency.
328 ///

Callers 6

run_benchmark_taskFunction · 0.80
run_local_benchmarkFunction · 0.80
get_linearizableMethod · 0.80
get_eventualMethod · 0.80
get_leaseMethod · 0.80

Calls 6

channel_closed_errorFunction · 0.85
timeout_errorFunction · 0.85
server_errorFunction · 0.85
extract_read_payloadFunction · 0.85
sendMethod · 0.80
cloneMethod · 0.45

Tested by 1