Repository navigation
DEL-2538: Add metric for commit conflicts in ingestor #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| use std::sync::{Arc, OnceLock}; | ||
|
|
||
| use url::Url; | ||
|
|
||
| use super::CommitConflictError; | ||
|
|
||
| /// What the commit loop did after another writer committed first. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum CommitConflictOutcome { | ||
| /// The target log version already existed. The loop tries the next version. | ||
| Retry, | ||
| /// A newer commit passed the conflict check. The loop moves its snapshot forward. | ||
| Rebase, | ||
| /// A newer commit failed the conflict check. The loop returns the error. | ||
| Abort, | ||
| /// The loop used every attempt, or retries were disabled. | ||
| Exhausted, | ||
| } | ||
|
|
||
| /// One commit-conflict event from the commit retry loop. | ||
| #[derive(Debug)] | ||
| pub struct CommitConflictEvent<'a> { | ||
| /// Root URL of the Delta table, including the table name as the last path segment. | ||
| pub table_url: &'a Url, | ||
| /// [`crate::protocol::DeltaOperation::name`] of the commit that lost the race. | ||
| pub operation: &'a str, | ||
| /// `commitInfo.operation` of the commit that won. Absent for a lost put, because | ||
| /// that attempt has not read the winning commit yet. | ||
| pub winner_operation: Option<&'a str>, | ||
| pub outcome: CommitConflictOutcome, | ||
| /// Set only when `outcome` is [`CommitConflictOutcome::Abort`]. | ||
| pub error: Option<&'a CommitConflictError>, | ||
| } | ||
|
|
||
| /// Receives commit-conflict events. The Delta library does not record metrics itself. | ||
| pub trait CommitConflictObserver: Send + Sync { | ||
| fn on_commit_conflict(&self, event: &CommitConflictEvent<'_>); | ||
| } | ||
|
|
||
| static OBSERVER: OnceLock<Arc<dyn CommitConflictObserver>> = OnceLock::new(); | ||
|
|
||
| /// Installs the process-wide observer. Returns `false` when one is already installed. | ||
| pub fn set_commit_conflict_observer(observer: Arc<dyn CommitConflictObserver>) -> bool { | ||
| OBSERVER.set(observer).is_ok() | ||
| } | ||
|
|
||
| pub(crate) fn notify(event: &CommitConflictEvent<'_>) { | ||
| if let Some(observer) = OBSERVER.get() { | ||
| observer.on_commit_conflict(event); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use std::sync::Mutex; | ||
|
|
||
| struct Counter(Mutex<u32>); | ||
|
|
||
| impl CommitConflictObserver for Counter { | ||
| fn on_commit_conflict(&self, event: &CommitConflictEvent<'_>) { | ||
| assert_eq!(event.operation, "WRITE"); | ||
| assert_eq!(event.outcome, CommitConflictOutcome::Retry); | ||
| *self.0.lock().unwrap() += 1; | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn installed_observer_counts_one_notification() { | ||
| let counter = Arc::new(Counter(Mutex::new(0))); | ||
| assert!(set_commit_conflict_observer(counter.clone())); | ||
| let table_url = Url::parse("s3://bucket/acme/traces_v2").unwrap(); | ||
| notify(&CommitConflictEvent { | ||
| table_url: &table_url, | ||
| operation: "WRITE", | ||
| winner_operation: None, | ||
| outcome: CommitConflictOutcome::Retry, | ||
| error: None, | ||
| }); | ||
| assert_eq!(*counter.0.lock().unwrap(), 1); | ||
| assert!(!set_commit_conflict_observer(counter)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create-race conflict skips observer
Low Severity
A lost race on the initial version-0 put is a
VersionAlreadyExistsretry, but it never callsnotify_commit_conflict. The handler still consumes an attempt and continues the retry loop, so table-creation conflicts are omitted from observer counts that the other version-already-exists path records.Additional Locations (1)
crates/core/src/kernel/transaction/mod.rs#L981-L989Reviewed by Cursor Bugbot for commit 754c915. Configure here.