Skip to main content

nodedb_cluster/
forward.rs

1//! Physical-plan execution trait for leader-based request routing.
2//!
3//! [`PlanExecutor`]: the physical-plan execution path introduced in C-β.
4//! The legacy [`RequestForwarder`] SQL-string path was deleted in C-δ.6.
5
6use crate::rpc_codec::{ExecuteRequest, ExecuteResponse};
7
8// ── Physical-plan execution (C-β) ────────────────────────────────────────────
9
10/// Trait for executing a pre-planned `PhysicalPlan` on the local Data Plane.
11///
12/// Implemented in `nodedb/src/control/exec_receiver.rs` by `LocalPlanExecutor`.
13/// The cluster RPC handler calls this when it receives an `ExecuteRequest`.
14///
15/// Responsibilities:
16/// 1. Validate that `deadline_remaining_ms > 0`.
17/// 2. For each `DescriptorVersionEntry`, verify the local descriptor version matches.
18/// 3. Decode `plan_bytes` via `nodedb::bridge::physical_plan::wire::decode`.
19/// 4. Dispatch through the local SPSC bridge.
20/// 5. Collect response payloads.
21/// 6. Map errors to `TypedClusterError`.
22pub trait PlanExecutor: Send + Sync + 'static {
23    fn execute_plan(
24        &self,
25        req: ExecuteRequest,
26    ) -> impl std::future::Future<Output = ExecuteResponse> + Send;
27}
28
29/// No-op executor for single-node mode or testing.
30pub struct NoopPlanExecutor;
31
32impl PlanExecutor for NoopPlanExecutor {
33    async fn execute_plan(&self, _req: ExecuteRequest) -> ExecuteResponse {
34        use crate::rpc_codec::TypedClusterError;
35        ExecuteResponse::err(TypedClusterError::Internal {
36            code: 0,
37            message: "plan execution not available (single-node mode)".into(),
38        })
39    }
40}