sajjad-moradi commented on code in PR #8877:
URL: https://github.com/apache/pinot/pull/8877#discussion_r896234956


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/realtime/MissingConsumingSegmentFinder.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.controller.helix.core.realtime;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.helix.AccessOption;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metrics.ControllerGauge;
+import org.apache.pinot.common.metrics.ControllerMeter;
+import org.apache.pinot.common.metrics.ControllerMetrics;
+import org.apache.pinot.common.utils.LLCSegmentName;
+import 
org.apache.pinot.spi.utils.CommonConstants.Helix.StateModel.SegmentStateModel;
+import org.apache.zookeeper.data.Stat;
+
+
+/**
+ * For a given table, this class finds out if there is any partition group for 
which there's no consuming segment in
+ * ideal state. If so, it emits two metrics:
+ *   - Number of missing consuming segments
+ *   - Maximum duration (in minutes) that a partition hasn't had a consuming 
segment
+ */
+public class MissingConsumingSegmentFinder {
+
+  private String _realtimeTableName;
+  private ControllerMetrics _controllerMetrics;
+  private SegmentMetadataFetcher _segmentMetadataFetcher;
+
+  public MissingConsumingSegmentFinder(String realtimeTableName, 
ZkHelixPropertyStore<ZNRecord> propertyStore,
+      ControllerMetrics controllerMetrics) {
+    _realtimeTableName = realtimeTableName;
+    _controllerMetrics = controllerMetrics;
+    _segmentMetadataFetcher = new SegmentMetadataFetcher(propertyStore, 
controllerMetrics);
+  }
+
+  @VisibleForTesting
+  MissingConsumingSegmentFinder(String realtimeTableName, 
SegmentMetadataFetcher segmentMetadataFetcher) {
+    _realtimeTableName = realtimeTableName;
+    _segmentMetadataFetcher = segmentMetadataFetcher;
+  }
+
+  public void findAndEmitMetrics(IdealState idealState) {
+    MissingSegmentInfo info = 
findMissingSegments(idealState.getRecord().getMapFields(), Instant.now());
+    _controllerMetrics.setValueOfTableGauge(_realtimeTableName, 
ControllerGauge.MISSING_CONSUMING_SEGMENT_COUNT,
+        info._count);
+    _controllerMetrics
+        .setValueOfTableGauge(_realtimeTableName, 
ControllerGauge.MISSING_CONSUMING_SEGMENT_MAX_DURATION_MINUTES,
+            info._maxDurationInMinutes);
+  }
+
+  @VisibleForTesting
+  MissingSegmentInfo findMissingSegments(Map<String, Map<String, String>> 
idealStateMap, Instant now) {
+    // create the maps
+    Map<Integer, LLCSegmentName> partitionGroupIdToLatestConsumingSegmentMap = 
new HashMap<>();
+    Map<Integer, LLCSegmentName> partitionGroupIdToLatestCompletedSegmentMap = 
new HashMap<>();
+    idealStateMap.forEach((segmentName, instanceToStatusMap) -> {
+      LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName);
+      if (llcSegmentName != null) { // Skip the uploaded realtime segments 
that don't conform to llc naming
+        if (instanceToStatusMap.containsValue(SegmentStateModel.CONSUMING)) {
+          updateMap(partitionGroupIdToLatestConsumingSegmentMap, 
llcSegmentName);

Review Comment:
   1) My understanding is that if a consuming segment encounters a permanent 
error, it calls controller to mark it as OFFLINE in ideal state. So for these 
cases, the last consumed time is when the previous completed segment went to 
ONLINE state. 
   2) We can ignore the new partition cases as Segment Validation Manager is 
going to create a new consuming segment for them. If we wanted to detect them, 
then we'd need to fetch the metadata for the stream which may be problematic 
(please refer to next comment).



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

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

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