voonhous commented on code in PR #18967:
URL: https://github.com/apache/hudi/pull/18967#discussion_r3407809233
##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java:
##########
@@ -1153,7 +1155,11 @@ public List<HoodieSchemaField> getFields() {
throw new IllegalStateException("Cannot get fields from schema type: " +
type);
}
if (fields == null) {
- fields =
Collections.unmodifiableList(avroSchema.getFields().stream().map(HoodieSchemaField::new).collect(Collectors.toList()));
+ synchronized (this) {
Review Comment:
Good point - dropped the `synchronized` double-checked locking in both
`getFields()` and `getFieldMap()` for a benign racy single-check. Since the
cached value is an immutable, deterministic view of the schema fields,
concurrent first-callers may each build it once but converge on equal results.
I kept the `volatile` on `fields`/`fieldMap` so the unmodifiable collections
(which wrap a non-final-field ArrayList/HashMap) are still published safely on
weak memory models - that avoids a reader ever seeing a partially-constructed
collection.
--
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]