danny0405 opened a new pull request, #20734:
URL: https://github.com/apache/hudi/pull/20734

   ### Describe the issue this Pull Request addresses
   
   issue: #20685
   
   `HoodieMergedLogRecordScanner.processNextRecord()` uses the static 
field-accessor `AvroRecordContext` while constructing buffered records and 
invoking the merger. These operations register schemas in the context's 
`LocalHoodieSchemaCache`, so separate scanners share mutable schema-ID state 
despite both the scanner and the cache being documented as not thread-safe. 
Concurrent scanners in the same JVM/classloader can therefore race on that 
cache.
   
   This fixes the scanner's ownership violation discussed in 
https://github.com/apache/hudi/issues/20685#issuecomment-6969462862. It does 
not claim that RFC-118 requires a shared cache or resolve every possible 
singleton-context caller.
   
   ### Summary and Changelog
   
   - Allocate one `AvroRecordContext` per scanner and reuse it across record 
merges, keeping schema IDs and their lifetime local to the scanner.
   - Add a deterministic regression test through `processNextRecord()` that 
checks context isolation between scanners, reuse within one scanner, 
independent schema-ID namespaces, schema resolution during merging, and the 
resulting records.
   - No code was copied from other projects.
   
   ### Impact
   
   The log-scanner merge path no longer shares its schema cache with other 
scanners or retains those schemas through the static context. Each scanner 
allocates one lightweight context. Public APIs, storage format, and the 
`LocalHoodieSchemaCache` contract are unchanged.
   
   ### Risk Level
   
   low: the scanner retains the same default Avro context behavior, with 
ownership changed from static to per-instance.
   
   Validation on JDK 17:
   - `TestHoodieMergedLogRecordScanner`, `TestHoodieMergedLogRecordReader`, and 
`TestLocalHoodieSchemaCache`: 7 tests passed.
   - The new regression test fails against the original scanner at the 
context-isolation assertion and passes with the fix. This is a deterministic 
ownership regression test, not a reproduction of a production concurrency 
failure.
   - Maven Checkstyle and Apache RAT checks passed for the selected reactor.
   
   Command: `mvn -o -pl hudi-common -am test -Punit-tests 
-Dtest=TestHoodieMergedLogRecordScanner,TestHoodieMergedLogRecordReader,TestLocalHoodieSchemaCache
 -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false -B`
   
   ### Documentation Update
   
   none: internal ownership fix; a source comment explains why the context must 
belong to the scanner.
   
   ### 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]

Reply via email to