MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / classify_dispatch

Function classify_dispatch

nodedb/src/control/planner/calvin/dispatch.rs:144–169  ·  view source on GitHub ↗

Classify the dispatch class of a task slice by collecting the unique set of write vShards. 0 or 1 unique write vShards → `SingleShard`. 2+ unique write vShards → `MultiShard` with the full `BTreeSet `.

(tasks: &[PhysicalTask])

Source from the content-addressed store, hash-verified

142/// 0 or 1 unique write vShards → `SingleShard`.
143/// 2+ unique write vShards → `MultiShard` with the full `BTreeSet<u32>`.
144pub fn classify_dispatch(tasks: &[PhysicalTask]) -> DispatchClass {
145 let mut vshards: BTreeSet<u32> = BTreeSet::new();
146 let mut last_vshard = None;
147
148 for task in tasks {
149 if is_write_plan(&task.plan) {
150 let id = task.vshard_id.as_u32();
151 vshards.insert(id);
152 last_vshard = Some(task.vshard_id);
153 }
154 }
155
156 match vshards.len() {
157 0 => DispatchClass::SingleShard {
158 vshard: tasks
159 .first()
160 .map(|t| t.vshard_id)
161 .unwrap_or(VShardId::new(0)),
162 },
163 1 => DispatchClass::SingleShard {
164 vshard: last_vshard
165 .expect("invariant: vshards.len() == 1 means last_vshard was set during the loop"),
166 },
167 _ => DispatchClass::MultiShard { vshards },
168 }
169}
170
171// ── build_static_tx_class ────────────────────────────────────────────────────
172

Calls 6

is_write_planFunction · 0.85
firstMethod · 0.80
as_u32Method · 0.45
insertMethod · 0.45
lenMethod · 0.45
expectMethod · 0.45