MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / commit_at

Method commit_at

src/txn-wal/src/txn_write.rs:119–340  ·  view source on GitHub ↗
(
        &mut self,
        handle: &mut TxnsHandle<K, V, T, D, C>,
        commit_ts: T,
    )

Source from the content-addressed store, hash-verified

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 );

Callers 5

commit_atFunction · 0.45
apply_and_tidyFunction · 0.45
conflicting_writesFunction · 0.45
commit_retryFunction · 0.45

Calls 15

cloneFunction · 0.85
small_caaFunction · 0.85
expectMethod · 0.80
shared_upperMethod · 0.80
take_write_for_commitMethod · 0.80
encode_to_vecMethod · 0.80
filter_retractionsMethod · 0.80
read_cacheMethod · 0.80
into_hollow_batchMethod · 0.80
inc_byMethod · 0.80
put_write_for_commitMethod · 0.80

Tested by

no test coverage detected