Skip to content

Commit

Permalink
Fix WAGED to only use logicalId when computing baseline and centraliz…
Browse files Browse the repository at this point in the history
…e picking assignable instances in the cache. (#2702)

Fix WAGED to only use logicalId when computing baseline and centralize picking assignable instances in the cache.
  • Loading branch information
zpinto authored and Xiaoyuan Lu committed Dec 8, 2023
1 parent 465f323 commit a24ed72
Show file tree
Hide file tree
Showing 62 changed files with 757 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ private void clearCachedComputation() {
HelixConstants.ChangeType changeType, ResourceChangeSnapshot snapshot) {
switch (changeType) {
case INSTANCE_CONFIG:
return snapshot.getInstanceConfigMap();
return snapshot.getAssignableInstanceConfigMap();
case IDEAL_STATE:
return snapshot.getIdealStateMap();
case RESOURCE_CONFIG:
return snapshot.getResourceConfigMap();
case LIVE_INSTANCE:
return snapshot.getLiveInstances();
return snapshot.getAssignableLiveInstances();
case CLUSTER_CONFIG:
ClusterConfig config = snapshot.getClusterConfig();
if (config == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,25 @@
class ResourceChangeSnapshot {

private Set<HelixConstants.ChangeType> _changedTypes;
private Map<String, InstanceConfig> _instanceConfigMap;
private Map<String, InstanceConfig> _allInstanceConfigMap;
private Map<String, InstanceConfig> _assignableInstanceConfigMap;
private Map<String, IdealState> _idealStateMap;
private Map<String, ResourceConfig> _resourceConfigMap;
private Map<String, LiveInstance> _liveInstances;
private Map<String, LiveInstance> _allLiveInstances;
private Map<String, LiveInstance> _assignableLiveInstances;
private ClusterConfig _clusterConfig;

/**
* Default constructor that constructs an empty snapshot.
*/
ResourceChangeSnapshot() {
_changedTypes = new HashSet<>();
_instanceConfigMap = new HashMap<>();
_allInstanceConfigMap = new HashMap<>();
_assignableInstanceConfigMap = new HashMap<>();
_idealStateMap = new HashMap<>();
_resourceConfigMap = new HashMap<>();
_liveInstances = new HashMap<>();
_allLiveInstances = new HashMap<>();
_assignableLiveInstances = new HashMap<>();
_clusterConfig = null;
}

Expand All @@ -80,12 +84,16 @@ class ResourceChangeSnapshot {
ResourceChangeSnapshot(ResourceControllerDataProvider dataProvider,
boolean ignoreNonTopologyChange) {
_changedTypes = new HashSet<>(dataProvider.getRefreshedChangeTypes());

_instanceConfigMap = ignoreNonTopologyChange ?
_allInstanceConfigMap = ignoreNonTopologyChange ?
dataProvider.getInstanceConfigMap().entrySet().parallelStream().collect(Collectors
.toMap(e -> e.getKey(),
e -> InstanceConfigTrimmer.getInstance().trimProperty(e.getValue()))) :
new HashMap<>(dataProvider.getInstanceConfigMap());
_assignableInstanceConfigMap = ignoreNonTopologyChange ?
dataProvider.getAssignableInstanceConfigMap().entrySet().parallelStream().collect(Collectors
.toMap(e -> e.getKey(),
e -> InstanceConfigTrimmer.getInstance().trimProperty(e.getValue()))) :
new HashMap<>(dataProvider.getAssignableInstanceConfigMap());
_idealStateMap = ignoreNonTopologyChange ?
dataProvider.getIdealStates().entrySet().parallelStream().collect(Collectors
.toMap(e -> e.getKey(),
Expand All @@ -99,7 +107,8 @@ class ResourceChangeSnapshot {
_clusterConfig = ignoreNonTopologyChange ?
ClusterConfigTrimmer.getInstance().trimProperty(dataProvider.getClusterConfig()) :
dataProvider.getClusterConfig();
_liveInstances = new HashMap<>(dataProvider.getLiveInstances());
_allLiveInstances = new HashMap<>(dataProvider.getLiveInstances());
_assignableLiveInstances = new HashMap<>(dataProvider.getAssignableLiveInstances());
}

/**
Expand All @@ -108,10 +117,12 @@ class ResourceChangeSnapshot {
*/
ResourceChangeSnapshot(ResourceChangeSnapshot snapshot) {
_changedTypes = new HashSet<>(snapshot._changedTypes);
_instanceConfigMap = new HashMap<>(snapshot._instanceConfigMap);
_allInstanceConfigMap = new HashMap<>(snapshot._allInstanceConfigMap);
_assignableInstanceConfigMap = new HashMap<>(snapshot._assignableInstanceConfigMap);
_idealStateMap = new HashMap<>(snapshot._idealStateMap);
_resourceConfigMap = new HashMap<>(snapshot._resourceConfigMap);
_liveInstances = new HashMap<>(snapshot._liveInstances);
_allLiveInstances = new HashMap<>(snapshot._allLiveInstances);
_assignableLiveInstances = new HashMap<>(snapshot._assignableLiveInstances);
_clusterConfig = snapshot._clusterConfig;
}

Expand All @@ -120,7 +131,11 @@ Set<HelixConstants.ChangeType> getChangedTypes() {
}

Map<String, InstanceConfig> getInstanceConfigMap() {
return _instanceConfigMap;
return _allInstanceConfigMap;
}

Map<String, InstanceConfig> getAssignableInstanceConfigMap() {
return _assignableInstanceConfigMap;
}

Map<String, IdealState> getIdealStateMap() {
Expand All @@ -132,7 +147,11 @@ Map<String, ResourceConfig> getResourceConfigMap() {
}

Map<String, LiveInstance> getLiveInstances() {
return _liveInstances;
return _allLiveInstances;
}

Map<String, LiveInstance> getAssignableLiveInstances() {
return _assignableLiveInstances;
}

ClusterConfig getClusterConfig() {
Expand Down
Loading

0 comments on commit a24ed72

Please sign in to comment.