Fix external view does not remove old ones Local cached external view may not contains the one that idealstate, current states got removed. When controller switches, we shall read the external views from Helix at least once.
Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/73c3f0ad Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/73c3f0ad Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/73c3f0ad Branch: refs/heads/master Commit: 73c3f0ad81c4ef76cbd1e07d9368fe652099e56c Parents: 0f0d417 Author: Junkai Xue <j...@linkedin.com> Authored: Mon Oct 29 16:13:48 2018 -0700 Committer: Junkai Xue <j...@linkedin.com> Committed: Thu Nov 1 17:10:46 2018 -0700 ---------------------------------------------------------------------- .../controller/stages/ClusterDataCache.java | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/73c3f0ad/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java b/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java index 08e98cc..9311ca2 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java +++ b/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java @@ -87,8 +87,8 @@ public class ClusterDataCache extends AbstractDataCache { private Map<String, Map<String, String>> _idealStateRuleMap; private Map<String, Map<String, MissingTopStateRecord>> _missingTopStateMap = new HashMap<>(); private Map<String, Map<String, String>> _lastTopStateLocationMap = new HashMap<>(); - private Map<String, ExternalView> _targetExternalViewMap = new HashMap<>(); - private Map<String, ExternalView> _externalViewMap = new HashMap<>(); + private Map<String, ExternalView> _targetExternalViewMap; + private Map<String, ExternalView> _externalViewMap; private Map<String, Map<String, Set<String>>> _disabledInstanceForPartitionMap = new HashMap<>(); private Set<String> _disabledInstanceSet = new HashSet<>(); private String _eventId = "NO_ID"; @@ -261,6 +261,15 @@ public class ClusterDataCache extends AbstractDataCache { updateDisabledInstances(); + if (_externalViewMap == null) { + _externalViewMap = accessor.getChildValuesMap(accessor.keyBuilder().externalViews()); + } + + if (_clusterConfig.isTargetExternalViewEnabled() && _targetExternalViewMap == null) { + _targetExternalViewMap = + accessor.getChildValuesMap(accessor.keyBuilder().targetExternalViews()); + } + long endTime = System.currentTimeMillis(); LogUtil.logInfo(LOG, _eventId, "END: ClusterDataCache.refresh() for cluster " + getClusterName() + ", took " @@ -782,7 +791,7 @@ public class ClusterDataCache extends AbstractDataCache { } public ExternalView getTargetExternalView(String resourceName) { - return _targetExternalViewMap.get(resourceName); + return _targetExternalViewMap == null ? null : _targetExternalViewMap.get(resourceName); } public void updateTargetExternalView(String resourceName, ExternalView targetExternalView) { @@ -794,6 +803,9 @@ public class ClusterDataCache extends AbstractDataCache { * @return */ public Map<String, ExternalView> getExternalViews() { + if (_externalViewMap == null) { + return Collections.emptyMap(); + } return Collections.unmodifiableMap(_externalViewMap); } @@ -802,6 +814,9 @@ public class ClusterDataCache extends AbstractDataCache { * @param externalViews */ public void updateExternalViews(List<ExternalView> externalViews) { + if (_externalViewMap == null) { + _externalViewMap = new HashMap<>(); + } for (ExternalView externalView : externalViews) { _externalViewMap.put(externalView.getResourceName(), externalView); }