Skip to content

Commit cb9c91b

Browse files
committed
refactor(engine): replace long argument lists with params structs
KV, sparse B-tree, graph edge/pattern, and timeseries grouped-scan entry points took eight-plus positional arguments and were annotated with #[allow(clippy::too_many_arguments)]. Bundle each call's arguments into a dedicated params struct instead, removing the lint allowance and updating every executor handler and test call site.
1 parent 8450183 commit cb9c91b

38 files changed

Lines changed: 1526 additions & 915 deletions

nodedb/src/data/executor/core_loop/maintenance.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ impl CoreLoop {
200200
for v in new_vals.difference(&old_vals) {
201201
if let Err(e) = self.sparse.index_put_in_txn(
202202
txn,
203-
database_id,
204-
tid,
205-
collection,
206-
&index_path.path,
207-
v,
208-
doc_id,
203+
crate::engine::sparse::btree_index::IndexEntryTxn {
204+
database_id,
205+
tenant_id: tid,
206+
collection,
207+
field: &index_path.path,
208+
value: v,
209+
document_id: doc_id,
210+
},
209211
) {
210212
tracing::warn!(
211213
core = self.core_id,

nodedb/src/data/executor/handlers/control/move_tenant.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ impl CoreLoop {
4444
}
4545

4646
// KV engine.
47-
self.kv_engine.rename_collection(
48-
old_database_id,
49-
new_database_id,
50-
tenant_id,
51-
old_collection,
52-
new_collection,
53-
);
47+
self.kv_engine
48+
.rename_collection(crate::engine::kv::RenameCollectionParams {
49+
old_database_id,
50+
new_database_id,
51+
tenant_id,
52+
old_collection,
53+
new_collection,
54+
});
5455

5556
self.response_ok(task)
5657
}

nodedb/src/data/executor/handlers/control/snapshot.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,29 @@ impl CoreLoop {
139139
debug!(core = self.core_id, %collection, %field, limit, "range scan");
140140

141141
// Try index-backed range scan first.
142-
let results = match self.sparse.range_scan(
143-
task.request.database_id.as_u64(),
144-
tid,
145-
collection,
146-
field,
147-
lower,
148-
upper,
149-
limit,
150-
) {
151-
Ok(r) => r,
152-
Err(e) => {
153-
warn!(core = self.core_id, error = %e, "sparse range scan failed");
154-
return self.response_error(
155-
task,
156-
ErrorCode::Internal {
157-
detail: e.to_string(),
158-
},
159-
);
160-
}
161-
};
142+
let results =
143+
match self
144+
.sparse
145+
.range_scan(crate::engine::sparse::btree_index::RangeScanParams {
146+
database_id: task.request.database_id.as_u64(),
147+
tenant_id: tid,
148+
collection,
149+
field,
150+
lower,
151+
upper,
152+
limit,
153+
}) {
154+
Ok(r) => r,
155+
Err(e) => {
156+
warn!(core = self.core_id, error = %e, "sparse range scan failed");
157+
return self.response_error(
158+
task,
159+
ErrorCode::Internal {
160+
detail: e.to_string(),
161+
},
162+
);
163+
}
164+
};
162165

163166
// If the index returned nothing, fall back to full scan + sort.
164167
// This handles collections without a secondary index on `field`.

nodedb/src/data/executor/handlers/document/write.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,14 @@ impl CoreLoop {
302302
}
303303
if let Err(e) = self.sparse.index_put_in_txn(
304304
&txn,
305-
task.request.database_id.as_u64(),
306-
tid,
307-
collection,
308-
path,
309-
&stored,
310-
doc_id,
305+
crate::engine::sparse::btree_index::IndexEntryTxn {
306+
database_id: task.request.database_id.as_u64(),
307+
tenant_id: tid,
308+
collection,
309+
field: path,
310+
value: &stored,
311+
document_id: doc_id,
312+
},
311313
) {
312314
return self.response_error(
313315
task,

nodedb/src/data/executor/handlers/graph_match.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,15 @@ impl CoreLoop {
253253
let overlay = self.match_graph_overlay(task, tid);
254254
match crate::engine::graph::pattern::executor::execute(
255255
&query,
256-
partition,
257-
&self.edge_store,
258-
frontier_bitmap,
259-
is_remote_node,
260-
varlen_caps,
261-
&props,
262-
overlay.as_ref(),
256+
crate::engine::graph::pattern::executor::MatchExecCtx {
257+
csr: partition,
258+
edge_store: &self.edge_store,
259+
frontier_bitmap,
260+
is_remote_node,
261+
varlen_caps,
262+
props: &props,
263+
overlay: overlay.as_ref(),
264+
},
263265
) {
264266
Ok(outcome) => self.match_outcome_response(task, outcome),
265267
Err(e) => self.response_error(task, ErrorCode::from(e)),
@@ -363,17 +365,19 @@ impl CoreLoop {
363365
// unit.
364366
match crate::engine::graph::pattern::executor::execute_continuation(
365367
&query,
366-
partition,
367-
&self.edge_store,
368-
None, // no anchor prefilter on the resume path
369-
is_remote_node,
368+
crate::engine::graph::pattern::executor::MatchExecCtx {
369+
csr: partition,
370+
edge_store: &self.edge_store,
371+
frontier_bitmap: None, // no anchor prefilter on the resume path
372+
is_remote_node,
373+
varlen_caps,
374+
props: &props,
375+
overlay: None,
376+
},
370377
ContinuationSeed {
371378
triple_idx: resume_triple_idx,
372379
seed_row,
373380
},
374-
varlen_caps,
375-
&props,
376-
None,
377381
) {
378382
Ok(outcome) => self.match_outcome_response(task, outcome),
379383
Err(e) => self.response_error(task, ErrorCode::from(e)),
@@ -459,14 +463,16 @@ impl CoreLoop {
459463
// built. Cross-shard MATCH read-your-own-writes is a separate unit.
460464
match crate::engine::graph::pattern::executor::execute_varlen_resume(
461465
&query,
462-
partition,
463-
&self.edge_store,
464-
None, // no anchor prefilter on the resume path
465-
is_remote_node,
466+
crate::engine::graph::pattern::executor::MatchExecCtx {
467+
csr: partition,
468+
edge_store: &self.edge_store,
469+
frontier_bitmap: None, // no anchor prefilter on the resume path
470+
is_remote_node,
471+
varlen_caps,
472+
props: &props,
473+
overlay: None,
474+
},
466475
resume,
467-
varlen_caps,
468-
&props,
469-
None,
470476
) {
471477
Ok(outcome) => self.match_outcome_response(task, outcome),
472478
Err(e) => self.response_error(task, ErrorCode::from(e)),

nodedb/src/data/executor/handlers/graph_temporal.rs

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,45 +57,22 @@ impl CoreLoop {
5757
);
5858
let database_id = task.request.database_id.as_u64();
5959
let tenant = TenantId::new(tid);
60+
let as_of_params = crate::engine::graph::edge_store::NeighborsAsOfParams {
61+
db: database_id,
62+
tid: tenant,
63+
collection,
64+
node: node_id,
65+
label_filter: edge_label.as_deref(),
66+
system_as_of_ms,
67+
valid_at_ms,
68+
};
6069
let edges_result = match direction {
61-
Direction::Out => self.edge_store.neighbors_out_as_of(
62-
database_id,
63-
tenant,
64-
collection,
65-
node_id,
66-
edge_label.as_deref(),
67-
system_as_of_ms,
68-
valid_at_ms,
69-
),
70-
Direction::In => self.edge_store.neighbors_in_as_of(
71-
database_id,
72-
tenant,
73-
collection,
74-
node_id,
75-
edge_label.as_deref(),
76-
system_as_of_ms,
77-
valid_at_ms,
78-
),
70+
Direction::Out => self.edge_store.neighbors_out_as_of(as_of_params),
71+
Direction::In => self.edge_store.neighbors_in_as_of(as_of_params),
7972
Direction::Both => {
80-
let out = self.edge_store.neighbors_out_as_of(
81-
database_id,
82-
tenant,
83-
collection,
84-
node_id,
85-
edge_label.as_deref(),
86-
system_as_of_ms,
87-
valid_at_ms,
88-
);
73+
let out = self.edge_store.neighbors_out_as_of(as_of_params);
8974
match out {
90-
Ok(mut out) => match self.edge_store.neighbors_in_as_of(
91-
database_id,
92-
tenant,
93-
collection,
94-
node_id,
95-
edge_label.as_deref(),
96-
system_as_of_ms,
97-
valid_at_ms,
98-
) {
75+
Ok(mut out) => match self.edge_store.neighbors_in_as_of(as_of_params) {
9976
Ok(inbound) => {
10077
out.extend(inbound);
10178
Ok(out)

nodedb/src/data/executor/handlers/kv/crud.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,16 @@ impl CoreLoop {
150150
.epoch_system_ms
151151
.map(|ms| ms as u64)
152152
.unwrap_or_else(current_ms);
153-
let old = self
154-
.kv_engine
155-
.put(did, tid, collection, key, value, ttl_ms, now_ms, surrogate);
153+
let old = self.kv_engine.put(crate::engine::kv::KvPutParams {
154+
database_id: did,
155+
tenant_id: tid,
156+
collection,
157+
key,
158+
value,
159+
ttl_ms,
160+
now_ms,
161+
surrogate,
162+
});
156163
if let Some(ref m) = self.metrics {
157164
m.record_kv_put();
158165
}
@@ -222,8 +229,16 @@ impl CoreLoop {
222229
);
223230
}
224231

225-
self.kv_engine
226-
.put(did, tid, collection, key, value, ttl_ms, now_ms, surrogate);
232+
self.kv_engine.put(crate::engine::kv::KvPutParams {
233+
database_id: did,
234+
tenant_id: tid,
235+
collection,
236+
key,
237+
value,
238+
ttl_ms,
239+
now_ms,
240+
surrogate,
241+
});
227242
if let Some(ref m) = self.metrics {
228243
m.record_kv_put();
229244
}
@@ -276,8 +291,16 @@ impl CoreLoop {
276291
return self.response_ok(task);
277292
}
278293

279-
self.kv_engine
280-
.put(did, tid, collection, key, value, ttl_ms, now_ms, surrogate);
294+
self.kv_engine.put(crate::engine::kv::KvPutParams {
295+
database_id: did,
296+
tenant_id: tid,
297+
collection,
298+
key,
299+
value,
300+
ttl_ms,
301+
now_ms,
302+
surrogate,
303+
});
281304
if let Some(ref m) = self.metrics {
282305
m.record_kv_put();
283306
}
@@ -378,16 +401,16 @@ impl CoreLoop {
378401
}
379402
};
380403

381-
self.kv_engine.put(
382-
did,
383-
tid,
404+
self.kv_engine.put(crate::engine::kv::KvPutParams {
405+
database_id: did,
406+
tenant_id: tid,
384407
collection,
385408
key,
386-
&stored_bytes,
409+
value: &stored_bytes,
387410
ttl_ms,
388411
now_ms,
389412
surrogate,
390-
);
413+
});
391414
if let Some(ref m) = self.metrics {
392415
m.record_kv_put();
393416
}

nodedb/src/data/executor/handlers/kv/field.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ impl CoreLoop {
9292
Err(e) => return self.response_error(task, e),
9393
};
9494

95-
self.kv_engine.put(
96-
did,
97-
tid,
95+
self.kv_engine.put(crate::engine::kv::KvPutParams {
96+
database_id: did,
97+
tenant_id: tid,
9898
collection,
9999
key,
100-
&computed.new_value,
101-
0,
100+
value: &computed.new_value,
101+
ttl_ms: 0,
102102
now_ms,
103103
surrogate,
104-
);
104+
});
105105
match response_codec::encode_json(
106106
&serde_json::json!({ "fields_added": computed.fields_added }),
107107
) {

nodedb/src/data/executor/handlers/kv/index.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ impl CoreLoop {
2424
) -> Response {
2525
debug!(core = self.core_id, %collection, %field, "kv register index");
2626
let now_ms = current_ms();
27-
let backfilled = self.kv_engine.register_index(
28-
did,
29-
tid,
30-
collection,
31-
field,
32-
field_position,
33-
backfill,
34-
now_ms,
35-
);
27+
let backfilled = self
28+
.kv_engine
29+
.register_index(crate::engine::kv::RegisterIndexParams {
30+
database_id: did,
31+
tenant_id: tid,
32+
collection,
33+
field,
34+
field_position,
35+
backfill,
36+
now_ms,
37+
});
3638
match response_codec::encode_json(&serde_json::json!({
3739
"index": field,
3840
"backfilled": backfilled,

nodedb/src/data/executor/handlers/kv/sorted.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ impl CoreLoop {
205205

206206
match self
207207
.kv_engine
208-
.sorted_index_range(did, tid, index_name, score_min, score_max, now_ms)
209-
{
208+
.sorted_index_range(crate::engine::kv::SortedIndexRangeParams {
209+
database_id: did,
210+
tenant_id: tid,
211+
index_name,
212+
score_min,
213+
score_max,
214+
now_ms,
215+
}) {
210216
Some(entries) => {
211217
let rows: Vec<serde_json::Value> = entries
212218
.into_iter()

0 commit comments

Comments
 (0)