(
&mut self,
handle: &mut TxnsHandle<K, V, T, D, C>,
commit_ts: T,
)
| 117 | /// Panics if any involved data shards were not registered before commit ts. |
| 118 | #[instrument(level = "debug", fields(ts = ?commit_ts))] |
| 119 | pub async fn commit_at<C>( |
| 120 | &mut self, |
| 121 | handle: &mut TxnsHandle<K, V, T, D, C>, |
| 122 | commit_ts: T, |
| 123 | ) -> Result<TxnApply<T>, T> |
| 124 | where |
| 125 | C: TxnsCodec, |
| 126 | { |
| 127 | let op = &Arc::clone(&handle.metrics).commit; |
| 128 | op.run(async { |
| 129 | let mut txns_upper = handle |
| 130 | .txns_write |
| 131 | .shared_upper() |
| 132 | .into_option() |
| 133 | .expect("txns shard should not be closed"); |
| 134 | |
| 135 | loop { |
| 136 | txns_upper = handle.txns_cache.update_ge(&txns_upper).await.clone(); |
| 137 | |
| 138 | // txns_upper is the (inclusive) minimum timestamp at which we |
| 139 | // could possibly write. If our requested commit timestamp is before |
| 140 | // that, then it's no longer possible to write and the caller needs |
| 141 | // to decide what to do. |
| 142 | if commit_ts < txns_upper { |
| 143 | debug!( |
| 144 | "commit_at {:?} mismatch current={:?}", |
| 145 | commit_ts, txns_upper |
| 146 | ); |
| 147 | return Err(txns_upper); |
| 148 | } |
| 149 | // Validate that the involved data shards are all registered. |
| 150 | for (data_id, _) in self.writes.iter() { |
| 151 | assert!( |
| 152 | handle |
| 153 | .txns_cache |
| 154 | .registered_at_progress(data_id, &txns_upper), |
| 155 | "{} should be registered to commit at {:?}", |
| 156 | data_id, |
| 157 | txns_upper, |
| 158 | ); |
| 159 | } |
| 160 | debug!( |
| 161 | "commit_at {:?}: [{:?}, {:?}) begin", |
| 162 | commit_ts, |
| 163 | txns_upper, |
| 164 | commit_ts.step_forward(), |
| 165 | ); |
| 166 | |
| 167 | let txn_batches_updates = FuturesUnordered::new(); |
| 168 | while let Some((data_id, updates)) = self.writes.pop_first() { |
| 169 | let data_write = handle.datas.take_write_for_commit(&data_id).unwrap_or_else( |
| 170 | || { |
| 171 | panic!( |
| 172 | "data shard {} must be registered with this Txn handle to commit", |
| 173 | data_id |
| 174 | ) |
| 175 | }, |
| 176 | ); |
no test coverage detected