You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2021/04/14 19:08:41 UTC
[GitHub] [helix] dasahcc commented on a change in pull request #1697: Directly use Best Possible State to calculate DifferenceWithIdealStateGauge metrics instead of relying on the persisted IdealState.
dasahcc commented on a change in pull request #1697:
URL: https://github.com/apache/helix/pull/1697#discussion_r613518461
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/PersistAssignmentStage.java
##########
@@ -128,25 +130,30 @@ private void persistAssignment(final Resource resource, final ResourceController
if (assignmentToPersist != null && hasInstanceMapChanged(assignmentToPersist, idealState)) {
for (Partition partition : assignmentToPersist.keySet()) {
Map<String, String> instanceMap = assignmentToPersist.get(partition);
- idealState.setInstanceStateMap(partition.getPartitionName(), instanceMap);
+ delta.setInstanceStateMap(partition.getPartitionName(), instanceMap);
}
needPersist = true;
}
if (needPersist) {
// Update instead of set to ensure any intermediate changes that the controller does not update are kept.
- accessor.updateProperty(keyBuilder.idealStates(resourceId), new DataUpdater<ZNRecord>() {
- @Override
- public ZNRecord update(ZNRecord current) {
- if (current != null) {
- // Overwrite MapFields and ListFields items with the same key.
- // Note that default merge will keep old values in the maps or lists unchanged, which is not desired.
+ accessor.updateProperty(keyBuilder.idealStates(resourceId), current -> {
+ if (current != null) {
+ ZNRecord deltaRecord = delta.getRecord();
+ // Overwrite MapFields and ListFields items with the same key.
+ if (!deltaRecord.getMapFields().isEmpty()) {
+ // Note that default merge will keep old values in the maps unchanged, which is not desired.
current.getMapFields().clear();
- current.getMapFields().putAll(idealState.getRecord().getMapFields());
- current.getListFields().putAll(idealState.getRecord().getListFields());
+ current.getMapFields().putAll(deltaRecord.getMapFields());
+ }
+ if (!deltaRecord.getListFields().isEmpty()) {
Review comment:
Question: why we need this check? We can add lists field anyway just not clear it up, right?
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -205,7 +205,9 @@ private void refreshExternalViews(final HelixDataAccessor accessor) {
// As we are not listening on external view change, external view will be
// refreshed once during the cache's first refresh() call, or when full refresh is required
if (_propertyDataChangedMap.get(HelixConstants.ChangeType.EXTERNAL_VIEW).getAndSet(false)) {
- _externalViewCache.refresh(accessor);
+ synchronized (_externalViewCache) {
+ _externalViewCache.refresh(accessor);
Review comment:
NIT: why not just put sychronized keyword on the method?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org