Skip to main content

nodedb_cluster/
forward.rs

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