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



##########
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:
       Because there are a couple of scenarios:
   1. Partitions read from ZK, they are all healthy. No expired partitions. 
Directly return the ZK partition data.
   2. Partitions read from ZK, there are some expired partitions, query SN to 
get latest update.
   3. Partitions skip read from ZK, no partition data from ZK and no expired 
data, query SN without any partition specific to get all partition health 
status.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to