MCPcopy Create free account
hub / github.com/apache/paimon-rust / try_commit

Method try_commit

crates/paimon/src/table/table_commit.rs:292–347  ·  view source on GitHub ↗

Try to commit with retries.

(&self, plan: CommitEntriesPlan)

Source from the content-addressed store, hash-verified

290
291 /// Try to commit with retries.
292 async fn try_commit(&self, plan: CommitEntriesPlan) -> Result<()> {
293 let mut retry_count = 0u32;
294 let mut last_snapshot_for_dup_check: Option<Snapshot> = None;
295 let start_time_ms = current_time_millis();
296
297 loop {
298 let latest_snapshot = self.snapshot_manager.get_latest_snapshot().await?;
299 let resolved = self.resolve_commit(&plan, &latest_snapshot).await?;
300
301 if resolved.entries.is_empty() {
302 break;
303 }
304
305 // Check for duplicate commit (idempotency on retry)
306 if self
307 .is_duplicate_commit(
308 &last_snapshot_for_dup_check,
309 &latest_snapshot,
310 &resolved.kind,
311 )
312 .await
313 {
314 break;
315 }
316
317 let result = self.try_commit_once(resolved, &latest_snapshot).await?;
318
319 match result {
320 true => break,
321 false => {
322 last_snapshot_for_dup_check = latest_snapshot;
323 }
324 }
325
326 let elapsed_ms = current_time_millis() - start_time_ms;
327 if elapsed_ms > self.commit_timeout_ms || retry_count >= self.commit_max_retries {
328 let snap_id = last_snapshot_for_dup_check
329 .as_ref()
330 .map(|s| s.id() + 1)
331 .unwrap_or(1);
332 return Err(crate::Error::DataInvalid {
333 message: format!(
334 "Commit failed for snapshot {} after {} millis with {} retries, \
335 there may exist commit conflicts between multiple jobs.",
336 snap_id, elapsed_ms, retry_count
337 ),
338 source: None,
339 });
340 }
341
342 self.commit_retry_wait(retry_count).await;
343 retry_count += 1;
344 }
345
346 Ok(())
347 }
348
349 /// Single commit attempt.

Callers 4

commitMethod · 0.80
overwriteMethod · 0.80
truncate_partitionsMethod · 0.80
truncate_tableMethod · 0.80

Calls 8

current_time_millisFunction · 0.85
get_latest_snapshotMethod · 0.80
resolve_commitMethod · 0.80
is_duplicate_commitMethod · 0.80
try_commit_onceMethod · 0.80
commit_retry_waitMethod · 0.80
is_emptyMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected