Skip to content

Commit 32ae9c0

Browse files
committed
refactor(engine): replace long argument lists with params structs
1 parent 53afdb9 commit 32ae9c0

9 files changed

Lines changed: 242 additions & 99 deletions

File tree

nodedb/src/data/executor/dispatch/document.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ impl CoreLoop {
129129
returning,
130130
} => self.execute_point_update(
131131
task,
132-
tid,
133-
collection,
134-
document_id,
135-
*surrogate,
136-
updates,
137-
returning.as_ref(),
132+
crate::data::executor::handlers::point::update::PointUpdateParams {
133+
tid,
134+
collection,
135+
document_id,
136+
surrogate: *surrogate,
137+
updates,
138+
returning: returning.as_ref(),
139+
},
138140
),
139141

140142
DocumentOp::Scan {
@@ -277,12 +279,14 @@ impl CoreLoop {
277279
surrogate,
278280
} => self.execute_upsert(
279281
task,
280-
tid,
281-
collection,
282-
document_id,
283-
*surrogate,
284-
value,
285-
on_conflict_updates,
282+
crate::data::executor::handlers::upsert::UpsertParams {
283+
tid,
284+
collection,
285+
document_id,
286+
surrogate: *surrogate,
287+
value,
288+
on_conflict_updates,
289+
},
286290
),
287291

288292
DocumentOp::Truncate { collection, .. } => self.execute_truncate(task, tid, collection),

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

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,41 @@ pub(in crate::data::executor) struct KvInsertOnConflictUpdateParams<'a> {
2626
pub surrogate: Surrogate,
2727
}
2828

