Davis-Zhang-Onehouse opened a new pull request, #20686:
URL: https://github.com/apache/hudi/pull/20686

   ### Describe the issue this Pull Request addresses
   
   issue: #20685
   Part of #20683, RFC-118 (#20684). First PR of the RFC-118 chain; it is 
independent of the rest and can be reviewed on its own.
   
   `LocalHoodieSchemaCache` (hudi-common) uses two unsynchronized `HashMap`s 
and an unguarded `nextVersionId++`. A cache shared by threads can lose entries, 
give one schema two ids, or publish the schema-to-id entry before the 
id-to-schema entry, so a concurrent lookup by that id returns empty.
   
   ### Summary and Changelog
   
   Makes `LocalHoodieSchemaCache` thread-safe.
   
   - Both maps are `ConcurrentHashMap`s. A hit is still a single lock-free map 
read.
   - A miss issues its id under one lock, including the id of the null schema 
(kept in a field, since a concurrent map has no null keys). The id-to-schema 
entry is published before the schema-to-id entry.
   - Java serialization runs under the same lock. A lookup by a null id still 
returns empty.
   - The class is annotated `@ThreadSafe` instead of `@NotThreadSafe`. The 
`create()` factory is unchanged.
   - `TestLocalHoodieSchemaCache` adds concurrent registration and lookup, 
stable ids, independent caches from `create()`, and a serialization round trip.
   
   No code was copied from other projects.
   
   ### Impact
   
   No public API change. Removes a race for callers that share one cache across 
threads. The uncontended path costs the same as before.
   
   ### Risk Level
   
   low: the change is local to one class and keeps its API. The new concurrency 
test fails on master in each of four runs and passes with the fix. 
`TestLocalHoodieSchemaCache` (6 tests), checkstyle and RAT pass on JDK 11.
   
   ### Documentation Update
   
   none
   
   ### 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