You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by "xyuanlu (via GitHub)" <gi...@apache.org> on 2023/10/12 19:00:18 UTC

[PR] Rest cache - property cache [helix]

xyuanlu opened a new pull request, #2658:
URL: https://github.com/apache/helix/pull/2658

   ### Issues
   
   - [ ] My PR addresses the following Helix issues and references them in the PR description:
   
   (#200 - Link your issue number here: You can write "Fixes #XXX". Please use the proper keyword so that the issue gets closed automatically. See https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue
   Any of the following keywords can be used: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved)
   
   ### Description
   
   - [ ] Here are some details about my PR, including screenshots of any UI changes:
   
   (Write a concise description including what, why, how)
   
   ### Tests
   
   - [ ] The following tests are written for this issue:
   
   (List the names of added unit/integration tests)
   
   - The following is the result of the "mvn test" command on the appropriate module:
   
   (If CI test fails due to known issue, please specify the issue and test PR locally. Then copy & paste the result of "mvn test" to here.)
   
   ### Changes that Break Backward Compatibility (Optional)
   
   - My PR contains changes that break backward compatibility or previous assumptions for certain methods or API. They include:
   
   (Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
   
   ### Documentation (Optional)
   
   - In case of new functionality, my PR adds documentation in the following wiki page:
   
   (Link the GitHub wiki you added)
   
   ### Commits
   
   - My commits all reference appropriate Apache Helix GitHub issues in their subject lines. 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
   
   - My diff has been formatted using helix-style.xml 
   (helix-style-intellij.xml if IntelliJ IDE is used)
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


Re: [PR] Rest cache - property cache [helix]

Posted by "xyuanlu (via GitHub)" <gi...@apache.org>.
xyuanlu closed pull request #2658: Rest cache - property cache
URL: https://github.com/apache/helix/pull/2658


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


Re: [PR] Rest cache - property cache [helix]

Posted by "MarkGaox (via GitHub)" <gi...@apache.org>.
MarkGaox commented on code in PR #2658:
URL: https://github.com/apache/helix/pull/2658#discussion_r1358920727


##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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 org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.PropertyCache;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterConstraints;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+/**
+ * Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated
+ * using event changes. External view are consolidated using current state.
+ */
+public class PerClusterDataProvider {
+
+  private HelixDataAccessor _accessor;
+
+  private RealmAwareZkClient _zkclient;
+
+  private final String _clusterName;
+
+  // Simple caches
+  private final RestPropertyCache<InstanceConfig> _instanceConfigCache;
+  private final RestPropertyCache<ClusterConfig> _clusterConfigCache;
+  private final RestPropertyCache<ResourceConfig> _resourceConfigCache;
+  private final RestPropertyCache<LiveInstance> _liveInstanceCache;
+  private final RestPropertyCache<IdealState> _idealStateCache;
+  private final RestPropertyCache<StateModelDefinition> _stateModelDefinitionCache;
+
+  // special caches
+  private final RestCurrentStateCache _currentStateCache;
+
+  // TODO: add external view caches
+
+  public PerClusterDataProvider(String clusterName, RealmAwareZkClient zkClient, BaseDataAccessor baseDataAccessor) {
+    _clusterName = clusterName;
+    _accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+    _zkclient = zkClient;
+    _instanceConfigCache = null;
+    _clusterConfigCache = null;
+    _resourceConfigCache = null;
+    _liveInstanceCache = null;
+    _idealStateCache = null;
+    _stateModelDefinitionCache = null;
+    _currentStateCache = null;
+  }
+  // TODO: consolidate EV from CSs
+  public Map<String, ExternalView> consolidateExternalViews() {

Review Comment:
   Just to understand, if the stoppable check wants to get the external view from the cache, it should call `consolidateExternalViews `which will generate EV by the data from `RestCurrentStateCache`? Is that the plan?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


Re: [PR] Rest cache - property cache [helix]

Posted by "junkaixue (via GitHub)" <gi...@apache.org>.
junkaixue commented on PR #2658:
URL: https://github.com/apache/helix/pull/2658#issuecomment-1942867093

   Is this still a valid change?


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


Re: [PR] Rest cache - property cache [helix]

Posted by "junkaixue (via GitHub)" <gi...@apache.org>.
junkaixue commented on code in PR #2658:
URL: https://github.com/apache/helix/pull/2658#discussion_r1481841947


##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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 org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.PropertyCache;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterConstraints;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+/**
+ * Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated
+ * using event changes. External view are consolidated using current state.
+ */
+public class PerClusterDataProvider {
+
+  private HelixDataAccessor _accessor;
+
+  private RealmAwareZkClient _zkclient;
+
+  private final String _clusterName;
+
+  // Simple caches
+  private final RestPropertyCache<InstanceConfig> _instanceConfigCache;
+  private final RestPropertyCache<ClusterConfig> _clusterConfigCache;
+  private final RestPropertyCache<ResourceConfig> _resourceConfigCache;

Review Comment:
   Do we need ResourceConfig cache?



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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 org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.PropertyCache;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterConstraints;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+/**
+ * Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated
+ * using event changes. External view are consolidated using current state.
+ */
+public class PerClusterDataProvider {
+
+  private HelixDataAccessor _accessor;
+
+  private RealmAwareZkClient _zkclient;

Review Comment:
   Why not use meta client.



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/HelixRestDataProviderManager.java:
##########
@@ -0,0 +1,68 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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.
+ *
+ */
+
+/** Init, register listener and manager callback handler for different
+ * clusters manage the providers lifecycle
+ *
+ */
+
+import java.util.List;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+public class HelixRestDataProviderManager {
+
+  protected RealmAwareZkClient _zkclient;
+
+  private HelixAdmin _helixAdmin;
+
+  private RestServiceDataProvider _restServiceDataProvider;
+  // list of callback handlers
+
+  //TODO: create own zk client
+  public HelixRestDataProviderManager(RealmAwareZkClient zkclient, HelixAdmin helixAdmin) {
+    _zkclient = zkclient;
+    _helixAdmin = helixAdmin;
+    _restServiceDataProvider = new RestServiceDataProvider();
+    init();
+  }
+
+  public RestServiceDataProvider getRestServiceDataProvider() {
+    return _restServiceDataProvider;
+  }
+
+  private void init() {
+    List<String> clusters = _helixAdmin.getClusters();
+    for (String cluster : clusters) {
+      PerClusterDataProvider clusterDataProvider =
+          new PerClusterDataProvider(cluster, _zkclient, new ZkBaseDataAccessor(_zkclient));
+      clusterDataProvider.initCache();
+      // register callback handler for each provider
+      _restServiceDataProvider.addClusterDataProvider(cluster, clusterDataProvider);
+    }
+  }
+
+  public void close() {

Review Comment:
   Close should pair with connect / start. Do you want to make it as thread based class?



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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 org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.PropertyCache;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterConstraints;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+/**
+ * Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated

Review Comment:
   Typo: 
   Dara -> Data
   ideal stats -> ideal states



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/HelixRestDataProviderManager.java:
##########
@@ -0,0 +1,68 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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.
+ *
+ */
+
+/** Init, register listener and manager callback handler for different
+ * clusters manage the providers lifecycle
+ *
+ */

Review Comment:
   Wrong place for comments.



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestCurrentStateCache.java:
##########
@@ -0,0 +1,42 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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.concurrent.ConcurrentHashMap;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.model.CurrentState;
+
+
+/**
+ * Special cache for instances current states.
+ *
+ */
+public class RestCurrentStateCache {
+
+  //Map<instanceName, Map<ResourceName, CurrentState>>
+  private ConcurrentHashMap<String, ConcurrentHashMap<String, CurrentState>>  _objCache;
+
+  public RestCurrentStateCache() {
+    _objCache = new ConcurrentHashMap<>();
+  }
+
+  public void init(final HelixDataAccessor accessor) {
+  }
+}

Review Comment:
   NIT: extra new line.



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestCurrentStateCache.java:
##########
@@ -0,0 +1,42 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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.concurrent.ConcurrentHashMap;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.model.CurrentState;
+
+
+/**
+ * Special cache for instances current states.

Review Comment:
   Why not CurrentStateCache instead of building its own?



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestServiceDataProvider.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+
+public class RestServiceDataProvider {
+  protected Map<String, PerClusterDataProvider> _clusterDataProviders ;

Review Comment:
   make it concurrent? What if remove cluster and read together?



##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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 org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.PropertyCache;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterConstraints;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+/**
+ * Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated
+ * using event changes. External view are consolidated using current state.
+ */
+public class PerClusterDataProvider {
+
+  private HelixDataAccessor _accessor;
+
+  private RealmAwareZkClient _zkclient;
+
+  private final String _clusterName;
+
+  // Simple caches
+  private final RestPropertyCache<InstanceConfig> _instanceConfigCache;
+  private final RestPropertyCache<ClusterConfig> _clusterConfigCache;
+  private final RestPropertyCache<ResourceConfig> _resourceConfigCache;
+  private final RestPropertyCache<LiveInstance> _liveInstanceCache;
+  private final RestPropertyCache<IdealState> _idealStateCache;
+  private final RestPropertyCache<StateModelDefinition> _stateModelDefinitionCache;

Review Comment:
   Do we need this?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


Re: [PR] Rest cache - property cache [helix]

Posted by "MarkGaox (via GitHub)" <gi...@apache.org>.
MarkGaox commented on code in PR #2658:
URL: https://github.com/apache/helix/pull/2658#discussion_r1366042565


##########
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java:
##########
@@ -424,6 +426,14 @@ private Map<String, ResourceAssignment> handleDelayedRebalanceMinActiveReplica(
     }
   }
 
+  private static Set<String> filterOutOnOperationInstances(Map<String, InstanceConfig> instanceConfigMap,
+      Set<String> nodes) {
+    return nodes.stream()
+        .filter(
+            instance -> !DelayedAutoRebalancer.INSTANCE_OPERATION_TO_EXCLUDE_FROM_ASSIGNMENT.contains(instanceConfigMap.get(instance).getInstanceOperation()))

Review Comment:
   We probably need checks before `instanceConfigMap.get()`



##########
helix-core/src/test/java/org/apache/helix/integration/rebalancer/TestInstanceOperation.java:
##########
@@ -338,21 +341,38 @@ public void testMarkEvacuationAfterEMM() throws Exception {
 
   @Test(dependsOnMethods = "testMarkEvacuationAfterEMM")
   public void testEvacuationWithOfflineInstancesInCluster() throws Exception {
+    _participants.get(1).syncStop();
     _participants.get(2).syncStop();
-    _participants.get(3).syncStop();
-    // wait for converge, and set evacuate on instance 0
-    Assert.assertTrue(_clusterVerifier.verifyByPolling());
 
-    String evacuateInstanceName =  _participants.get(0).getInstanceName();
+    String evacuateInstanceName =  _participants.get(_participants.size()-2).getInstanceName();
     _gSetupTool.getClusterManagementTool()
         .setInstanceOperation(CLUSTER_NAME, evacuateInstanceName, InstanceConstants.InstanceOperation.EVACUATE);
 
-    Map<String, IdealState> assignment;
-    List<String> currentActiveInstances =
-        _participantNames.stream().filter(n -> (!n.equals(evacuateInstanceName) && !n.equals(_participants.get(3).getInstanceName()))).collect(Collectors.toList());
-    TestHelper.verify( ()-> {return verifyIS(evacuateInstanceName);}, TestHelper.WAIT_DURATION);
+    Map<String, ExternalView> assignment;
+    // EV should contain all participants, check resources one by one
+    assignment = getEV();
+    for (String resource : _allDBs) {
+      ExternalView ev = assignment.get(resource);
+      for (String partition : ev.getPartitionSet()) {
+        AtomicInteger activeReplicaCount = new AtomicInteger();
+        ev.getStateMap(partition)
+            .values()
+            .stream()
+            .filter(
+                v -> v.equals("MASTER") || v.equals("LEADER") || v.equals("SLAVE") || v.equals("FOLLOWER") || v.equals(
+                    "STANDBY"))
+            .forEach(v -> activeReplicaCount.getAndIncrement());
+        Assert.assertTrue(activeReplicaCount.get() >= REPLICA-1);
+        Assert.assertFalse(ev.getStateMap(partition).containsKey(evacuateInstanceName) && ev.getStateMap(partition)
+            .get(evacuateInstanceName)
+            .equals("MASTER") && ev.getStateMap(partition)
+            .get(evacuateInstanceName)
+            .equals("LEADER"));
+

Review Comment:
   nit: empty line



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


Re: [PR] Rest cache - property cache [helix]

Posted by "xyuanlu (via GitHub)" <gi...@apache.org>.
xyuanlu commented on code in PR #2658:
URL: https://github.com/apache/helix/pull/2658#discussion_r1359177240


##########
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.helix.rest.common.dataprovider;
+
+/*
+ * 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 org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.common.caches.PropertyCache;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterConstraints;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+
+
+/**
+ * Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated
+ * using event changes. External view are consolidated using current state.
+ */
+public class PerClusterDataProvider {
+
+  private HelixDataAccessor _accessor;
+
+  private RealmAwareZkClient _zkclient;
+
+  private final String _clusterName;
+
+  // Simple caches
+  private final RestPropertyCache<InstanceConfig> _instanceConfigCache;
+  private final RestPropertyCache<ClusterConfig> _clusterConfigCache;
+  private final RestPropertyCache<ResourceConfig> _resourceConfigCache;
+  private final RestPropertyCache<LiveInstance> _liveInstanceCache;
+  private final RestPropertyCache<IdealState> _idealStateCache;
+  private final RestPropertyCache<StateModelDefinition> _stateModelDefinitionCache;
+
+  // special caches
+  private final RestCurrentStateCache _currentStateCache;
+
+  // TODO: add external view caches
+
+  public PerClusterDataProvider(String clusterName, RealmAwareZkClient zkClient, BaseDataAccessor baseDataAccessor) {
+    _clusterName = clusterName;
+    _accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+    _zkclient = zkClient;
+    _instanceConfigCache = null;
+    _clusterConfigCache = null;
+    _resourceConfigCache = null;
+    _liveInstanceCache = null;
+    _idealStateCache = null;
+    _stateModelDefinitionCache = null;
+    _currentStateCache = null;
+  }
+  // TODO: consolidate EV from CSs
+  public Map<String, ExternalView> consolidateExternalViews() {

Review Comment:
   It should just call getEV. consolidateExternalViews will be called internal in this data provider



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org