| 116 | } |
| 117 | |
| 118 | pub async fn mint( |
| 119 | &mut self, |
| 120 | binding_ts: IntoTime, |
| 121 | mut new_into_upper: Antichain<IntoTime>, |
| 122 | new_from_upper: AntichainRef<'_, FromTime>, |
| 123 | ) -> ReclockBatch<FromTime, IntoTime> { |
| 124 | assert!(!new_into_upper.less_equal(&binding_ts)); |
| 125 | // The updates to the remap trace that occured during minting. |
| 126 | let mut batch = ReclockBatch { |
| 127 | updates: vec![], |
| 128 | upper: self.upper.clone(), |
| 129 | }; |
| 130 | |
| 131 | while *self.upper == [IntoTime::minimum()] |
| 132 | || (PartialOrder::less_equal(&self.source_upper.frontier(), &new_from_upper) |
| 133 | && PartialOrder::less_than(&self.upper, &new_into_upper) |
| 134 | && self.upper.less_equal(&binding_ts)) |
| 135 | { |
| 136 | // If source is closed, close remap shard as well. |
| 137 | if new_from_upper.is_empty() { |
| 138 | new_into_upper = Antichain::new(); |
| 139 | } |
| 140 | |
| 141 | // If this is the first binding we mint then we will mint it at the minimum target |
| 142 | // timestamp. The first source upper is always the upper of the snapshot and by mapping |
| 143 | // it to the minimum target timestamp we make it so that the final shard never appears |
| 144 | // empty at any timestamp. |
| 145 | let binding_ts = if *self.upper == [IntoTime::minimum()] { |
| 146 | IntoTime::minimum() |
| 147 | } else { |
| 148 | binding_ts.clone() |
| 149 | }; |
| 150 | |
| 151 | let mut updates = vec![]; |
| 152 | for src_ts in self.source_upper.frontier().iter().cloned() { |
| 153 | updates.push((src_ts, binding_ts.clone(), Diff::MINUS_ONE)); |
| 154 | } |
| 155 | for src_ts in new_from_upper.iter().cloned() { |
| 156 | updates.push((src_ts, binding_ts.clone(), Diff::ONE)); |
| 157 | } |
| 158 | consolidation::consolidate_updates(&mut updates); |
| 159 | |
| 160 | let new_batch = match self.append_batch(updates, &new_into_upper).await { |
| 161 | Ok(trace_batch) => trace_batch, |
| 162 | Err(UpperMismatch { current, .. }) => self.sync(current.borrow()).await, |
| 163 | }; |
| 164 | batch.updates.extend(new_batch.updates); |
| 165 | batch.upper = new_batch.upper; |
| 166 | } |
| 167 | |
| 168 | batch |
| 169 | } |
| 170 | |
| 171 | /// Appends the provided updates to the remap collection at the next available minting |
| 172 | /// IntoTime and updates this operator's in-memory state accordingly. |