yihua opened a new issue, #20847:
URL: https://github.com/apache/hudi/issues/20847
### Bug Description
**What happened:**
With the record level index (global or partitioned), an `insert` or
`bulk_insert` whose batch repeats a record key fails deep inside the metadata
table write, with an error that does not say what to change:
- With streaming metadata writes (the Spark default), `RecordIndexMapper`
emits one index entry per written row and nothing reduces them by key, so the
job fails in the metadata table HFile writer: `HoodieDuplicateKeyException:
Duplicate key found for insert statement, key is: Duplicate recordKey 2 found
while writing to HFile.` This happens after the data files are written.
- With streaming metadata writes off, `HoodieTableMetadataUtil.reduceByKeys`
throws `HoodieIOException: Two HoodieRecord updates to the index is seen for
same record key 2, record 1 : HoodieRecord{...}`.
In both modes the data instant does not complete (the failure is before the
data commit), so this is an error-reporting problem, not data loss.
**What you expected:**
The record level index holds one location per key, so refusing the write is
right. It should fail before any record index entry is written, with a message
that names the key and how to avoid it (`hoodie.combine.before.insert=true`, or
`upsert`). The streaming path could run the same reduce-by-key the
non-streaming record index update and the streaming secondary index update
already run.
A related gap: with streaming off, the non-streaming record index update
reads keys from each written file into a set, so two copies of a key that land
in the same file group are not detected and the commit succeeds.
**Steps to reproduce:**
1. `create table t (id int, name string, dt string) using hudi partitioned
by (dt) tblproperties (primaryKey = 'id', type = 'mor')` with
`hoodie.index.type=RECORD_INDEX` and
`hoodie.metadata.global.record.level.index.enable=true`.
2. `insert into t values (1, 'a', 'p1'), (1, 'b', 'p1'), (2, 'c', 'p1')`.
3. The insert fails with the HFile duplicate key error above.
### Environment
**Hudi version:** master (1.3.0-SNAPSHOT)
**Query engine:** Spark 3.5
**Relevant configs:** `hoodie.index.type=RECORD_INDEX`,
`hoodie.metadata.global.record.level.index.enable=true`,
`hoodie.metadata.streaming.write.enabled` true or false
### Logs and Stack Trace
```
org.apache.hudi.exception.HoodieDuplicateKeyException: Duplicate key found
for insert statement, key is: Duplicate recordKey 1 found while writing to
HFile.
at org.apache.hudi.io.storage.hadoop.HoodieAvroHFileWriter.writeAvro
```
--
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]