nsivabalan opened a new pull request, #18237:
URL: https://github.com/apache/hudi/pull/18237
### Describe the issue this Pull Request addresses
Prevent duplicate clean operations in metadata table when data table commits
complete out of order. When commits are out of order, the metadata table may
attempt to execute the same clean operation multiple times with the same
instant time, leading to failures or inconsistent state. This is applicable
only to version6, since in version 8 and above, we always generate a new
instant time for cleans in mdt.
### Summary and Changelog
- Added getMetadataMetaClient() protected method in
HoodieBackedTableMetadataWriter to allow subclasses to access the metadata meta
client
- Modified executeClean() in
HoodieBackedTableMetadataWriterTableVersionSix to check if a clean instant
already exists in the completed
cleaner timeline before executing clean operation
- When a clean instant already exists, the operation is skipped with a log
message instead of attempting to execute it again
- Refactored timestamp creation methods (createCleanTimestamp,
createRestoreTimestamp, etc.) to be static in
HoodieBackedTableMetadataWriterTableVersionSix
- Made createCleanTimestamp visible for testing with @VisibleForTesting
annotation
- Updated cleanIfNecessary() to use the new getMetadataMetaClient() getter
method for consistency
- Scenario
When data table commits complete out of order:
1. Commit C3 completes first and MDT syncs, creating clean instant C3002
2. Commit C2 (started before C3) completes later
3. MDT re-attempts sync and may try to execute clean with the same instant
time C3002
4. Without this check, duplicate clean execution causes failures
This fix ensures idempotency by checking the timeline before executing
clean operations, similar to the existing checks for compaction and log
compaction operations in the same class.
Verification:
Added comprehensive unit tests in TestHoodieBackedTableMetadataWriter:
- testExecuteCleanWhenCleanInstantDoesNotExist() - Verifies clean
operation proceeds when instant doesn't exist
- testExecuteCleanWhenCleanInstantAlreadyExists() - Verifies clean
operation is skipped when instant already exists (prevents duplicate
in out-of-order scenarios)
- testCreateCleanTimestamp() - Tests the clean timestamp creation helper
method
- testCreateCleanTimestampWithMultipleValues() - Parameterized test for
timestamp formatting
### Impact
No failures when performing clean in mdt.
### Risk Level
low
### Documentation Update
<!-- Describe any necessary documentation update if there is any new
feature, config, or user-facing change. If not, put "none".
- The config description must be updated if new configs are added or the
default value of the configs are changed.
- Any new feature or user-facing change requires updating the Hudi website.
Please follow the
[instruction](https://hudi.apache.org/contribute/developer-setup#website)
to make changes to the website. -->
### Contributor's checklist
- [ ] Read through [contributor's
guide](https://hudi.apache.org/contribute/how-to-contribute)
- [ ] Enough context is provided in the sections above
- [ ] 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]