Skip to content

Commit c046fbf

Browse files
committed
refactor(engine): replace long argument lists with params structs
1 parent 34f3210 commit c046fbf

27 files changed

Lines changed: 493 additions & 265 deletions

File tree

nodedb/src/control/planner/calvin/dependent_recon.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ use crate::control::cluster::calvin::executor::ollp::error::OllpError;
2323
use crate::control::planner::calvin::dispatch::collection_name_from_plan;
2424
use crate::control::planner::calvin::preexec::{PreexecScan, run_preexec_scan};
2525
use crate::control::planner::calvin::{
26-
build_dependent_tx_class, is_dependent_predicate, predicate_class_for_filters,
27-
run_dependent_with_retry, submit_calvin_routed_assign,
26+
DependentRetryArgs, build_dependent_tx_class, is_dependent_predicate,
27+
predicate_class_for_filters, run_dependent_with_retry, submit_calvin_routed_assign,
2828
};
2929
use crate::control::planner::implicit_edges::{
30-
EdgeFieldOverrides, append_implicit_edge_delete_tasks, append_implicit_edge_update_tasks,
31-
parse_edge_field_overrides,
30+
EdgeFieldOverrides, EdgeUpdateCtx, append_implicit_edge_delete_tasks,
31+
append_implicit_edge_update_tasks, parse_edge_field_overrides,
3232
};
3333
use crate::control::state::SharedState;
3434
use crate::types::{DatabaseId, TenantId, TraceId};
@@ -371,12 +371,14 @@ pub async fn dispatch_dependent_edge_recon(
371371
}
372372
EdgeLifecycle::Update(overrides) => {
373373
append_implicit_edge_update_tasks(
374-
state,
374+
EdgeUpdateCtx {
375+
state,
376+
tenant_id,
377+
database_id,
378+
trace_id: TraceId::ZERO,
379+
collection: dep_collection,
380+
},
375381
&mut edge_tasks,
376-
tenant_id,
377-
database_id,
378-
TraceId::ZERO,
379-
dep_collection,
380382
&edges,
381383
&surrogates,
382384
overrides,
@@ -440,16 +442,16 @@ pub async fn dispatch_dependent_edge_recon(
440442
)
441443
};
442444

443-
run_dependent_with_retry(
445+
run_dependent_with_retry(DependentRetryArgs {
444446
registry,
445-
orc,
446-
pred_class,
447+
orchestrator: orc,
448+
predicate_class_hash: pred_class,
447449
timeout,
448450
ollp_max_retries,
449451
initial_predicted,
450452
submit,
451453
rescan,
452-
)
454+
})
453455
.await?;
454456

455457
Ok(DependentReconOutcome {

nodedb/src/control/planner/calvin/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use dispatch::{
2222
pub use dispatch_multi::dispatch_tasks_to_calvin;
2323
pub use explain::calvin_explain_preamble;
2424
pub use predicate::predicate_class_for_filters;
25-
pub use retry_loop::run_dependent_with_retry;
25+
pub use retry_loop::{DependentRetryArgs, run_dependent_with_retry};
2626
pub use submit::{
2727
RoutedAssignment, submit_and_await_calvin, submit_and_await_calvin_with_timeout,
2828
submit_calvin_routed, submit_calvin_routed_assign,

nodedb/src/control/planner/calvin/retry_loop.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,36 @@ use crate::control::planner::calvin::submit::RoutedAssignment;
3333
/// `submit` and `rescan` are injected so this loop is unit-testable WITHOUT a
3434
/// live server/executor: a fake scheduler driving the real
3535
/// [`CalvinCompletionRegistry`] suffices.
36-
#[allow(clippy::too_many_arguments)]
36+
pub struct DependentRetryArgs<'a, P, SF, RF> {
37+
pub registry: &'a CalvinCompletionRegistry,
38+
pub orchestrator: &'a OllpOrchestrator,
39+
pub predicate_class_hash: u64,
40+
pub timeout: std::time::Duration,
41+
pub ollp_max_retries: u32,
42+
pub initial_predicted: P,
43+
pub submit: SF,
44+
pub rescan: RF,
45+
}
46+
3747
pub async fn run_dependent_with_retry<P, SF, SFut, RF, RFut>(
38-
registry: &CalvinCompletionRegistry,
39-
orchestrator: &OllpOrchestrator,
40-
predicate_class_hash: u64,
41-
timeout: std::time::Duration,
42-
ollp_max_retries: u32,
43-
initial_predicted: P,
44-
mut submit: SF,
45-
mut rescan: RF,
48+
args: DependentRetryArgs<'_, P, SF, RF>,
4649
) -> crate::Result<()>
4750
where
4851
SF: FnMut(&P) -> SFut,
4952
SFut: std::future::Future<Output = Result<RoutedAssignment, OllpError>>,
5053
RF: FnMut() -> RFut,
5154
RFut: std::future::Future<Output = crate::Result<P>>,
5255
{
56+
let DependentRetryArgs {
57+
registry,
58+
orchestrator,
59+
predicate_class_hash,
60+
timeout,
61+
ollp_max_retries,
62+
initial_predicted,
63+
mut submit,
64+
mut rescan,
65+
} = args;
5366
let mut predicted = initial_predicted;
5467
let mut retry: u32 = 0;
5568
loop {

nodedb/src/control/planner/calvin/retry_loop_tests.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ fn converges_after_two_mismatches() {
100100
let submit_calls = Arc::clone(&submit_calls);
101101
let rescan_calls = Arc::clone(&rescan_calls);
102102
let tx = tx.clone();
103-
run_dependent_with_retry(
104-
&registry,
105-
&orchestrator,
106-
0xABCD,
107-
std::time::Duration::from_secs(5),
108-
5,
109-
vec![1, 2, 3],
110-
move |_predicted: &Vec<u32>| {
103+
run_dependent_with_retry(DependentRetryArgs {
104+
registry: &registry,
105+
orchestrator: &orchestrator,
106+
predicate_class_hash: 0xABCD,
107+
timeout: std::time::Duration::from_secs(5),
108+
ollp_max_retries: 5,
109+
initial_predicted: vec![1, 2, 3],
110+
submit: move |_predicted: &Vec<u32>| {
111111
let seq = Arc::clone(&seq);
112112
let submit_calls = Arc::clone(&submit_calls);
113113
let tx = tx.clone();
@@ -120,14 +120,14 @@ fn converges_after_two_mismatches() {
120120
Ok::<RoutedAssignment, OllpError>(assignment)
121121
}
122122
},
123-
move || {
123+
rescan: move || {
124124
let rescan_calls = Arc::clone(&rescan_calls);
125125
async move {
126126
let n = rescan_calls.fetch_add(1, Ordering::SeqCst);
127127
Ok(vec![100 + n])
128128
}
129129
},
130-
)
130+
})
131131
.await
132132
};
133133

@@ -168,14 +168,14 @@ fn exhausts_on_persistent_mismatch() {
168168
let seq = Arc::clone(&seq);
169169
let submit_calls = Arc::clone(&submit_calls);
170170
let tx = tx.clone();
171-
run_dependent_with_retry(
172-
&registry,
173-
&orchestrator,
174-
0xABCD,
175-
std::time::Duration::from_secs(5),
176-
3,
177-
vec![1],
178-
move |_predicted: &Vec<u32>| {
171+
run_dependent_with_retry(DependentRetryArgs {
172+
registry: &registry,
173+
orchestrator: &orchestrator,
174+
predicate_class_hash: 0xABCD,
175+
timeout: std::time::Duration::from_secs(5),
176+
ollp_max_retries: 3,
177+
initial_predicted: vec![1],
178+
submit: move |_predicted: &Vec<u32>| {
179179
let seq = Arc::clone(&seq);
180180
let submit_calls = Arc::clone(&submit_calls);
181181
let tx = tx.clone();
@@ -188,8 +188,8 @@ fn exhausts_on_persistent_mismatch() {
188188
Ok::<RoutedAssignment, OllpError>(assignment)
189189
}
190190
},
191-
move || async move { Ok(vec![1]) },
192-
)
191+
rescan: move || async move { Ok(vec![1]) },
192+
})
193193
.await
194194
};
195195

@@ -231,14 +231,14 @@ fn pre_admission_retry_does_not_rescan() {
231231
let submit_calls = Arc::clone(&submit_calls);
232232
let rescan_calls = Arc::clone(&rescan_calls);
233233
let tx = tx.clone();
234-
run_dependent_with_retry(
235-
&registry,
236-
&orchestrator,
237-
0xABCD,
238-
std::time::Duration::from_secs(5),
239-
5,
240-
vec![1],
241-
move |_predicted: &Vec<u32>| {
234+
run_dependent_with_retry(DependentRetryArgs {
235+
registry: &registry,
236+
orchestrator: &orchestrator,
237+
predicate_class_hash: 0xABCD,
238+
timeout: std::time::Duration::from_secs(5),
239+
ollp_max_retries: 5,
240+
initial_predicted: vec![1],
241+
submit: move |_predicted: &Vec<u32>| {
242242
let seq = Arc::clone(&seq);
243243
let submit_calls = Arc::clone(&submit_calls);
244244
let tx = tx.clone();
@@ -255,14 +255,14 @@ fn pre_admission_retry_does_not_rescan() {
255255
Ok::<RoutedAssignment, OllpError>(assignment)
256256
}
257257
},
258-
move || {
258+
rescan: move || {
259259
let rescan_calls = Arc::clone(&rescan_calls);
260260
async move {
261261
rescan_calls.fetch_add(1, Ordering::SeqCst);
262262
Ok(vec![1])
263263
}
264264
},
265-
)
265+
})
266266
.await
267267
};
268268

nodedb/src/control/planner/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ mod catalog_inputs;
1010
pub mod query;
1111
pub mod security;
1212

13-
pub use query::{QueryContext, SYSTEM_FUNCTION_NAMES};
13+
pub use query::{PlanSqlWithRlsParams, QueryContext, SYSTEM_FUNCTION_NAMES};
1414
pub use security::PlanSecurityContext;

nodedb/src/control/planner/context/query/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use super::catalog_inputs::CatalogInputs;
88

99
mod planning;
1010

11+
pub use planning::PlanSqlWithRlsParams;
12+
1113
/// Query context for the Control Plane.
1214
///
1315
/// SQL queries are parsed and planned via nodedb-sql, then converted

nodedb/src/control/planner/context/query/planning.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ use super::QueryContext;
1313
use crate::control::planner::context::security::PlanSecurityContext;
1414
use crate::control::server::response_shape::schema::OutputSchema;
1515

16+
/// Bundled arguments for [`QueryContext::plan_sql_with_rls`].
17+
pub struct PlanSqlWithRlsParams<'a> {
18+
pub sql: &'a str,
19+
pub tenant_id: crate::types::TenantId,
20+
pub database_id: crate::types::DatabaseId,
21+
pub sec: &'a PlanSecurityContext<'a>,
22+
}
23+
1624
impl QueryContext {
1725
/// Parse SQL and convert to NodeDB physical plan(s).
1826
///
@@ -145,17 +153,19 @@ impl QueryContext {
145153
/// Parse SQL, inject RLS predicates, convert to physical plan.
146154
///
147155
/// This is the primary query entry point.
148-
#[allow(clippy::too_many_arguments)]
149156
pub async fn plan_sql_with_rls(
150157
&self,
151-
sql: &str,
152-
tenant_id: crate::types::TenantId,
153-
database_id: crate::types::DatabaseId,
154-
sec: &PlanSecurityContext<'_>,
158+
params: PlanSqlWithRlsParams<'_>,
155159
) -> crate::Result<(
156160
Vec<nodedb_physical::physical_task::PhysicalTask>,
157161
OutputSchema,
158162
)> {
163+
let PlanSqlWithRlsParams {
164+
sql,
165+
tenant_id,
166+
database_id,
167+
sec,
168+
} = params;
159169
self.plan_sql_with_rls_returning(sql, tenant_id, database_id, sec, false)
160170
.await
161171
}

nodedb/src/control/planner/implicit_edges/delete.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use nodedb_physical::physical_task::PhysicalTask;
88

99
use super::extract::resolve_edge_label;
10-
use super::routed::push_edge_delete;
10+
use super::routed::{EdgeRouteCtx, push_edge_delete};
1111
use crate::control::state::SharedState;
1212
use crate::types::{DatabaseId, TenantId, TraceId};
1313

@@ -40,14 +40,16 @@ pub async fn append_implicit_edge_delete_tasks(
4040
for edge in edges {
4141
let label = resolve_edge_label(edge.label.as_deref());
4242
push_edge_delete(
43-
state,
43+
EdgeRouteCtx {
44+
state,
45+
tenant_id,
46+
database_id,
47+
trace_id,
48+
collection,
49+
src: &edge.from,
50+
dst: &edge.to,
51+
},
4452
out,
45-
tenant_id,
46-
database_id,
47-
trace_id,
48-
collection,
49-
&edge.from,
50-
&edge.to,
5153
label,
5254
)
5355
.await?;

nodedb/src/control/planner/implicit_edges/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ pub use catalog::mark_collection_edge_bearing;
3232
pub use delete::append_implicit_edge_delete_tasks;
3333
pub use insert::append_implicit_edge_tasks;
3434
pub use update::{
35-
EdgeFieldOverrides, FieldUpdate, WeightUpdate, append_implicit_edge_update_tasks,
36-
parse_edge_field_overrides,
35+
EdgeFieldOverrides, EdgeUpdateCtx, FieldUpdate, WeightUpdate,
36+
append_implicit_edge_update_tasks, parse_edge_field_overrides,
3737
};

0 commit comments

Comments
 (0)