Skip to content

Scope concurrent delete-file conflicts by partition - #4508

Open
harshilv17 wants to merge 2 commits into
apache:mainfrom
harshilv17:fix/scope-delete-file-conflicts-by-partition
Open

harshilv17 wants to merge 2 commits into
apache:mainfrom
harshilv17:fix/scope-delete-file-conflicts-by-partition

Conversation

@harshilv17

Copy link
Copy Markdown

Closes #4507

Rationale for this change

On a commit retry, _validate_no_new_delete_files is called with partition_set=None, and _added_delete_files can only rule out a delete file by its column stats. Position deletes and deletion vectors have no stats on data columns, so a delete file committed concurrently in any partition fails a partition-filtered delete() or overwrite(). This shows up on tables shared with Spark or Flink merge-on-read writers. It was raised in the #3320 review and deferred with a code comment.

Java scopes this by partition: DeleteFileIndex.Builder projects the data filter onto each spec with Projections.inclusive(spec, caseSensitive) and filters delete manifest entries by partition. This change does the same in _added_delete_files: when a data_filter is given, it builds a per-spec evaluator from inclusive_projection + expression_evaluator (as DataScan._build_partition_evaluator does) and skips delete files whose partition can't match. A filter on non-partition columns projects to AlwaysTrue, so those delete files still count as conflicts. The comment deferring this in snapshot.py is removed.

Are these changes tested?

Yes. test_partition_filtered_write_validates_concurrent_position_delete_by_partition in tests/table/test_commit_retry.py commits a concurrent position delete (with the existing commit_partition_position_delete helper) in the written partition and in another one, for both delete and overwrite, on each catalog fixture. On main the other-partition cases fail with ValidationException: Found new conflicting delete files; with this change they succeed, and the same-partition cases still conflict.

test_added_delete_files_case_insensitive_filter used a mock delete file with partition=None on a table partitioned by x, which a real manifest can't contain; it now has partition=Record(1).

tests/table passes, and ruff and mypy are clean.

Are there any user-facing changes?

Yes: a delete() or overwrite() filtered to some partitions no longer fails its commit retry because another writer committed a delete file in an unrelated partition.

Commit validation checked concurrent delete files only against the data
filter's column metrics, which position deletes and deletion vectors
don't have for data columns, so any delete file committed in another
partition failed a partition-filtered delete or overwrite. Project the
data filter onto each delete file's spec, as Java's DeleteFileIndex
does, and skip delete files whose partition can't match.
@harshilv17

Copy link
Copy Markdown
Author

@lawofcycles could you take a look? This scopes the delete-file conflict check by partition, the follow-up deferred in #3320 (#3320 (comment)).

@harshilv17

Copy link
Copy Markdown
Author

@Fokko @kevinjqliu could one of you take a look when you have time? This scopes the concurrent delete-file conflict check by partition, the follow-up deferred in #3320. I have a stacked follow-up ready that also prunes manifests during validation.

@rahulsmahadev rahulsmahadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @harshilv17! This matches Java's DeleteFileIndex, and the new test fails on main and passes here. In 512 cases with real concurrent commits (identity, bucket, truncate and time transforms, null partitions, older and newly added specs, unpartitioned deletes), every concurrent delete of a row matching the filter still conflicted. LGTM.

A couple of smaller suggestions are inline, plus the changelog label, since users can see this.

Comment thread pyiceberg/table/update/validate.py Outdated

dfi = DeleteFileIndex()

# Delete files have no stats on the data columns, so only the partition can rule them out:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: equality deletes have stats on their equality columns, and position deletes have data-column stats when they store the deleted row, so the stats check below can still rule some out. Maybe "Position deletes and deletion vectors usually have no stats on the data columns, so also prune by partition: ...".

row_filter = data_filter

def _partition_evaluator(spec_id: int) -> Callable[[Record], bool]:
spec = table.specs()[spec_id]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing covers a delete file written under an older spec: with table.spec() here, tests/table still passes. A test that changes the spec (say identity on category to bucket on value) and then commits a delete under the old spec in another partition would pin it.

Cover a concurrent delete file written under a spec that is no longer
current, so validation must project the filter onto that file's spec.
Clarify the comment on why delete files are pruned by partition.
@harshilv17

Copy link
Copy Markdown
Author

Thanks @rahulsmahadev! Reworded the comment as suggested, and added test_partition_filtered_write_validates_concurrent_position_delete_under_older_spec: it moves the table from identity on category to bucket on value, then commits a delete under the old spec. It fails with table.spec() in place of the file's spec. I can't add labels. Could a committer add changelog?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commit retry rejects a partition-filtered delete/overwrite when a concurrent position delete lands in a different partition

2 participants