yihua opened a new issue, #20812:
URL: https://github.com/apache/hudi/issues/20812

   Metadata table writes can fail at random on Spark executors with 
`ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7` in 
`HoodieMetadataPayload.getInsertValue`, called from 
`HoodieAvroRecord.prependMetaFields` in the append handle while writing the 
`files` partition. It affects 1.2.0, 1.2.1 and master.
   
   `getInsertValue` returns the generated record only when the schema is the 
same object as `HoodieMetadataRecord.getClassSchema()` (#17672). Any other 
schema goes to a branch that writes at meta-field offsets, which the metadata 
schema doesn't have. The append handle gets its schema from 
`HoodieSchemaCache.intern(HoodieSchema.parse(config.getWriteSchema()))`, and 
the cache keeps whichever equal schema is interned first in the JVM:
   - `HoodieMetadataPayload` already initialized (driver, local mode): the 
cache holds the `SCHEMA$` wrapper, and the check passes.
   - Handle constructed first (an executor whose first metadata work is this 
write, since `handleUpdate` creates the handle before reading any record): the 
cache holds the parsed copy, `HoodieMetadataPayload` interns into that copy 
when it loads, and every metadata log write on that executor fails until it 
exits.
   
   Repro against `hudi-spark3.5-bundle_2.12-1.2.1.jar` in a fresh JVM. It 
prints `HoodieMetadataRecord` with `payload-first` and throws the exception 
without it:
   
   ```java
   public static void main(String[] args) throws Exception {
     if (args.length > 0 && args[0].equals("payload-first")) {
       Class.forName(HoodieMetadataPayload.class.getName());
     }
     // HoodieWriteHandle's constructor
     HoodieSchema writeSchema = 
HoodieSchemaCache.intern(HoodieSchema.parse(HoodieMetadataRecord.getClassSchema().toString()));
     HoodieRecord<HoodieMetadataPayload> record = 
HoodieMetadataPayload.createPartitionListRecord(Collections.singletonList("p1"));
     // HoodieAvroRecord.prependMetaFields
     
System.out.println(record.getData().getInsertValue(writeSchema.toAvroSchema()).get().getClass().getSimpleName());
   }
   ```
   
   Proposal: take the generated-record path for any schema that is the metadata 
record schema, not only that one object. #19560, the fix for #19559 (a 
different trigger of the same branch), checks the record name and would cover 
this case too. `testInsertValueFastPathOnlyForClassSchema` in 
`TestHoodieMetadataPayload` currently expects this exception for an equal copy 
and would need to change.
   


-- 
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]

Reply via email to