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/08/03 21:31:08 UTC

[GitHub] [helix] zhangmeng916 commented on a change in pull request #1197: Support option to skip direct ZK read for health check API

zhangmeng916 commented on a change in pull request #1197:
URL: https://github.com/apache/helix/pull/1197#discussion_r464668238



##########
File path: helix-rest/src/main/java/org/apache/helix/rest/common/HelixDataAccessorWrapper.java
##########
@@ -64,24 +63,47 @@ public HelixDataAccessorWrapper(ZKHelixDataAccessor dataAccessor) {
     _restClient = CustomRestClientFactory.get();
   }
 
+  public HelixDataAccessorWrapper(ZKHelixDataAccessor dataAccessor, CustomRestClient customRestClient) {
+    super(dataAccessor);
+    _restClient = customRestClient;
+  }
+
   public Map<String, Map<String, Boolean>> getAllPartitionsHealthOnLiveInstance(
       RESTConfig restConfig, Map<String, String> customPayLoads) {
+    return getAllPartitionsHealthOnLiveInstance(restConfig, customPayLoads, false);
+  }
+
+  /**
+   * Retrieve partition health status for each live instances combined with reading health partition report from ZK
+   * and customized REST API call.
+   *
+   * @param restConfig        restConfig for the cluster contains customize REST API endpoint
+   * @param customPayLoads    user passed in customized payloads
+   * @param skipZKRead        skip the ZK read if this flag is true
+   * @return                  A map of instance -> partition -> healthy or not (boolean).
+   */
+  public Map<String, Map<String, Boolean>> getAllPartitionsHealthOnLiveInstance(
+      RESTConfig restConfig, Map<String, String> customPayLoads, boolean skipZKRead) {
     // Only checks the instances are online with valid reports
     List<String> liveInstances = getChildNames(keyBuilder().liveInstances());
     // Make a parallel batch call for getting all healthreports from ZK.
-    List<HelixProperty> zkHealthReports = getProperty(liveInstances.stream()
-        .map(instance -> keyBuilder().healthReport(instance, PARTITION_HEALTH_KEY))
-        .collect(Collectors.toList()), false);
+    List<HelixProperty> zkHealthReports;
+    if (!skipZKRead) {
+      zkHealthReports = getProperty(liveInstances.stream()
+          .map(instance -> keyBuilder().healthReport(instance, PARTITION_HEALTH_KEY))
+          .collect(Collectors.toList()), false);
+    } else {
+      zkHealthReports =
+          liveInstances.stream().map(instance -> new HelixProperty(instance)).collect(Collectors.toList());
+    }
     Map<String, Future<Map<String, Boolean>>> parallelTasks = new HashMap<>();
     for (int i = 0; i < liveInstances.size(); i++) {
       String liveInstance = liveInstances.get(i);
-      Optional<ZNRecord> maybeHealthRecord =
-          Optional.ofNullable(zkHealthReports.get(i)).map(HelixProperty::getRecord);
-      parallelTasks.put(liveInstance,
-          POOL.submit(() -> maybeHealthRecord
-              .map(record -> getPartitionsHealth(liveInstance, record, restConfig, customPayLoads))
-              .orElseGet(() -> getHealthStatusFromRest(liveInstance, Collections.emptyList(),
-                  restConfig, customPayLoads))));
+      Optional<ZNRecord> maybeHealthRecord = Optional.ofNullable(zkHealthReports.get(i)).map(HelixProperty::getRecord);
+      parallelTasks.put(liveInstance, POOL.submit(() -> maybeHealthRecord.map(
+          record -> getPartitionsHealthFromCustomAPI(liveInstance, record, restConfig, customPayLoads, skipZKRead))
+          .orElseGet(
+              () -> getHealthStatusFromRest(liveInstance, Collections.emptyList(), restConfig, customPayLoads))));

Review comment:
       Why we cannot combine this case together with the case where skipZKRead is set to true? Is that because backward compatibility make it harder to code? 




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



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