mayankshriv commented on a change in pull request #6890:
URL: https://github.com/apache/incubator-pinot/pull/6890#discussion_r632197571



##########
File path: 
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/TableStatus.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.
+ */
+
+package org.apache.pinot.spi.config.table;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+
+/**
+ * Container object to encapsulate table status which contains
+ * - Ingestion status: specifies if the table is ingesting properly or not
+ */
+public class TableStatus {
+
+  private IngestionStatus _ingestionStatus;
+
+  public enum IngestionState {
+    HEALTHY,
+    UNHEALTHY
+  }
+
+  public static class IngestionStatus {

Review comment:
       Always good to add `@JsonIgnoreProperties(ignoreUnknown = true)`
   

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/util/ConsumingSegmentInfoReader.java
##########
@@ -131,6 +134,51 @@ private String generateServerURL(String tableNameWithType, 
String endpoint) {
     return String.format("%s/tables/%s/consumingSegmentsInfo", endpoint, 
tableNameWithType);
   }
 
+  /**
+   * Utility method to derive ingestion status from consuming segment Info. 
Status is HEALTHY if
+   * consuming segment info specifies CONSUMING state for all active segments 
across all servers
+   * including replicas.
+   */
+  public TableStatus.IngestionStatus getIngestionStatus(String 
tableNameWithType, int timeoutMs) {
+    try {
+      ConsumingSegmentsInfoMap consumingSegmentsInfoMap = 
getConsumingSegmentsInfo(tableNameWithType, timeoutMs);
+      for (Map.Entry<String, List<ConsumingSegmentInfo>> 
consumingSegmentInfoEntry : consumingSegmentsInfoMap._segmentToConsumingInfoMap
+          .entrySet()) {
+        String segmentName = consumingSegmentInfoEntry.getKey();
+        List<ConsumingSegmentInfo> consumingSegmentInfoList = 
consumingSegmentInfoEntry.getValue();
+        if (consumingSegmentInfoList == null || 
consumingSegmentInfoList.isEmpty()) {
+          String errorMessage = "Did not get any response from servers for 
segment: " + segmentName;
+          return 
TableStatus.IngestionStatus.newIngestionStatus(TableStatus.IngestionState.UNHEALTHY,
 errorMessage);
+        }
+
+        // Check if any responses are missing
+        Set<String> serversForSegment = 
_pinotHelixResourceManager.getServersForSegment(tableNameWithType, segmentName);
+        if (serversForSegment.size() != consumingSegmentInfoList.size()) {
+          Set<String> serversResponded =
+              consumingSegmentInfoList.stream().map(c -> 
c._serverName).collect(Collectors.toSet());
+          serversForSegment.removeAll(serversResponded);
+          String errorMessage =
+              "Not all servers responded for segment: " + segmentName + " 
Missing servers : " + serversForSegment;
+          return 
TableStatus.IngestionStatus.newIngestionStatus(TableStatus.IngestionState.UNHEALTHY,
 errorMessage);
+        }
+
+        for (ConsumingSegmentInfo consumingSegmentInfo : 
consumingSegmentInfoList) {
+          if (consumingSegmentInfo._consumerState
+              .equals(ConsumerState.NOT_CONSUMING.toString())) {

Review comment:
       We stop consumption during segment generation. Will that be treated as 
error?




-- 
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:
us...@infra.apache.org



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

Reply via email to