You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2022/07/28 00:13:51 UTC

[pinot] branch master updated: Optimize PinotHelixResourceManager.getServerToSegmentsMap() and getServers() (#9118)

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new e2b54e586b Optimize PinotHelixResourceManager.getServerToSegmentsMap() and getServers() (#9118)
e2b54e586b is described below

commit e2b54e586b973064a822cb8330f7b56578d4f8a7
Author: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
AuthorDate: Wed Jul 27 17:13:46 2022 -0700

    Optimize PinotHelixResourceManager.getServerToSegmentsMap() and getServers() (#9118)
---
 .../helix/core/PinotHelixResourceManager.java      | 36 ++++++++++------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
index c919c826e1..067ad2e250 100644
--- a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
+++ b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
@@ -414,10 +414,8 @@ public class PinotHelixResourceManager {
   }
 
   public List<InstanceConfig> getAllControllerInstanceConfigs() {
-    return HelixHelper.getInstanceConfigs(_helixZkManager)
-        .stream()
-        .filter(instance -> InstanceTypeUtils.isController(instance.getId()))
-        .collect(Collectors.toList());
+    return HelixHelper.getInstanceConfigs(_helixZkManager).stream()
+        .filter(instance -> InstanceTypeUtils.isController(instance.getId())).collect(Collectors.toList());
   }
 
   /**
@@ -2504,13 +2502,12 @@ public class PinotHelixResourceManager {
     if (idealState == null) {
       throw new IllegalStateException("Ideal state does not exist for table: " + tableNameWithType);
     }
-
-    for (String segment : idealState.getPartitionSet()) {
-      for (String server : idealState.getInstanceStateMap(segment).keySet()) {
-        serverToSegmentsMap.computeIfAbsent(server, key -> new ArrayList<>()).add(segment);
+    for (Map.Entry<String, Map<String, String>> entry : idealState.getRecord().getMapFields().entrySet()) {
+      String segmentName = entry.getKey();
+      for (String server : entry.getValue().keySet()) {
+        serverToSegmentsMap.computeIfAbsent(server, key -> new ArrayList<>()).add(segmentName);
       }
     }
-
     return serverToSegmentsMap;
   }
 
@@ -2522,11 +2519,10 @@ public class PinotHelixResourceManager {
     if (idealState == null) {
       throw new IllegalStateException("Ideal state does not exist for table: " + tableNameWithType);
     }
-
-    return idealState.getPartitionSet().stream()
-        .filter(segmentName::equals)
-        .flatMap(s -> idealState.getInstanceStateMap(s).keySet().stream())
-        .collect(Collectors.toSet());
+    Map<String, String> instanceStateMap = idealState.getInstanceStateMap(segmentName);
+    Preconditions.checkState(instanceStateMap != null, "Segment: {} does not exist in the ideal state of table: {}",
+        segmentName, tableNameWithType);
+    return instanceStateMap.keySet();
   }
 
   /**
@@ -3030,7 +3026,7 @@ public class PinotHelixResourceManager {
 
     if (tableNamesWithType.isEmpty()) {
       throw new TableNotFoundException(
-          "Table '" + tableName + (tableType != null ? "_" + tableType.toString() : "") + "' not found.");
+          "Table '" + tableName + (tableType != null ? "_" + tableType : "") + "' not found.");
     }
 
     return tableNamesWithType;
@@ -3217,8 +3213,9 @@ public class PinotHelixResourceManager {
         Thread.sleep(SEGMENT_CLEANUP_CHECK_INTERVAL_MS);
       }
     } while (System.currentTimeMillis() < endTimeMs);
-    throw new RuntimeException("Timeout while waiting for segments to be deleted for table: " + tableNameWithType
-        + ", timeout: " + timeOutInMillis + "ms");
+    throw new RuntimeException(
+        "Timeout while waiting for segments to be deleted for table: " + tableNameWithType + ", timeout: "
+            + timeOutInMillis + "ms");
   }
 
   /**
@@ -3318,7 +3315,7 @@ public class PinotHelixResourceManager {
    * @param tableNameWithType
    */
   public SegmentLineage listSegmentLineage(String tableNameWithType) {
-      return SegmentLineageAccessHelper.getSegmentLineage(_propertyStore, tableNameWithType);
+    return SegmentLineageAccessHelper.getSegmentLineage(_propertyStore, tableNameWithType);
   }
 
   /**
@@ -3620,8 +3617,7 @@ public class PinotHelixResourceManager {
       Map<String, String> taskProperties) {
     String periodicTaskRequestId = API_REQUEST_ID_PREFIX + UUID.randomUUID().toString().substring(0, 8);
 
-    LOGGER.info(
-        "[TaskRequestId: {}] Sending periodic task message to all controllers for running task {} against {},"
+    LOGGER.info("[TaskRequestId: {}] Sending periodic task message to all controllers for running task {} against {},"
             + " with properties {}.\"", periodicTaskRequestId, periodicTaskName,
         tableName != null ? " table '" + tableName + "'" : "all tables", taskProperties);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org