helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [helix] branch master updated: Improve ZK read with batch call
Date Wed, 07 Aug 2019 23:57:19 GMT
This is an automated email from the ASF dual-hosted git repository.

jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new e4e8ee9  Improve ZK read with batch call
e4e8ee9 is described below

commit e4e8ee90b94abf13e9cf2062a67d435da6abb794
Author: Junkai Xue <jxue@linkedin.com>
AuthorDate: Mon Aug 5 16:33:50 2019 -0700

    Improve ZK read with batch call
    
    Current HealthReport read is single call for each participant. Improve it will batch call
to ZK to reduce the number of calls.
---
 .../helix/rest/server/service/InstanceServiceImpl.java     | 14 ++++++++++----
 .../helix/rest/server/service/TestInstanceService.java     | 11 +++++------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
index 90e32d3..79188bc 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
@@ -31,6 +31,7 @@ import java.util.stream.Collectors;
 import org.apache.helix.ConfigAccessor;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixException;
+import org.apache.helix.HelixProperty;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.model.CurrentState;
@@ -222,10 +223,15 @@ public class InstanceServiceImpl implements InstanceService {
     // Only checks the instances are online with valid reports
     List<String> liveInstances =
         _dataAccessor.getChildNames(_dataAccessor.keyBuilder().liveInstances());
-    for (String instance : liveInstances) {
-      ZNRecord customizedHealth = _dataAccessor
-          .getProperty(_dataAccessor.keyBuilder().healthReport(instance, PARTITION_HEALTH_KEY))
-          .getRecord();
+    // Make a parallel batch call for getting all healthreports from ZK.
+    List<HelixProperty> healthReports = _dataAccessor.getProperty(liveInstances.stream()
+        .map(instance -> _dataAccessor.keyBuilder().healthReport(instance, PARTITION_HEALTH_KEY))
+        .collect(Collectors.toList()));
+    for (int i = 0; i < liveInstances.size(); i++) {
+      String instance = liveInstances.get(i);
+      // TODO: Check ZNRecord is null or not. Need logic to check whether the healthreports
exist
+      // or not. If it does not exist, we should query the participant directly for the health
report.
+      ZNRecord customizedHealth = healthReports.get(i).getRecord();
       for (String partitionName : customizedHealth.getMapFields().keySet()) {
         try {
           Map<String, String> healthMap = customizedHealth.getMapField(partitionName);
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/service/TestInstanceService.java
b/helix-rest/src/test/java/org/apache/helix/rest/server/service/TestInstanceService.java
index bc2e05c..2945580 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/service/TestInstanceService.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/service/TestInstanceService.java
@@ -135,12 +135,11 @@ public class TestInstanceService {
     when(_dataAccessor.keyBuilder()).thenReturn(new PropertyKey.Builder(TEST_CLUSTER));
     when(_dataAccessor.getChildNames(new PropertyKey.Builder(TEST_CLUSTER).liveInstances()))
         .thenReturn(Arrays.asList("host0", "host1"));
-    when(_dataAccessor.getProperty(
-        new PropertyKey.Builder(TEST_CLUSTER).healthReport("host0", "PARTITION_HEALTH")))
-        .thenReturn(new HealthStat(healthData.get(0)));
-    when(_dataAccessor.getProperty(
-        new PropertyKey.Builder(TEST_CLUSTER).healthReport("host1", "PARTITION_HEALTH")))
-        .thenReturn(new HealthStat(healthData.get(1)));
+    when(_dataAccessor.getProperty(Arrays
+        .asList(new PropertyKey.Builder(TEST_CLUSTER).healthReport("host0", "PARTITION_HEALTH"),
+            new PropertyKey.Builder(TEST_CLUSTER).healthReport("host1", "PARTITION_HEALTH"))))
+        .thenReturn(
+            Arrays.asList(new HealthStat(healthData.get(0)), new HealthStat(healthData.get(1))));
     PartitionHealth computeResult = service.generatePartitionHealthMapFromZK();
     PartitionHealth expectedResult = generateExpectedResult();
     Assert.assertEquals(computeResult, expectedResult);


Mime
View raw message