MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / dispatch_kv

Function dispatch_kv

nodedb/src/control/server/resp/gateway_dispatch.rs:29–62  ·  view source on GitHub ↗

Dispatch a read-only KV operation. Routes through the gateway when available (cluster-aware routing), falling back to direct local SPSC dispatch on single-node boot. Bridge/dispatch errors are mapped to `Error::Bridge` with a `BUSY` detail so the RESP handler can return `-BUSY` to the Redis client.

(
    state: &SharedState,
    session: &RespSession,
    plan: PhysicalPlan,
)

Source from the content-addressed store, hash-verified

27/// Bridge/dispatch errors are mapped to `Error::Bridge` with a `BUSY` detail
28/// so the RESP handler can return `-BUSY` to the Redis client.
29pub(super) async fn dispatch_kv(
30 state: &SharedState,
31 session: &RespSession,
32 plan: PhysicalPlan,
33) -> crate::Result<Response> {
34 match state.gateway.as_ref() {
35 Some(gw) => {
36 let gw_ctx = QueryContext {
37 tenant_id: session.tenant_id,
38 trace_id: TraceId::generate(),
39 database_id: DatabaseId::DEFAULT,
40 };
41 gw.execute(&gw_ctx, plan)
42 .await
43 .map_err(|e| crate::Error::Bridge {
44 detail: GatewayErrorMap::to_resp(&e),
45 })
46 .map(gateway_payloads_to_response)
47 }
48 None => {
49 let vshard =
50 VShardId::from_collection_in_database(DatabaseId::DEFAULT, &session.collection);
51 dispatch_utils::dispatch_to_data_plane(
52 state,
53 session.tenant_id,
54 vshard,
55 plan,
56 TraceId::ZERO,
57 )
58 .await
59 .map_err(map_busy_error)
60 }
61 }
62}
63
64/// Dispatch a KV write operation: WAL append first, then gateway or Data Plane.
65///

Callers 14

handle_getFunction · 0.85
handle_setFunction · 0.85
handle_existsFunction · 0.85
handle_mgetFunction · 0.85
handle_ttlFunction · 0.85
handle_scanFunction · 0.85
handle_keysFunction · 0.85
handle_dbsizeFunction · 0.85
handle_hgetFunction · 0.85
handle_hmgetFunction · 0.85
handle_zrankFunction · 0.85
handle_zrangeFunction · 0.85

Calls 3

dispatch_to_data_planeFunction · 0.50
as_refMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected