Indian-boult opened a new pull request, #20779:
URL: https://github.com/apache/hudi/pull/20779
### Describe the issue this Pull Request addresses
Closes #20017
A binary copy that fails after copying some of its inputs leaves its output
file behind. `HoodieBinaryCopyHandle` releases the copier with `close()`, which
writes the Parquet footer, so the file is readable and holds the row groups
copied so far. The handle never created a write marker, unlike
`HoodieCreateHandle` and `ExternalFileClusteringWriteHandle`, so neither the
marker reconciliation at commit (`HoodieTable#reconcileAgainstMarkers`) nor the
marker-based rollback knew about the file.
`SparkBinaryCopyClusteringExecutionStrategy` picks a new file ID in each task
attempt, so the file is a file group of its own, with the clustering instant
time.
Repro on master: COW table, metadata table off, two base files of 30 records
in one partition, one clustering group, and the copy failing while it
prefetches the second input (`Failed to retrieve prefetched content for ...`).
Same result with direct and timeline-server-based markers.
| | Spark retries the task | the clustering fails and is run again |
| --- | --- | --- |
| failed attempt's file | 30 rows, the first input's keys | same |
| what removes it on master | nothing: the commit finds no marker | nothing:
the rollback of the inflight instant finds no marker, and the new run commits
under the same instant time |
| read with the metadata table off, after the commit | 90 rows, 60 distinct
keys | 90 rows, 60 distinct keys |
| `clean()` with `KEEP_LATEST_FILE_VERSIONS`, 1 version | deletes the two
replaced inputs, keeps the failed attempt's file (the only slice of its file
group) | same |
| with this PR | the commit deletes the file; 60 rows; only the committed
file is left after `clean()` | the rollback deletes the file; 60 rows; only the
committed file is left after `clean()` |
With the metadata table on, the file is not in the files partition, so reads
skip it, but nothing deletes it either. A metadata table initialized later from
a listing would add it, since `DirectoryInfo` keeps data files of completed
instants (code read, not tested).
### Summary and Changelog
Binary-copy clustering now creates a marker for its output file, as the
other write handles do. The file of a failed or retried copy attempt is deleted
when the clustering commits, or when its inflight instant is rolled back, so
reads without the metadata table no longer return its rows and it no longer
outlives the cleaner.
- `HoodieBinaryCopyHandle`: the constructor calls
`createMarkerFile(partitionPath, path.getName())` (IO type `CREATE`) before the
copier creates the file, as `ExternalFileClusteringWriteHandle` does. Direct
and timeline-server-based markers both go through `WriteMarkersFactory`. A doc
comment on `closeWriterQuietly` says that the closed file stays readable until
the commit or the rollback deletes it.
- Tests:
-
`TestHoodieBinaryCopyHandle#testConstructorCreatesMarkerBeforeOutputFile`: the
constructor creates exactly `partition/<file>.marker.CREATE`, and not the
output file. The existing failure test now uses direct markers, since the
default timeline-server-based markers need a running server.
-
`TestSparkBinaryCopyClusteringAndValidationMeta#testFailedCopyAttemptIsDeletedWhenTaskIsRetried`,
for both marker types, on Spark `local[2,2]` so the task is retried once: the
clustering instant wrote only the committed file, a read with the metadata
table off returns each of the 60 records once, and after `clean()` the
committed file is the only base file in the partition.
-
`TestSparkBinaryCopyClusteringAndValidationMeta#testFailedCopyAttemptIsRolledBackWhenClusteringIsRetried`,
for both marker types: the first run fails on the second input, and its file
holds exactly the first input's record keys. The second run rolls back,
commits, and passes the same checks.
- `FailSecondInputOnceStrategy`, a test subclass of
`SparkBinaryCopyClusteringExecutionStrategy`: in the clustering task, right
before the copy handle is created, it renames the second input away, and a task
failure listener renames it back.
- On master, the four new functional tests fail at `the failed attempt's
file must be deleted`, and the handle test finds no marker.
### Impact
Binary-copy clustering (`SparkBinaryCopyClusteringExecutionStrategy` and
`SparkStreamCopyClusteringExecutionStrategy`, COW only) writes one marker per
output file. A failed copy attempt no longer leaves a file that listing readers
return and the cleaner keeps. No public API or config change.
### Risk Level
low. One marker per clustering group, created the same way as for
`HoodieCreateHandle`. Nothing changes when the copy succeeds. When an attempt
fails, its file is now handled as for the other handles: the commit deletes it
(or fails, with `hoodie.fail.job.on.duplicate.data.file.detection=true`), and
the rollback deletes it. As for the other handles, markers do not cover an
attempt that publishes its file after the commit, for ex a killed attempt that
closes it on S3A (#20657).
### Documentation Update
none
### Contributor's checklist
- [x] Read through [contributor's
guide](https://hudi.apache.org/contribute/how-to-contribute)
- [x] Enough context is provided in the sections above
- [x] Adequate tests were added if applicable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]