You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ji...@apache.org on 2020/04/23 19:27:58 UTC
[helix] 12/23: update cache functions for customized view
aggregation (#887)
This is an automated email from the ASF dual-hosted git repository.
jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
commit eeeab152355e48738d9e69fe6329053ba081d054
Author: zhangmeng916 <56...@users.noreply.github.com>
AuthorDate: Thu Mar 12 10:07:23 2020 -0700
update cache functions for customized view aggregation (#887)
Update some cache functions for customized view aggregation
---
.../main/java/org/apache/helix/ConfigAccessor.java | 2 +-
.../main/java/org/apache/helix/PropertyKey.java | 6 +++---
.../java/org/apache/helix/PropertyPathBuilder.java | 24 ++++++++++++++++++++--
.../CustomizedStateConfigChangeListener.java | 4 ++--
.../helix/common/caches/CustomizedStateCache.java | 17 +++++++--------
.../helix/common/caches/CustomizedViewCache.java | 11 ++++++++++
.../helix/common/caches/ParticipantStateCache.java | 6 +++---
.../org/apache/helix/model/HelixConfigScope.java | 5 ++++-
.../model/builder/HelixConfigScopeBuilder.java | 1 +
9 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
index 30a9a8f..34b72c3 100644
--- a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
@@ -598,7 +598,7 @@ public class ConfigAccessor {
throw new HelixException(String.format("Failed to get config. cluster: %s is not setup.", clusterName));
}
HelixConfigScope scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.CUSTOMIZED_STATE_AGGREGATION).forCluster(clusterName).build();
+ new HelixConfigScopeBuilder(ConfigScopeProperty.CUSTOMIZED_STATE).forCluster(clusterName).build();
ZNRecord record = getConfigZnRecord(scope);
if (record == null) {
diff --git a/helix-core/src/main/java/org/apache/helix/PropertyKey.java b/helix-core/src/main/java/org/apache/helix/PropertyKey.java
index 29e8d65..73e125e 100644
--- a/helix-core/src/main/java/org/apache/helix/PropertyKey.java
+++ b/helix-core/src/main/java/org/apache/helix/PropertyKey.java
@@ -255,9 +255,9 @@ public class PropertyKey {
* @return {@link PropertyKey}
*/
public PropertyKey customizedStateConfig() {
- return new PropertyKey(CONFIGS, ConfigScopeProperty.CUSTOMIZED_STATE_AGGREGATION,
+ return new PropertyKey(CONFIGS, ConfigScopeProperty.CUSTOMIZED_STATE,
CustomizedStateConfig.class, _clusterName,
- ConfigScopeProperty.CUSTOMIZED_STATE_AGGREGATION.name(), _clusterName);
+ ConfigScopeProperty.CUSTOMIZED_STATE.name(), _clusterName);
}
/**
@@ -645,7 +645,7 @@ public class PropertyKey {
* Get a property key associated with all {@link CustomizedView}
* @return {@link PropertyKey}
*/
- public PropertyKey customizedView() {
+ public PropertyKey customizedViews() {
return new PropertyKey(CUSTOMIZEDVIEW, CustomizedView.class, _clusterName);
}
diff --git a/helix-core/src/main/java/org/apache/helix/PropertyPathBuilder.java b/helix-core/src/main/java/org/apache/helix/PropertyPathBuilder.java
index 48db47a..d9bb2b4 100644
--- a/helix-core/src/main/java/org/apache/helix/PropertyPathBuilder.java
+++ b/helix-core/src/main/java/org/apache/helix/PropertyPathBuilder.java
@@ -27,7 +27,6 @@ import java.util.regex.Pattern;
import org.apache.helix.model.ControllerHistory;
import org.apache.helix.model.CurrentState;
-import org.apache.helix.model.CustomizedState;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.InstanceConfig;
@@ -43,7 +42,6 @@ import org.slf4j.LoggerFactory;
import static org.apache.helix.PropertyType.CONFIGS;
import static org.apache.helix.PropertyType.CURRENTSTATES;
-import static org.apache.helix.PropertyType.CUSTOMIZEDSTATES;
import static org.apache.helix.PropertyType.EXTERNALVIEW;
import static org.apache.helix.PropertyType.HISTORY;
import static org.apache.helix.PropertyType.IDEALSTATES;
@@ -99,6 +97,10 @@ public class PropertyPathBuilder {
addEntry(PropertyType.TARGETEXTERNALVIEW, 1, "/{clusterName}/TARGETEXTERNALVIEW");
addEntry(PropertyType.TARGETEXTERNALVIEW, 2,
"/{clusterName}/TARGETEXTERNALVIEW/{resourceName}");
+ addEntry(PropertyType.CUSTOMIZEDVIEW, 1, "/{clusterName}/CUSTOMIZEDVIEW");
+ addEntry(PropertyType.CUSTOMIZEDVIEW, 2, "/{clusterName}/CUSTOMIZEDVIEW/{resourceName}");
+ addEntry(PropertyType.CUSTOMIZEDVIEW, 3,
+ "/{clusterName}/CUSTOMIZEDVIEW/{resourceName}/{customizedStateName}");
addEntry(PropertyType.STATEMODELDEFS, 1, "/{clusterName}/STATEMODELDEFS");
addEntry(PropertyType.STATEMODELDEFS, 2, "/{clusterName}/STATEMODELDEFS/{stateModelName}");
addEntry(PropertyType.CONTROLLER, 1, "/{clusterName}/CONTROLLER");
@@ -276,6 +278,20 @@ public class PropertyPathBuilder {
return String.format("/%s/TARGETEXTERNALVIEW/%s", clusterName, resourceName);
}
+ public static String customizedView(String clusterName) {
+ return String.format("/%s/CUSTOMIZEDVIEW", clusterName);
+ }
+
+ public static String customizedView(String clusterName, String customizedStateName) {
+ return String.format("/%s/CUSTOMIZEDVIEW/%s", clusterName, customizedStateName);
+ }
+
+ public static String customizedView(String clusterName, String customizedStateName,
+ String resourceName) {
+ return String
+ .format("/%s/CUSTOMIZEDVIEW/%s/%s", clusterName, customizedStateName, resourceName);
+ }
+
public static String liveInstance(String clusterName) {
return String.format("/%s/LIVEINSTANCES", clusterName);
}
@@ -373,6 +389,10 @@ public class PropertyPathBuilder {
return String.format("/%s/CONFIGS/RESOURCE", clusterName);
}
+ public static String customizedStateConfig(String clusterName) {
+ return String.format("/%s/CONFIGS/CUSTOMIZED_STATE", clusterName);
+ }
+
public static String controller(String clusterName) {
return String.format("/%s/CONTROLLER", clusterName);
}
diff --git a/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateConfigChangeListener.java b/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateConfigChangeListener.java
index 4d31d87..2a0068b 100644
--- a/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateConfigChangeListener.java
+++ b/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateConfigChangeListener.java
@@ -23,11 +23,11 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.model.CustomizedStateConfig;
/**
- * Interface to implement to listen for changes to customized state aggregation configurations.
+ * Interface to implement to listen for changes to customized state configurations.
*/
public interface CustomizedStateConfigChangeListener {
/**
- * Invoked when customized state aggregation config changes
+ * Invoked when customized state config changes
* @param customizedStateConfig
* @param context
*/
diff --git a/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedStateCache.java b/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedStateCache.java
index 2964b13..0875b00 100644
--- a/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedStateCache.java
+++ b/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedStateCache.java
@@ -27,7 +27,6 @@ import org.apache.helix.HelixDataAccessor;
import org.apache.helix.PropertyKey;
import org.apache.helix.common.controllers.ControlContextProvider;
import org.apache.helix.model.CustomizedState;
-import org.apache.helix.model.CustomizedStateConfig;
import org.apache.helix.model.LiveInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,13 +34,16 @@ import org.slf4j.LoggerFactory;
public class CustomizedStateCache extends ParticipantStateCache<CustomizedState> {
private static final Logger LOG = LoggerFactory.getLogger(CurrentStateCache.class.getName());
+ private final Set<String> _aggregationEnabledTypes;
- public CustomizedStateCache(String clusterName) {
- this(createDefaultControlContextProvider(clusterName));
+ public CustomizedStateCache(String clusterName, Set<String> aggregationEnabledTypes) {
+ this(createDefaultControlContextProvider(clusterName), aggregationEnabledTypes);
}
- public CustomizedStateCache(ControlContextProvider contextProvider) {
+ public CustomizedStateCache(ControlContextProvider contextProvider,
+ Set<String> aggregationEnabledTypes) {
super(contextProvider);
+ _aggregationEnabledTypes = aggregationEnabledTypes;
}
@Override
@@ -49,13 +51,8 @@ public class CustomizedStateCache extends ParticipantStateCache<CustomizedState>
Map<String, LiveInstance> liveInstanceMap) {
Set<PropertyKey> participantStateKeys = new HashSet<>();
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
- Set<String> restrictedKeys = new HashSet<>(
- accessor.getProperty(accessor.keyBuilder().customizedStateConfig()).getRecord()
- .getListFields().get(
- CustomizedStateConfig.CustomizedStateProperty.AGGREGATION_ENABLED_TYPES
- .name()));
for (String instanceName : liveInstanceMap.keySet()) {
- for (String customizedStateType : restrictedKeys) {
+ for (String customizedStateType : _aggregationEnabledTypes) {
accessor.getChildNames(keyBuilder.customizedStates(instanceName, customizedStateType))
.stream().forEach(resourceName -> participantStateKeys
.add(keyBuilder.customizedState(instanceName, customizedStateType, resourceName)));
diff --git a/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedViewCache.java b/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedViewCache.java
index 493ca69..a718872 100644
--- a/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedViewCache.java
+++ b/helix-core/src/main/java/org/apache/helix/common/caches/CustomizedViewCache.java
@@ -139,6 +139,17 @@ public class CustomizedViewCache extends AbstractDataCache<CustomizedView> {
return Collections.unmodifiableMap(_customizedViewMap);
}
+ /**
+ * Remove dead customized views from map
+ * @param resourceNames
+ */
+
+ public synchronized void removeCustomizedView(List<String> resourceNames) {
+ for (String resourceName : resourceNames) {
+ _customizedViewCache.remove(resourceName);
+ }
+ }
+
public void clear() {
_customizedViewCache.clear();
_customizedViewMap.clear();
diff --git a/helix-core/src/main/java/org/apache/helix/common/caches/ParticipantStateCache.java b/helix-core/src/main/java/org/apache/helix/common/caches/ParticipantStateCache.java
index 61556b1..b7e69b3 100644
--- a/helix-core/src/main/java/org/apache/helix/common/caches/ParticipantStateCache.java
+++ b/helix-core/src/main/java/org/apache/helix/common/caches/ParticipantStateCache.java
@@ -19,8 +19,6 @@ package org.apache.helix.common.caches;
* under the License.
*/
-import com.google.common.collect.Maps;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -28,6 +26,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import com.google.common.collect.Maps;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.PropertyKey;
import org.apache.helix.common.controllers.ControlContextProvider;
@@ -108,7 +107,8 @@ public abstract class ParticipantStateCache<T> extends AbstractDataCache {
Map<String, LiveInstance> liveInstanceMap) {
long start = System.currentTimeMillis();
- Set<PropertyKey> participantStateKeys = PopulateParticipantKeys(accessor, liveInstanceMap);
+ Set<PropertyKey> participantStateKeys =
+ PopulateParticipantKeys(accessor, liveInstanceMap);
// All new entries from zk not cached locally yet should be read from ZK.
Set<PropertyKey> reloadKeys = new HashSet<>(participantStateKeys);
diff --git a/helix-core/src/main/java/org/apache/helix/model/HelixConfigScope.java b/helix-core/src/main/java/org/apache/helix/model/HelixConfigScope.java
index cf49ccd..0b335ca 100644
--- a/helix-core/src/main/java/org/apache/helix/model/HelixConfigScope.java
+++ b/helix-core/src/main/java/org/apache/helix/model/HelixConfigScope.java
@@ -38,7 +38,8 @@ public class HelixConfigScope {
CONSTRAINT(2, 0),
REST(2, 0),
CLOUD(2, 0),
- CUSTOMIZED_STATE_AGGREGATION(2, 0);
+ CUSTOMIZED_STATE_AGGREGATION(2, 0),
+ CUSTOMIZED_STATE(2, 0);
final int _zkPathArgNum;
final int _mapKeyArgNum;
@@ -91,6 +92,8 @@ public class HelixConfigScope {
template.addEntry(ConfigScopeProperty.CLOUD, 1, "/{clusterName}/CONFIGS/CLOUD");
template.addEntry(ConfigScopeProperty.CUSTOMIZED_STATE_AGGREGATION, 2,
"/{clusterName}/CONFIGS/CUSTOMIZED_STATE_AGGREGATION/{clusterName}");
+ template.addEntry(ConfigScopeProperty.CUSTOMIZED_STATE, 2,
+ "/{clusterName}/CONFIGS/CUSTOMIZED_STATE/{clusterName}");
}
final ConfigScopeProperty _type;
diff --git a/helix-core/src/main/java/org/apache/helix/model/builder/HelixConfigScopeBuilder.java b/helix-core/src/main/java/org/apache/helix/model/builder/HelixConfigScopeBuilder.java
index 98de1e7..8166bf4 100644
--- a/helix-core/src/main/java/org/apache/helix/model/builder/HelixConfigScopeBuilder.java
+++ b/helix-core/src/main/java/org/apache/helix/model/builder/HelixConfigScopeBuilder.java
@@ -130,6 +130,7 @@ public class HelixConfigScopeBuilder {
scope = new HelixConfigScope(_type, Arrays.asList(_clusterName, _clusterName), null);
break;
case CUSTOMIZED_STATE_AGGREGATION:
+ case CUSTOMIZED_STATE:
scope = new HelixConfigScope(_type, Arrays.asList(_clusterName, _clusterName), null);
default:
break;