You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/06/10 21:50:17 UTC

[GitHub] [pinot] npawar commented on a diff in pull request #8877: Emit metrics if there's no consuming segment for a partition

npawar commented on code in PR #8877:
URL: https://github.com/apache/pinot/pull/8877#discussion_r894908251


##########
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:
   have you on purpose omitted the cases where there's no CONSUMING segment, but the ValidationManager will be fixing it?



##########
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:
   Like 1) OFFLINE state segment, or 2) when it was the very first segment that was deleted, hence no completed segment recorded 3) new partition
   I feel this should be a generic metric which says how many are not CONSUMING, and be oblivious to what is correctable ad what's not



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/realtime/PinotLLCRealtimeSegmentManager.java:
##########
@@ -874,6 +871,8 @@ public void ensureAllPartitionsConsuming(TableConfig tableConfig, PartitionLevel
     HelixHelper.updateIdealState(_helixManager, realtimeTableName, idealState -> {
       assert idealState != null;
       if (idealState.isEnabled()) {
+        new MissingConsumingSegmentFinder(realtimeTableName, _propertyStore, _controllerMetrics)

Review Comment:
   should this be run after the validation manager is done with the current round? Bit confusing that we first try to emit for what's missing and then immediately proceed to fixing.



-- 
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-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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