qqu0127 commented on code in PR #2289:
URL: https://github.com/apache/helix/pull/2289#discussion_r1028524870
##########
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/AssignmentMetadataStore.java:
##########
@@ -61,36 +62,42 @@ protected AssignmentMetadataStore(BucketDataAccessor
bucketDataAccessor, String
_bestPossiblePath = String.format(BEST_POSSIBLE_TEMPLATE, clusterName,
ASSIGNMENT_METADATA_KEY);
}
- public synchronized Map<String, ResourceAssignment> getBaseline() {
+ public Map<String, ResourceAssignment> getBaseline() {
// Return the in-memory baseline. If null, read from ZK. This is to
minimize reads from ZK
if (_globalBaseline == null) {
- try {
- HelixProperty baseline =
- _dataAccessor.compressedBucketRead(_baselinePath,
HelixProperty.class);
- _globalBaseline = splitAssignments(baseline);
- } catch (ZkNoNodeException ex) {
- // Metadata does not exist, so return an empty map
- _globalBaseline = new HashMap<>();
+ // double-checked locking
+ synchronized (this) {
+ if (_globalBaseline == null) {
+ _globalBaseline = fetchAssignmentOrDefault(_baselinePath);
+ }
}
}
return _globalBaseline;
}
- public synchronized Map<String, ResourceAssignment>
getBestPossibleAssignment() {
+ public Map<String, ResourceAssignment> getBestPossibleAssignment() {
// Return the in-memory baseline. If null, read from ZK. This is to
minimize reads from ZK
if (_bestPossibleAssignment == null) {
- try {
- HelixProperty baseline =
- _dataAccessor.compressedBucketRead(_bestPossiblePath,
HelixProperty.class);
- _bestPossibleAssignment = splitAssignments(baseline);
- } catch (ZkNoNodeException ex) {
- // Metadata does not exist, so return an empty map
- _bestPossibleAssignment = new HashMap<>();
+ // double-checked locking
+ synchronized (this) {
+ if (_bestPossibleAssignment == null) {
+ _bestPossibleAssignment =
fetchAssignmentOrDefault(_bestPossiblePath);
+ }
}
}
return _bestPossibleAssignment;
}
+ private Map<String, ResourceAssignment> fetchAssignmentOrDefault(String
path) {
+ try {
Review Comment:
Thanks for the comment, but why this has to be synchronized? it's a read
operation
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]