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 2020/03/12 17:58:50 UTC
[GitHub] [helix] zhangmeng916 opened a new pull request #888: Modify data
providers and add customized view aggregation stage
zhangmeng916 opened a new pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888
### Issues
- [X] My PR addresses the following Helix issues and references them in the PR description:
(#850 )
### Description
- [X] Here are some details about my PR, including screenshots of any UI changes:
To support customized view aggregation, we need to change the current data providers to add the refresh for customized state and customized view. We also need to have an extra stage that does the computation from customized state to customized view.
### Tests
- [X] The following tests are written for this issue:
TestCustomizedStateComputationStage
TestCustomizedViewStage
TestComputeAndCleanupCustomizedView
- [X] The following is the result of the "mvn test" command on the appropriate module:
[INFO] Tests run: 909, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3,438.097 s - in TestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 909, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
### Commits
- [X] My commits all reference appropriate Apache Helix GitHub issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Code Quality
- [X] My diff has been formatted using helix-style.xml
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392728296
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
+ }
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
Review comment:
Worth it. Because if you have 1K resources, you might refresh 1K times, right?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392788574
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
+ }
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
Review comment:
I remove all the cache refresh/remove logic in this stage. But let me double check. I saw external view computation stage does have cache refresh and remove, and I'll make sure the cache is not used anywhere.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392723977
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -156,6 +161,30 @@ private void refreshTargetExternalViews(final HelixDataAccessor accessor) {
}
}
+ public void refreshCustomizedViewMap(final HelixDataAccessor accessor) {
+ // As we are not listening on customized view change, customized view will be
+ // refreshed once during the cache's first refresh() call, or when full refresh is required
+ List<String> stateTypes = accessor.getChildNames(accessor.keyBuilder().customizedViews());
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_VIEW).getAndSet(false)) {
+ for (String stateType : stateTypes) {
+ if (!_customizedViewCacheMap.containsKey(stateType)) {
+ CustomizedViewCache newCustomizedViewCache =
+ new CustomizedViewCache(getClusterName(), stateType);
+ newCustomizedViewCache.refresh(accessor);
+ _customizedViewCacheMap.put(stateType, newCustomizedViewCache);
+ } else {
+ _customizedViewCacheMap.get(stateType).refresh(accessor);
+ }
+ }
+ for (String stateType : _customizedViewCacheMap.keySet()) {
Review comment:
Can we leverage the removeCustomizedViewTypes() that already defined?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393977501
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedStateComputationStage.java
##########
@@ -0,0 +1,92 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractBaseStage;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedStateComputationStage extends AbstractBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedStateComputationStage.class);
+
+ @Override
+ public void process(ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+ final Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
Review comment:
The RESOURCES_TO_REBALANCE is a set of valid resources that we filtered. I think it would be a better input.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394041552
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -139,6 +155,28 @@ protected void dumpDebugInfo() {
}
}
+ private void refreshCustomizedStateConfig(final HelixDataAccessor accessor) {
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_STATE_CONFIG)
+ .getAndSet(false)) {
+ CustomizedStateConfig customizedStateConfig =
+ accessor.getProperty(accessor.keyBuilder().customizedStateConfig());
+ if (customizedStateConfig != null) {
+ _aggregationEnabledTypes =
+ new HashSet<>(customizedStateConfig.getAggregationEnabledTypes());
+ } else {
+ _aggregationEnabledTypes.clear();
+ }
+ _customizedStateCache.setAggregationEnabledTypes(_aggregationEnabledTypes);
Review comment:
Can we explicitly call this outside the refreshCustomizedStateConfig and just before _customizedStateCache.refresh()? Since _customizedStateCache.setAggregationEnabledTypes and refresh must be ordered, putting them together is easier for us to understand and maintain.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392722246
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -96,13 +99,15 @@
// Special caches
private CurrentStateCache _currentStateCache;
+ private CustomizedStateCache _customizedStateCache;
Review comment:
This will increase the read throughput and pipeline latency, which is one of the major concerns. Before we have a real use case, I prefer to keep it in the resource data provider only.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392558356
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -217,6 +222,7 @@ public String getObjName(StateModelDefinition obj) {
}
}, false);
_currentStateCache = new CurrentStateCache(this);
+ _customizedStateCache = new CustomizedStateCache(this, _aggregationEnabledTypes);
Review comment:
I tried, but this will break the other constructor:
public CustomizedStateCache(String clusterName, Set<String> aggregationEnabledTypes) {
this(createDefaultControlContextProvider(clusterName), aggregationEnabledTypes);
}
The clusterName does not contain any aggregation type information, and we need to provide them explicitly.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on issue #888: Modify data providers
and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on issue #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#issuecomment-600370105
This PR is ready to merge, approved by @jiajunwang
Final commit message:
Add two stages for customized state view aggregation.
1. One stage is the computation stage for customized state. It takes the Zookeeper data of customized states and converts them to the formatted output used by the other stage.
2. The other stage is customized view aggregation stage. It will take the output from the customized state computation stage, and output the customized view to Zookeeper.
3. The two stages together compute the customized view from the customized states.
4. Unit tests are added to verify the correctness of the two stages.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393857727
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -139,6 +155,27 @@ protected void dumpDebugInfo() {
}
}
+ private void refreshCustomizedStateConfig(final HelixDataAccessor accessor) {
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_STATE_CONFIG)
+ .getAndSet(false)) {
+ CustomizedStateConfig customizedStateConfig =
+ accessor.getProperty(accessor.keyBuilder().customizedStateConfig());
+ if (customizedStateConfig != null) {
+ _aggregationEnabledTypes =
Review comment:
nit, since the customizedStateConfig is created in the current method scope, I think directly assign the type set to _aggregationEnabledTypes is fine. A copy constructor is not necessary.
But no strong preference here.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392558664
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -96,13 +99,15 @@
// Special caches
private CurrentStateCache _currentStateCache;
+ private CustomizedStateCache _customizedStateCache;
Review comment:
Currently I do not see the usage of customized state in task pipeline. I kept it here mainly for two reasons, one is that it's similar to current state cache, and easier to identify and debug if we put them together, also it keeps some assumption of our tests. The other reason is that we may have extended use case in the future, our TF users may also have some customized state they need.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393975783
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -123,8 +136,11 @@ public synchronized void refresh(HelixDataAccessor accessor) {
}
// Refresh resource controller specific property caches
+ refreshCustomizedStateConfig(accessor);
+ _customizedStateCache.refresh(accessor, _liveInstanceCache.getPropertyMap());
refreshExternalViews(accessor);
Review comment:
ok, will discuss in the controller PR.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392723441
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -286,6 +292,27 @@ private void refreshResourceConfig(final HelixDataAccessor accessor,
}
}
+ private void refreshCustomizedStateConfig(final HelixDataAccessor accessor,
+ Set<HelixConstants.ChangeType> refreshedType) {
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_STATE_CONFIG)
+ .getAndSet(false)) {
+ CustomizedStateConfig customizedStateConfig =
+ accessor.getProperty(accessor.keyBuilder().customizedStateConfig());
+ if (customizedStateConfig != null) {
Review comment:
If it is null, shall we change clean the _aggregationEnabledTypes?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393329126
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
+ }
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
Review comment:
I've confirmed that routing table would not read from the customized view cache output from this stage, so we are safe to remove the refresh of cache
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392558374
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -374,6 +405,14 @@ public void setClusterConfig(ClusterConfig clusterConfig) {
_clusterConfig = clusterConfig;
}
+ public Set<String> getCustomizedStateConfig() {
+ return _aggregationEnabledTypes;
+ }
+
+ public void setCustomizedStateConfig(Set<String> aggregationEnabledTypes) {
Review comment:
It's likely to be only used in test for now. So I keep it as public.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392723758
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -217,6 +222,7 @@ public String getObjName(StateModelDefinition obj) {
}
}, false);
_currentStateCache = new CurrentStateCache(this);
+ _customizedStateCache = new CustomizedStateCache(this, _aggregationEnabledTypes);
Review comment:
My major concern is that it relies on the reference of the input set (aggregationEnabledTypes) to accept any types update. Ideally, it should be read explicitly in the CustomizedStateCache logic. So it exactly knows that this set might have been changed. For now, every read of this set in the CustomizedStateCache can return different content. This may introduce bugs.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392541046
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -286,6 +292,27 @@ private void refreshResourceConfig(final HelixDataAccessor accessor,
}
}
+ private void refreshCustomizedStateConfig(final HelixDataAccessor accessor,
+ Set<HelixConstants.ChangeType> refreshedType) {
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_STATE_CONFIG)
+ .getAndSet(false)) {
+ CustomizedStateConfig customizedStateConfig =
+ accessor.getProperty(accessor.keyBuilder().customizedStateConfig());
+ if (customizedStateConfig != null) {
+ _aggregationEnabledTypes = new HashSet<>(customizedStateConfig.getRecord().getListFields()
+ .get(CustomizedStateConfig.CustomizedStateProperty.AGGREGATION_ENABLED_TYPES.name()));
Review comment:
Instead of calling the raw method, do we have a method in customizedStateConfig to get the types?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392724793
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -374,6 +405,14 @@ public void setClusterConfig(ClusterConfig clusterConfig) {
_clusterConfig = clusterConfig;
}
+ public Set<String> getAggregationEnabledCustomizedStateTypes() {
+ return _aggregationEnabledTypes;
+ }
+
+ public void SetAggregationEnabledCustomizedStateTypes(Set<String> aggregationEnabledTypes) {
Review comment:
As you mentioned it is now for test only, I would prefer protected.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393855994
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -286,6 +286,7 @@ private void refreshResourceConfig(final HelixDataAccessor accessor,
}
}
+
Review comment:
nit, not necessary
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang merged pull request #888: Modify data providers
and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang merged pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392724987
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,164 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ cache.refreshCustomizedViewMap(dataAccessor);
Review comment:
Question, I assume the reason that we refresh it in this stage is to read the most recent status. If this is the case, can we bypass the refresh that is done in the cache refresh? It seems to me that one of them is not necessary.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392546558
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
Review comment:
I think this has been done in the external view stage. There is no need to do it twice.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392541335
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -374,6 +405,14 @@ public void setClusterConfig(ClusterConfig clusterConfig) {
_clusterConfig = clusterConfig;
}
+ public Set<String> getCustomizedStateConfig() {
Review comment:
getEnabledCustomizedStateTypes()?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392724335
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedStateComputationStage.java
##########
@@ -0,0 +1,94 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.controller.dataproviders.BaseControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractBaseStage;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedStateComputationStage extends AbstractBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedStateComputationStage.class);
+
+ @Override
+ public void process(ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ BaseControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+ final Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
+ Set<String> aggregationEnabledTypes = cache.getAggregationEnabledCustomizedStateTypes();
+
+ if (cache == null || resourceMap == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires DataCache|RESOURCE");
+ }
+
+ Map<String, LiveInstance> liveInstances = cache.getLiveInstances();
+ final CustomizedStateOutput customizedStateOutput = new CustomizedStateOutput();
+
+ for (LiveInstance instance : liveInstances.values()) {
+ String instanceName = instance.getInstanceName();
+ // update customized states.
+ for (String customizedStateType : aggregationEnabledTypes) {
+ Map<String, CustomizedState> customizedStateMap =
+ cache.getCustomizedState(instanceName, customizedStateType);
+ updateCustomizedStates(instance, customizedStateType, customizedStateMap,
+ customizedStateOutput, resourceMap);
+ }
+ }
+ event.addAttribute(AttributeName.CUSTOMIZED_STATE.name(), customizedStateOutput);
+ }
+
+ // update customized state in CustomizedStateOutput
+ private void updateCustomizedStates(LiveInstance instance, String customizedStateType,
Review comment:
How about just pass the instanceName?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393884977
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -123,8 +136,11 @@ public synchronized void refresh(HelixDataAccessor accessor) {
}
// Refresh resource controller specific property caches
+ refreshCustomizedStateConfig(accessor);
+ _customizedStateCache.refresh(accessor, _liveInstanceCache.getPropertyMap());
refreshExternalViews(accessor);
Review comment:
Maybe we shall consider moving these 3 calculations to the update stages in the async thread. But let's leave it here for now. We will revisit anyway.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392542516
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedStateComputationStage.java
##########
@@ -0,0 +1,107 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.controller.dataproviders.BaseControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractBaseStage;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedStateComputationStage extends AbstractBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedStateComputationStage.class);
+
+ @Override
+ public void process(ClusterEvent event) throws Exception {
+ HelixManager helixManager = event.getAttribute(AttributeName.helixmanager.name());
+ Set<String> aggregationEnabledTypes = new HashSet<>();
+ if (helixManager.getHelixDataAccessor().getProperty(
Review comment:
Haven't we refreshed this in the BaseControllerDataProvider, can we just use that result here?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392546092
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -96,13 +99,15 @@
// Special caches
private CurrentStateCache _currentStateCache;
+ private CustomizedStateCache _customizedStateCache;
Review comment:
I think if we add it here, it will be done by the Task pipeline as well. Is it necessary?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393975426
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedStateComputationStage.java
##########
@@ -0,0 +1,92 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractBaseStage;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedStateComputationStage extends AbstractBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedStateComputationStage.class);
+
+ @Override
+ public void process(ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+ final Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
Review comment:
I followed CurrentStateComputationStage convention here. What is exactly the difference for them?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392546485
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
Review comment:
This logic confused me. Are we setting curCustomizedViews or customizedViewCache? Or both?
Could you please split these 2 parts?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392541435
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -374,6 +405,14 @@ public void setClusterConfig(ClusterConfig clusterConfig) {
_clusterConfig = clusterConfig;
}
+ public Set<String> getCustomizedStateConfig() {
+ return _aggregationEnabledTypes;
+ }
+
+ public void setCustomizedStateConfig(Set<String> aggregationEnabledTypes) {
Review comment:
Same, the name should reflect what we set. Moreover, do we need this set to be public?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392544157
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -217,6 +222,7 @@ public String getObjName(StateModelDefinition obj) {
}
}, false);
_currentStateCache = new CurrentStateCache(this);
+ _customizedStateCache = new CustomizedStateCache(this, _aggregationEnabledTypes);
Review comment:
If you passed "this", I guess you don't need to pass "_aggregationEnabledTypes" in addition. You can always call BaseControllerDataProvider.getCustomizedStateConfig() in the CustomizedStateCache. And that method is safer and cleaner.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393977842
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -139,6 +155,27 @@ protected void dumpDebugInfo() {
}
}
+ private void refreshCustomizedStateConfig(final HelixDataAccessor accessor) {
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_STATE_CONFIG)
+ .getAndSet(false)) {
+ CustomizedStateConfig customizedStateConfig =
+ accessor.getProperty(accessor.keyBuilder().customizedStateConfig());
+ if (customizedStateConfig != null) {
+ _aggregationEnabledTypes =
Review comment:
In that case, should be good. I thought it was just for protecting the input.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394038432
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -89,7 +89,7 @@
// Property caches
private final PropertyCache<ResourceConfig> _resourceConfigCache;
private final PropertyCache<InstanceConfig> _instanceConfigCache;
- private final PropertyCache<LiveInstance> _liveInstanceCache;
+ protected final PropertyCache<LiveInstance> _liveInstanceCache;
Review comment:
nit, safer to add a protected readonly method for getting the list instead of returning the list. Otherwise, the children may modify this list.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394067879
##########
File path: helix-core/src/test/java/org/apache/helix/controller/stages/TestCustomizedViewStage.java
##########
@@ -0,0 +1,106 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewStage extends ZkUnitTestBase {
+ private final String RESOURCE_NAME = "testResourceName";
+ private final String PARTITION_NAME = "testResourceName_0";
+ private final String CUSTOMIZED_STATE_NAME = "customizedState1";
+ private final String INSTANCE_NAME = "localhost_1";
+
+ @Test
+ public void testCachedCustomizedViews() throws Exception {
+ String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
+
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
+ HelixManager manager = new DummyClusterManager(clusterName, accessor);
+
+ setupLiveInstances(clusterName, new int[]{0, 1});
+ setupStateModel(clusterName);
+
+ ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+ ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
+ event.addAttribute(AttributeName.helixmanager.name(), manager);
+ event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
+
+ CustomizedStateConfig config = new CustomizedStateConfig();
+ List<String> aggregationEnabledTypes = new ArrayList<>();
+ aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
+ config.setAggregationEnabledTypes(aggregationEnabledTypes);
+
+ PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.customizedStateConfig(), config);
+
+ CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
+ customizedState.setState(PARTITION_NAME, "STARTED");
+ accessor
+ .setProperty(keyBuilder.customizedState(INSTANCE_NAME, "customizedState1", RESOURCE_NAME),
+ customizedState);
+
+ CustomizedViewAggregationStage customizedViewComputeStage =
+ new CustomizedViewAggregationStage();
+ Pipeline dataRefresh = new Pipeline();
+ dataRefresh.addStage(new ReadClusterDataStage());
+ runPipeline(event, dataRefresh);
+ runStage(event, new ResourceComputationStage());
+ runStage(event, new CustomizedStateComputationStage());
+ runStage(event, customizedViewComputeStage);
+ Assert.assertEquals(cache.getCustomizedViewCacheMap().values(),
+ accessor.getChildValues(accessor.keyBuilder().customizedViews()));
+
+ // Assure there is no customized view got updated when running the stage again
+ List<CustomizedView> oldCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ runStage(event, customizedViewComputeStage);
+ List<CustomizedView> newCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ Assert.assertEquals(oldCustomizedViews, newCustomizedViews);
Review comment:
Actually I found in TestExternalVeiwStage the following code.
Assert.assertEquals(oldExternalViews, newExternalViews);
for (int i = 0; i < oldExternalViews.size(); i++) {
Assert.assertEquals(oldExternalViews.get(i).getStat().getVersion(),
newExternalViews.get(i).getStat().getVersion());
}
I believe this test doesn't fail. I think my test is using the same logic. Since I would also like to examine each item based on index, like the above code, let's keep it as list for now. If we encounter any test failure, let's revisit it.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392789121
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java
##########
@@ -217,6 +222,7 @@ public String getObjName(StateModelDefinition obj) {
}
}, false);
_currentStateCache = new CurrentStateCache(this);
+ _customizedStateCache = new CustomizedStateCache(this, _aggregationEnabledTypes);
Review comment:
I agree. I suggest we defer the decision in the next PR together with the controller. The main reason is that then I can show easily which test is broken with the change in controller logic and cache change. We can decide whether changing the test logic makes more sense or the cache logic.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] pkuwm commented on a change in pull request #888: Modify
data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394057107
##########
File path: helix-core/src/test/java/org/apache/helix/controller/stages/TestCustomizedViewStage.java
##########
@@ -0,0 +1,106 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewStage extends ZkUnitTestBase {
+ private final String RESOURCE_NAME = "testResourceName";
+ private final String PARTITION_NAME = "testResourceName_0";
+ private final String CUSTOMIZED_STATE_NAME = "customizedState1";
+ private final String INSTANCE_NAME = "localhost_1";
+
+ @Test
+ public void testCachedCustomizedViews() throws Exception {
+ String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
+
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
+ HelixManager manager = new DummyClusterManager(clusterName, accessor);
+
+ setupLiveInstances(clusterName, new int[]{0, 1});
+ setupStateModel(clusterName);
+
+ ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+ ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
+ event.addAttribute(AttributeName.helixmanager.name(), manager);
+ event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
+
+ CustomizedStateConfig config = new CustomizedStateConfig();
+ List<String> aggregationEnabledTypes = new ArrayList<>();
+ aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
+ config.setAggregationEnabledTypes(aggregationEnabledTypes);
+
+ PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.customizedStateConfig(), config);
+
+ CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
+ customizedState.setState(PARTITION_NAME, "STARTED");
+ accessor
+ .setProperty(keyBuilder.customizedState(INSTANCE_NAME, "customizedState1", RESOURCE_NAME),
+ customizedState);
+
+ CustomizedViewAggregationStage customizedViewComputeStage =
+ new CustomizedViewAggregationStage();
+ Pipeline dataRefresh = new Pipeline();
+ dataRefresh.addStage(new ReadClusterDataStage());
+ runPipeline(event, dataRefresh);
+ runStage(event, new ResourceComputationStage());
+ runStage(event, new CustomizedStateComputationStage());
+ runStage(event, customizedViewComputeStage);
+ Assert.assertEquals(cache.getCustomizedViewCacheMap().values(),
+ accessor.getChildValues(accessor.keyBuilder().customizedViews()));
+
+ // Assure there is no customized view got updated when running the stage again
+ List<CustomizedView> oldCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ runStage(event, customizedViewComputeStage);
+ List<CustomizedView> newCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ Assert.assertEquals(oldCustomizedViews, newCustomizedViews);
Review comment:
Ordering is not guaranteed. In ZK's Znode implementation, it is using a set to store children. And it is converted to a list when returning to the client. So the ordering could be random.
If you are just checking if they have the same element without ordering, I would suggest using Sets so ordering is ignored. Only if you also want to check the ordering, a list is more appropriate.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393965942
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -139,6 +155,27 @@ protected void dumpDebugInfo() {
}
}
+ private void refreshCustomizedStateConfig(final HelixDataAccessor accessor) {
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_STATE_CONFIG)
+ .getAndSet(false)) {
+ CustomizedStateConfig customizedStateConfig =
+ accessor.getProperty(accessor.keyBuilder().customizedStateConfig());
+ if (customizedStateConfig != null) {
+ _aggregationEnabledTypes =
Review comment:
This is actually converting list to set. Any easier 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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394073188
##########
File path: helix-core/src/test/java/org/apache/helix/controller/stages/TestCustomizedViewStage.java
##########
@@ -0,0 +1,106 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewStage extends ZkUnitTestBase {
+ private final String RESOURCE_NAME = "testResourceName";
+ private final String PARTITION_NAME = "testResourceName_0";
+ private final String CUSTOMIZED_STATE_NAME = "customizedState1";
+ private final String INSTANCE_NAME = "localhost_1";
+
+ @Test
+ public void testCachedCustomizedViews() throws Exception {
+ String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
+
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
+ HelixManager manager = new DummyClusterManager(clusterName, accessor);
+
+ setupLiveInstances(clusterName, new int[]{0, 1});
+ setupStateModel(clusterName);
+
+ ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+ ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
+ event.addAttribute(AttributeName.helixmanager.name(), manager);
+ event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
+
+ CustomizedStateConfig config = new CustomizedStateConfig();
+ List<String> aggregationEnabledTypes = new ArrayList<>();
+ aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
+ config.setAggregationEnabledTypes(aggregationEnabledTypes);
+
+ PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.customizedStateConfig(), config);
+
+ CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
+ customizedState.setState(PARTITION_NAME, "STARTED");
+ accessor
+ .setProperty(keyBuilder.customizedState(INSTANCE_NAME, "customizedState1", RESOURCE_NAME),
+ customizedState);
+
+ CustomizedViewAggregationStage customizedViewComputeStage =
+ new CustomizedViewAggregationStage();
+ Pipeline dataRefresh = new Pipeline();
+ dataRefresh.addStage(new ReadClusterDataStage());
+ runPipeline(event, dataRefresh);
+ runStage(event, new ResourceComputationStage());
+ runStage(event, new CustomizedStateComputationStage());
+ runStage(event, customizedViewComputeStage);
+ Assert.assertEquals(cache.getCustomizedViewCacheMap().values(),
Review comment:
Please see the comments above.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393863504
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -156,6 +193,47 @@ private void refreshTargetExternalViews(final HelixDataAccessor accessor) {
}
}
+ public void refreshCustomizedViewMap(final HelixDataAccessor accessor) {
+ // As we are not listening on customized view change, customized view will be
+ // refreshed once during the cache's first refresh() call, or when full refresh is required
+ List<String> newStateTypes = accessor.getChildNames(accessor.keyBuilder().customizedViews());
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_VIEW).getAndSet(false)) {
+ for (String stateType : newStateTypes) {
+ if (!_customizedViewCacheMap.containsKey(stateType)) {
+ CustomizedViewCache newCustomizedViewCache =
+ new CustomizedViewCache(getClusterName(), stateType);
+ newCustomizedViewCache.refresh(accessor);
+ _customizedViewCacheMap.put(stateType, newCustomizedViewCache);
+ } else {
Review comment:
nit, this else is not necessary.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392724117
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -156,6 +161,30 @@ private void refreshTargetExternalViews(final HelixDataAccessor accessor) {
}
}
+ public void refreshCustomizedViewMap(final HelixDataAccessor accessor) {
+ // As we are not listening on customized view change, customized view will be
+ // refreshed once during the cache's first refresh() call, or when full refresh is required
+ List<String> stateTypes = accessor.getChildNames(accessor.keyBuilder().customizedViews());
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_VIEW).getAndSet(false)) {
+ for (String stateType : stateTypes) {
+ if (!_customizedViewCacheMap.containsKey(stateType)) {
+ CustomizedViewCache newCustomizedViewCache =
+ new CustomizedViewCache(getClusterName(), stateType);
+ newCustomizedViewCache.refresh(accessor);
+ _customizedViewCacheMap.put(stateType, newCustomizedViewCache);
+ } else {
+ _customizedViewCacheMap.get(stateType).refresh(accessor);
+ }
+ }
+ for (String stateType : _customizedViewCacheMap.keySet()) {
+ if (!stateTypes.contains(stateType)) {
Review comment:
nit, the var names here are confusing.
stateTypes -> currentStateTypes
the stateType here -> cachedStateType
Will that be cleaner?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392542323
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -156,6 +161,23 @@ private void refreshTargetExternalViews(final HelixDataAccessor accessor) {
}
}
+ public void refreshCustomizedViewMap(final HelixDataAccessor accessor) {
+ // As we are not listening on customized view change, customized view will be
+ // refreshed once during the cache's first refresh() call, or when full refresh is required
+ List<String> stateTypes = accessor.getChildNames(accessor.keyBuilder().customizedViews());
+ if (_propertyDataChangedMap.get(HelixConstants.ChangeType.CUSTOMIZED_VIEW).getAndSet(false)) {
+ for (String stateType: stateTypes) {
+ _customizedViewCacheMap.get(stateType).refresh(accessor);
Review comment:
The map is initialized as en empty map. Do we need to check for NPE here?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393864943
##########
File path: helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
##########
@@ -193,6 +279,17 @@ public void removeExternalViews(List<String> resourceNames) {
}
}
+ /**
+ * Remove dead customized views for certain state types from map
+ * @param stateTypeNames
+ */
+
+ public void removeCustomizedViewTypes(List<String> stateTypeNames) {
Review comment:
private?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392728000
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
Review comment:
Maybe you can enrich the comment here.
If customizedViewCache != null, you have curCustomizedViews assigned. Otherwise, you have an empty curCustomizedViews. And a customizedViewCache will be initialized then assign to the local var "customizedViewCache".
The thing confused me the most is what's the difference between curCustomizedViews and customizedViewCache? For the following code, they could be completely different things. To be honest, I can still not following.
I was expecting either one of the following cases:
curCustomizedViews = (customizedViewCache != null)? customizedViewCache.getCustomizedViewMap() : new HashMap<>();
Or,
CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
if (customizedViewCache != null) {
customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
}
curCustomizedViews = customizedViewCache.getCustomizedViewMap();
But never the mix.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392728765
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,164 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ cache.refreshCustomizedViewMap(dataAccessor);
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
+ }
+
+ List<String> customizedViewsToRemove = new ArrayList<>();
+
+ // remove stale customized views
+ for (String resourceName : curCustomizedViews.keySet()) {
+ if (!resourceMap.keySet().contains(resourceName)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for resource: " + resourceName);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType, resourceName));
+ customizedViewsToRemove.add(resourceName);
+ }
+ }
+ customizedViewCache.removeCustomizedView(customizedViewsToRemove);
Review comment:
Same here, if we don't remove it, will the next pipeline refresh the cache and delete it anyway?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392728427
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
+ }
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
Review comment:
But, actually, I have another question even before that. Why do you need to refresh this cache? It is not used in the following logic. And as for the next pipeline, it will refresh the cache from ZK anyway.
Finally, in your previous logic, CustomizedViewCache could be a newly created instance (created by "new CustomizedViewCache(event.getClusterName(), stateType);" And you are not put it back to the Resource Cache), right? So refresh it does not help anyone in my understanding. Please correct me if I missed anything.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] pkuwm commented on a change in pull request #888: Modify
data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394048072
##########
File path: helix-core/src/test/java/org/apache/helix/controller/stages/TestCustomizedViewStage.java
##########
@@ -0,0 +1,106 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewStage extends ZkUnitTestBase {
+ private final String RESOURCE_NAME = "testResourceName";
+ private final String PARTITION_NAME = "testResourceName_0";
+ private final String CUSTOMIZED_STATE_NAME = "customizedState1";
+ private final String INSTANCE_NAME = "localhost_1";
+
+ @Test
+ public void testCachedCustomizedViews() throws Exception {
+ String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
+
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
+ HelixManager manager = new DummyClusterManager(clusterName, accessor);
+
+ setupLiveInstances(clusterName, new int[]{0, 1});
+ setupStateModel(clusterName);
+
+ ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+ ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
+ event.addAttribute(AttributeName.helixmanager.name(), manager);
+ event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
+
+ CustomizedStateConfig config = new CustomizedStateConfig();
+ List<String> aggregationEnabledTypes = new ArrayList<>();
+ aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
+ config.setAggregationEnabledTypes(aggregationEnabledTypes);
+
+ PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.customizedStateConfig(), config);
+
+ CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
+ customizedState.setState(PARTITION_NAME, "STARTED");
+ accessor
+ .setProperty(keyBuilder.customizedState(INSTANCE_NAME, "customizedState1", RESOURCE_NAME),
+ customizedState);
+
+ CustomizedViewAggregationStage customizedViewComputeStage =
+ new CustomizedViewAggregationStage();
+ Pipeline dataRefresh = new Pipeline();
+ dataRefresh.addStage(new ReadClusterDataStage());
+ runPipeline(event, dataRefresh);
+ runStage(event, new ResourceComputationStage());
+ runStage(event, new CustomizedStateComputationStage());
+ runStage(event, customizedViewComputeStage);
+ Assert.assertEquals(cache.getCustomizedViewCacheMap().values(),
+ accessor.getChildValues(accessor.keyBuilder().customizedViews()));
+
+ // Assure there is no customized view got updated when running the stage again
+ List<CustomizedView> oldCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ runStage(event, customizedViewComputeStage);
+ List<CustomizedView> newCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ Assert.assertEquals(oldCustomizedViews, newCustomizedViews);
Review comment:
More accurate to convert the 2 lists to sets for assertion? If the ordering is different, this assert would fail.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392561237
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
+ }
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
Review comment:
I tried to use in-memory content, and that does require a couple of set functions in CustomizedViewCache. I feel it's not clean. Please let me know if you think it's worth.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394051617
##########
File path: helix-core/src/test/java/org/apache/helix/controller/stages/TestCustomizedViewStage.java
##########
@@ -0,0 +1,106 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewStage extends ZkUnitTestBase {
+ private final String RESOURCE_NAME = "testResourceName";
+ private final String PARTITION_NAME = "testResourceName_0";
+ private final String CUSTOMIZED_STATE_NAME = "customizedState1";
+ private final String INSTANCE_NAME = "localhost_1";
+
+ @Test
+ public void testCachedCustomizedViews() throws Exception {
+ String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
+
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
+ HelixManager manager = new DummyClusterManager(clusterName, accessor);
+
+ setupLiveInstances(clusterName, new int[]{0, 1});
+ setupStateModel(clusterName);
+
+ ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+ ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
+ event.addAttribute(AttributeName.helixmanager.name(), manager);
+ event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
+
+ CustomizedStateConfig config = new CustomizedStateConfig();
+ List<String> aggregationEnabledTypes = new ArrayList<>();
+ aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
+ config.setAggregationEnabledTypes(aggregationEnabledTypes);
+
+ PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.customizedStateConfig(), config);
+
+ CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
+ customizedState.setState(PARTITION_NAME, "STARTED");
+ accessor
+ .setProperty(keyBuilder.customizedState(INSTANCE_NAME, "customizedState1", RESOURCE_NAME),
+ customizedState);
+
+ CustomizedViewAggregationStage customizedViewComputeStage =
+ new CustomizedViewAggregationStage();
+ Pipeline dataRefresh = new Pipeline();
+ dataRefresh.addStage(new ReadClusterDataStage());
+ runPipeline(event, dataRefresh);
+ runStage(event, new ResourceComputationStage());
+ runStage(event, new CustomizedStateComputationStage());
+ runStage(event, customizedViewComputeStage);
+ Assert.assertEquals(cache.getCustomizedViewCacheMap().values(),
+ accessor.getChildValues(accessor.keyBuilder().customizedViews()));
+
+ // Assure there is no customized view got updated when running the stage again
+ List<CustomizedView> oldCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ runStage(event, customizedViewComputeStage);
+ List<CustomizedView> newCustomizedViews =
+ accessor.getChildValues(accessor.keyBuilder().customizedViews());
+ Assert.assertEquals(oldCustomizedViews, newCustomizedViews);
Review comment:
I thought the children were retrieved in a certain order, but by looking at the code, seems actually it's random based on the order whichever child is gotten back first. Is it right?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r393865412
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedStateComputationStage.java
##########
@@ -0,0 +1,92 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractBaseStage;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedStateComputationStage extends AbstractBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedStateComputationStage.class);
+
+ @Override
+ public void process(ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+ final Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
Review comment:
Should this be RESOURCES_TO_REBALANCE like the CustomizedViewAggregationStage does?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] pkuwm commented on a change in pull request #888: Modify
data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r394057349
##########
File path: helix-core/src/test/java/org/apache/helix/controller/stages/TestCustomizedViewStage.java
##########
@@ -0,0 +1,106 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CustomizedState;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewStage extends ZkUnitTestBase {
+ private final String RESOURCE_NAME = "testResourceName";
+ private final String PARTITION_NAME = "testResourceName_0";
+ private final String CUSTOMIZED_STATE_NAME = "customizedState1";
+ private final String INSTANCE_NAME = "localhost_1";
+
+ @Test
+ public void testCachedCustomizedViews() throws Exception {
+ String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
+
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
+ HelixManager manager = new DummyClusterManager(clusterName, accessor);
+
+ setupLiveInstances(clusterName, new int[]{0, 1});
+ setupStateModel(clusterName);
+
+ ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+ ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
+ event.addAttribute(AttributeName.helixmanager.name(), manager);
+ event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
+
+ CustomizedStateConfig config = new CustomizedStateConfig();
+ List<String> aggregationEnabledTypes = new ArrayList<>();
+ aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
+ config.setAggregationEnabledTypes(aggregationEnabledTypes);
+
+ PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.customizedStateConfig(), config);
+
+ CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
+ customizedState.setState(PARTITION_NAME, "STARTED");
+ accessor
+ .setProperty(keyBuilder.customizedState(INSTANCE_NAME, "customizedState1", RESOURCE_NAME),
+ customizedState);
+
+ CustomizedViewAggregationStage customizedViewComputeStage =
+ new CustomizedViewAggregationStage();
+ Pipeline dataRefresh = new Pipeline();
+ dataRefresh.addStage(new ReadClusterDataStage());
+ runPipeline(event, dataRefresh);
+ runStage(event, new ResourceComputationStage());
+ runStage(event, new CustomizedStateComputationStage());
+ runStage(event, customizedViewComputeStage);
+ Assert.assertEquals(cache.getCustomizedViewCacheMap().values(),
Review comment:
And also here. Collection vs List. Would be better to make them 2 sets.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392729094
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,164 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ cache.refreshCustomizedViewMap(dataAccessor);
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
+ }
+
+ List<String> customizedViewsToRemove = new ArrayList<>();
+
+ // remove stale customized views
+ for (String resourceName : curCustomizedViews.keySet()) {
+ if (!resourceMap.keySet().contains(resourceName)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for resource: " + resourceName);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType, resourceName));
+ customizedViewsToRemove.add(resourceName);
+ }
+ }
+ customizedViewCache.removeCustomizedView(customizedViewsToRemove);
+ } catch (HelixException ex) {
+ LogUtil.logError(LOG, _eventId,
+ "Failed to calculate customized view for resource " + resource.getResourceName(), ex);
+ }
+ }
+ }
+ }
+
+ private void computeCustomizedStateView(final Resource resource, final String stateType,
+ CustomizedStateOutput customizedStateOutput,
+ final Map<String, CustomizedView> curCustomizedViews,
+ List<CustomizedView> newCustomizedViews) {
Review comment:
Shall we call it updatedCustomizedViews to be clearer?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392546784
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
+ }
+
+ for (Resource resource : resourceMap.values()) {
+ try {
+ computeCustomizedStateView(resource, stateType, customizedStateOutput, curCustomizedViews,
+ newCustomizedViews);
+ // Keep MBeans for existing resources and unregister MBeans for dropped resources
+ if (clusterStatusMonitor != null) {
+ clusterStatusMonitor.retainResourceMonitor(monitoringResources);
+ }
+
+ List<PropertyKey> keys = new ArrayList<>();
+ for (Iterator<CustomizedView> it = newCustomizedViews.iterator(); it.hasNext(); ) {
+ CustomizedView view = it.next();
+ String resourceName = view.getResourceName();
+ keys.add(keyBuilder.customizedView(stateType, resourceName));
+ }
+ // add/update customized-views
+ if (newCustomizedViews.size() > 0) {
+ dataAccessor.setChildren(keys, newCustomizedViews);
+ customizedViewCache.refresh(dataAccessor);
Review comment:
Shall we just pass the in-memory content to the cache instead of requiring it to read from ZK again?
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] zhangmeng916 commented on a change in pull request #888:
Modify data providers and add customized view aggregation stage
Posted by GitBox <gi...@apache.org>.
zhangmeng916 commented on a change in pull request #888: Modify data providers and add customized view aggregation stage
URL: https://github.com/apache/helix/pull/888#discussion_r392560516
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/CustomizedViewAggregationStage.java
##########
@@ -0,0 +1,171 @@
+package org.apache.helix.controller.stages;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.CustomizedViewCache;
+import org.apache.helix.controller.LogUtil;
+import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider;
+import org.apache.helix.controller.pipeline.AbstractAsyncBaseStage;
+import org.apache.helix.controller.pipeline.AsyncWorkerType;
+import org.apache.helix.controller.pipeline.StageException;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
+import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CustomizedViewAggregationStage extends AbstractAsyncBaseStage {
+ private static Logger LOG = LoggerFactory.getLogger(CustomizedViewAggregationStage.class);
+
+ @Override
+ public AsyncWorkerType getAsyncWorkerType() {
+ return AsyncWorkerType.CustomizedStateViewComputeWorker;
+ }
+
+ @Override
+ public void execute(final ClusterEvent event) throws Exception {
+ _eventId = event.getEventId();
+ HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
+ Map<String, Resource> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
+ ResourceControllerDataProvider cache =
+ event.getAttribute(AttributeName.ControllerDataProvider.name());
+
+ if (manager == null || resourceMap == null || cache == null) {
+ throw new StageException(
+ "Missing attributes in event:" + event + ". Requires ClusterManager|RESOURCES|DataCache");
+ }
+
+ HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
+ PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+
+ CustomizedStateOutput customizedStateOutput =
+ event.getAttribute(AttributeName.CUSTOMIZED_STATE.name());
+ ClusterStatusMonitor clusterStatusMonitor =
+ event.getAttribute(AttributeName.clusterStatusMonitor.name());
+
+ List<CustomizedView> newCustomizedViews = new ArrayList<>();
+ Set<String> monitoringResources = new HashSet<>();
+
+ Map<String, CustomizedViewCache> customizedViewCacheMap = cache.getCustomizedViewCacheMap();
+ cache.refreshCustomizedViewMap(dataAccessor);
+
+ // remove stale customized view type from ZK and cache
+ List<String> customizedViewTypesToRemove = new ArrayList<>();
+ for (String stateType : customizedViewCacheMap.keySet()) {
+ if (!customizedStateOutput.getAllStateTypes().contains(stateType)) {
+ LogUtil.logInfo(LOG, _eventId, "Remove customizedView for stateType: " + stateType);
+ dataAccessor.removeProperty(keyBuilder.customizedView(stateType));
+ customizedViewTypesToRemove.add(stateType);
+ }
+ }
+
+ cache.removeCustomizedViewTypes(customizedViewTypesToRemove);
+
+ // update customized view
+ for (String stateType : customizedStateOutput.getAllStateTypes()) {
+ Map<String, CustomizedView> curCustomizedViews = new HashMap<>();
+ CustomizedViewCache customizedViewCache = customizedViewCacheMap.get(stateType);
+ if (customizedViewCache != null) {
+ curCustomizedViews = customizedViewCache.getCustomizedViewMap();
+ } else {
+ customizedViewCache = new CustomizedViewCache(event.getClusterName(), stateType);
Review comment:
The logic here is that if customizedViewCache is not null, we will get the mapping (resource -> customizedView) from the cache, and use that in the later computation stage. However, if the customizedViewCache is null, meaning the stateType does not exist in the customizedViewCache list, we will initialize a new customizedViewCache for it.
----------------------------------------------------------------
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
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org