29+
/// Parameters for a KV point `GET`.
30+
pub(in crate::data::executor) struct KvGetParams<'a> {
31+
pub did: u64,
32+
pub tid: u64,
33+
pub collection: &'a str,
34+
pub key: &'a [u8],
35+
pub rls_filters: &'a [u8],
36+
pub surrogate_ceiling: Option<u32>,
37+
}
38+
39+
/// Parameters for a KV point write (`PUT` / `INSERT` / `INSERT ... IF ABSENT`).
40+
pub(in crate::data::executor) struct KvWriteParams<'a> {
41+
pub did: u64,
42+
pub tid: u64,
43+
pub collection: &'a str,
44+
pub key: &'a [u8],
45+
pub value: &'a [u8],
46+
pub ttl_ms: u64,
47+
pub surrogate: Surrogate,
48+
}
49+
2950
impl CoreLoop {
30-
#[allow(clippy::too_many_arguments)]
3151
pub(in crate::data::executor) fn execute_kv_get(
3252
&self,
3353
task: &ExecutionTask,
34-
did: u64,
35-
tid: u64,
36-
collection: &str,
37-
key: &[u8],
38-
rls_filters: &[u8],
39-
surrogate_ceiling: Option<u32>,
54+
params: KvGetParams<'_>,
4055
) -> Response {
56+
let KvGetParams {
57+
did,
58+
tid,
59+
collection,
60+
key,
61+
rls_filters,
62+
surrogate_ceiling,
63+
} = params;
4164
debug!(core = self.core_id, %collection, "kv get");
4265

4366
// Read-your-own-writes: an in-transaction get consults this
@@ -122,18 +145,20 @@ impl CoreLoop {
122145
}
123146
}
124147

125-
#[allow(clippy::too_many_arguments)]
126148
pub(in crate::data::executor) fn execute_kv_put(
127149
&mut self,
128150
task: &ExecutionTask,
129-
did: u64,
130-
tid: u64,
131-
collection: &str,
132-
key: &[u8],
133-
value: &[u8],
134-
ttl_ms: u64,
135-
surrogate: Surrogate,
151+
params: KvWriteParams<'_>,
136152
) -> Response {
153+
let KvWriteParams {
154+
did,
155+
tid,
156+
collection,
157+
key,
158+
value,
159+
ttl_ms,
160+
surrogate,
161+
} = params;
137162
debug!(core = self.core_id, %collection, "kv put");
138163

139164
// Memory budget check: reject new PUTs when over budget.
@@ -186,18 +211,20 @@ impl CoreLoop {
186211
/// are pinned to one Data Plane core (vshard routing), and the core
187212
/// loop runs ops serially — no other writer can slip between the
188213
/// probe and the put on the same key.
189-
#[allow(clippy::too_many_arguments)]
190214
pub(in crate::data::executor) fn execute_kv_insert(
191215
&mut self,
192216
task: &ExecutionTask,
193-
did: u64,
194-
tid: u64,
195-
collection: &str,
196-
key: &[u8],
197-
value: &[u8],
198-
ttl_ms: u64,
199-
surrogate: Surrogate,
217+
params: KvWriteParams<'_>,
200218
) -> Response {
219+
let KvWriteParams {
220+
did,
221+
tid,
222+
collection,
223+
key,
224+
value,
225+
ttl_ms,
226+
surrogate,
227+
} = params;
201228
debug!(core = self.core_id, %collection, "kv insert");
202229

203230
if self.kv_engine.is_over_budget() {
@@ -258,18 +285,20 @@ impl CoreLoop {
258285

259286
/// SQL `INSERT ... ON CONFLICT DO NOTHING` semantics: write if absent,
260287
/// silent no-op on duplicate. No error on conflict.
261-
#[allow(clippy::too_many_arguments)]
262288
pub(in crate::data::executor) fn execute_kv_insert_if_absent(
263289
&mut self,
264290
task: &ExecutionTask,
265-
did: u64,
266-
tid: u64,
267-
collection: &str,
268-
key: &[u8],
269-
value: &[u8],
270-
ttl_ms: u64,
271-
surrogate: Surrogate,
291+
params: KvWriteParams<'_>,
272292
) -> Response {
293+
let KvWriteParams {
294+
did,
295+
tid,
296+
collection,
297+
key,
298+
value,
299+
ttl_ms,
300+
surrogate,
301+
} = params;
273302
debug!(core = self.core_id, %collection, "kv insert-if-absent");
274303

275304
if self.kv_engine.is_over_budget() {
@@ -323,7 +352,6 @@ impl CoreLoop {
323352
/// decode the stored value, apply the updates (with `EXCLUDED`
324353
/// resolving to the would-be-inserted row), and write the merged
325354
/// result back.
326-
#[allow(clippy::too_many_arguments)]
327355
pub(in crate::data::executor) fn execute_kv_insert_on_conflict_update(
328356
&mut self,
329357
task: &ExecutionTask,

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

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,68 @@ impl CoreLoop {
2424
surrogate_ceiling,
2525
} => self.execute_kv_get(
2626
task,
27-
did,
28-
tid,
29-
collection,
30-
key,
31-
rls_filters,
32-
*surrogate_ceiling,
27+
super::crud::KvGetParams {
28+
did,
29+
tid,
30+
collection,
31+
key,
32+
rls_filters,
33+
surrogate_ceiling: *surrogate_ceiling,
34+
},
3335
),
3436
KvOp::Put {
3537
collection,
3638
key,
3739
value,
3840
ttl_ms,
3941
surrogate,
40-
} => self.execute_kv_put(task, did, tid, collection, key, value, *ttl_ms, *surrogate),
42+
} => self.execute_kv_put(
43+
task,
44+
super::crud::KvWriteParams {
45+
did,
46+
tid,
47+
collection,
48+
key,
49+
value,
50+
ttl_ms: *ttl_ms,
51+
surrogate: *surrogate,
52+
},
53+
),
4154
KvOp::Insert {
4255
collection,
4356
key,
4457
value,
4558
ttl_ms,
4659
surrogate,
47-
} => {
48-
self.execute_kv_insert(task, did, tid, collection, key, value, *ttl_ms, *surrogate)
49-
}
60+
} => self.execute_kv_insert(
61+
task,
62+
super::crud::KvWriteParams {
63+
did,
64+
tid,
65+
collection,
66+
key,
67+
value,
68+
ttl_ms: *ttl_ms,
69+
surrogate: *surrogate,
70+
},
71+
),
5072
KvOp::InsertIfAbsent {
5173
collection,
5274
key,
5375
value,
5476
ttl_ms,
5577
surrogate,
5678
} => self.execute_kv_insert_if_absent(
57-
task, did, tid, collection, key, value, *ttl_ms, *surrogate,
79+
task,
80+
super::crud::KvWriteParams {
81+
did,
82+
tid,
83+
collection,
84+
key,
85+
value,
86+
ttl_ms: *ttl_ms,
87+
surrogate: *surrogate,
88+
},
5889
),
5990
KvOp::InsertOnConflictUpdate {
6091
collection,
@@ -135,12 +166,14 @@ impl CoreLoop {
135166
backfill,
136167
} => self.execute_kv_register_index(
137168
task,
138-
did,
139-
tid,
140-
collection,
141-
field,
142-
*field_position,
143-
*backfill,
169+
super::index::KvRegisterIndexParams {
170+
did,
171+
tid,
172+
collection,
173+
field,
174+
field_position: *field_position,
175+
backfill: *backfill,
176+
},
144177
),
145178
KvOp::DropIndex { collection, field } => {
146179
self.execute_kv_drop_index(task, did, tid, collection, field)
@@ -278,11 +311,13 @@ impl CoreLoop {
278311
score_max,
279312
} => self.execute_kv_sorted_index_range(
280313
task,
281-
did,
282-
tid,
283-
index_name,
284-
score_min.as_deref(),
285-
score_max.as_deref(),
314+
super::sorted::KvSortedIndexRangeParams {
315+
did,
316+
tid,
317+
index_name,
318+
score_min: score_min.as_deref(),
319+
score_max: score_max.as_deref(),
320+
},
286321
),
287322
KvOp::SortedIndexCount { index_name } => {
288323
self.execute_kv_sorted_index_count(task, did, tid, index_name)

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ use crate::data::executor::response_codec;
1010
use crate::data::executor::task::ExecutionTask;
1111
use crate::engine::kv::current_ms;
1212

13+
/// Parameters for registering a KV secondary index.
14+
pub(in crate::data::executor) struct KvRegisterIndexParams<'a> {
15+
pub did: u64,
16+
pub tid: u64,
17+
pub collection: &'a str,
18+
pub field: &'a str,
19+
pub field_position: usize,
20+
pub backfill: bool,
21+
}
22+
1323
impl CoreLoop {
14-
#[allow(clippy::too_many_arguments)]
1524
pub(in crate::data::executor) fn execute_kv_register_index(
1625
&mut self,
1726
task: &ExecutionTask,
18-
did: u64,
19-
tid: u64,
20-
collection: &str,
21-
field: &str,
22-
field_position: usize,
23-
backfill: bool,
27+
params: KvRegisterIndexParams<'_>,
2428
) -> Response {
29+
let KvRegisterIndexParams {
30+
did,
31+
tid,
32+
collection,
33+
field,
34+
field_position,
35+
backfill,
36+
} = params;
2537
debug!(core = self.core_id, %collection, %field, "kv register index");
2638
let now_ms = current_ms();
2739
let backfilled = self

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
pub(in crate::data::executor) mod atomic;
66
pub(in crate::data::executor) mod batch;
7-
mod crud;
7+
pub(in crate::data::executor) mod crud;
88
mod dispatch;
99
mod field;
1010
mod index;

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ pub(in crate::data::executor) struct KvRegisterSortedIndexParams<'a> {
2727
pub window_end_ms: u64,
2828
}
2929

30+
/// Parameters for `execute_kv_sorted_index_range`.
31+
pub(in crate::data::executor) struct KvSortedIndexRangeParams<'a> {
32+
pub did: u64,
33+
pub tid: u64,
34+
pub index_name: &'a str,
35+
pub score_min: Option<&'a [u8]>,
36+
pub score_max: Option<&'a [u8]>,
37+
}
38+
3039
impl CoreLoop {
3140
pub(in crate::data::executor) fn execute_kv_register_sorted_index(
3241
&mut self,
@@ -190,16 +199,18 @@ impl CoreLoop {
190199
}
191200
}
192201

193-
#[allow(clippy::too_many_arguments)]
194202
pub(in crate::data::executor) fn execute_kv_sorted_index_range(
195203
&self,
196204
task: &ExecutionTask,
197-
did: u64,
198-
tid: u64,
199-
index_name: &str,
200-
score_min: Option<&[u8]>,
201-
score_max: Option<&[u8]>,
205+
params: KvSortedIndexRangeParams<'_>,
202206
) -> Response {
207+
let KvSortedIndexRangeParams {
208+
did,
209+
tid,
210+
index_name,
211+
score_min,
212+
score_max,
213+
} = params;
203214
debug!(core = self.core_id, %index_name, "kv sorted index range");
204215
let now_ms = current_ms();
205216

0 commit comments

Comments
 (0)