-
Notifications
You must be signed in to change notification settings - Fork 475
fix(transaction): detect duplicate file paths within a single FastAppend batch #2509
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,11 +164,28 @@ impl<'a> SnapshotProducer<'a> { | |
| } | ||
|
|
||
| pub(crate) async fn validate_duplicate_files(&self) -> Result<()> { | ||
| let new_files: HashSet<&str> = self | ||
| .added_data_files | ||
| .iter() | ||
| .map(|df| df.file_path.as_str()) | ||
| .collect(); | ||
| // First, detect duplicate file paths within the batch itself. | ||
| // Collecting straight into a `HashSet` would silently deduplicate | ||
| // and pass corruption through to the manifest, so we walk the list | ||
| // explicitly and surface every distinct duplicated path. | ||
| let mut new_files: HashSet<&str> = HashSet::with_capacity(self.added_data_files.len()); | ||
| let mut duplicates_in_batch: HashSet<&str> = HashSet::new(); | ||
|
Comment on lines
+171
to
+172
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is over complicated, we should throw error immediately when
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I prefer to move this check in the begigning of |
||
| for data_file in &self.added_data_files { | ||
| if !new_files.insert(data_file.file_path.as_str()) { | ||
| duplicates_in_batch.insert(data_file.file_path.as_str()); | ||
| } | ||
| } | ||
| if !duplicates_in_batch.is_empty() { | ||
| let mut paths: Vec<&str> = duplicates_in_batch.into_iter().collect(); | ||
| paths.sort_unstable(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious to know if we need the sort? |
||
| return Err(Error::new( | ||
| ErrorKind::DataInvalid, | ||
| format!( | ||
| "Cannot add duplicate file paths within the same commit: {}", | ||
| paths.join(", ") | ||
| ), | ||
| )); | ||
| } | ||
|
|
||
| let mut referenced_files = Vec::new(); | ||
| if let Some(current_snapshot) = self.table.metadata().current_snapshot() { | ||
|
|
||
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.
This comment is maybe a little verbose?