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])
| 142 | /// 0 or 1 unique write vShards → `SingleShard`. |
| 143 | /// 2+ unique write vShards → `MultiShard` with the full `BTreeSet<u32>`. |
| 144 | pub 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 |