yihua opened a new pull request, #20852: URL: https://github.com/apache/hudi/pull/20852
### Describe the issue this Pull Request addresses closes #20847 With the record level index and streaming metadata writes (the Spark default), an insert or bulk_insert whose batch repeats a record key fails inside the metadata table HFile writer with `Duplicate key found for insert statement, key is: Duplicate recordKey 2 found while writing to HFile.`, and the non-streaming path fails with `Two HoodieRecord updates to the index is seen for same record key ...`. Neither says what to change. ### Summary and Changelog `RecordIndexMapper.postProcess` now runs `HoodieTableMetadataUtil.reduceByKeys` on the streaming record index entries, as `SecondaryIndexMapper` and the non-streaming record index update already do. A repeated key now fails in that reduce, before any record index entry is written and before the data commit, and the error is rewritten as a `HoodieMetadataException` that names the key and the metadata partition and suggests `hoodie.combine.before.insert=true` or upsert. The reduce honors the partitioned record level index, so the same key in two partitions stays two entries there. The new `TestRecordIndexRepeatedKeys` covers insert and bulk_insert, COW and MOR, streaming on and off, and the global and partitioned index; its failing cases fail on master with the two messages above. `TestMetadataIndexMapper` adds unit tests for the reduce. Not changed here: the non-streaming path still accepts two copies that land in one file group (noted in #20847), and #20848 tracks inserts of a key that an earlier commit already wrote. ### Impact A repeated key under the record level index fails with a clear message instead of the HFile error. Streaming writes with the record level index pay one extra shuffle of the record index entries (inserts and deletes only, not updates), the same cost the non-streaming path and the streaming secondary index already pay. ### Risk Level low. Valid writes produce the same record index entries; the existing global index partition-move suites pass unchanged. ### Documentation Update none ### 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]
