swaminathanmanish commented on code in PR #15008:
URL: https://github.com/apache/pinot/pull/15008#discussion_r1952034182


##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/DiskUtilizationChecker.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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.validation;
+
+import com.google.common.collect.BiMap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.restlet.resources.DiskUsageInfo;
+import org.apache.pinot.controller.ControllerConf;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.CompletionServiceHelper;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DiskUtilizationChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DiskUtilizationChecker.class);
+  private final int _resourceUtilizationCheckTimeoutMs;
+  private final long _resourceUtilizationCheckerFrequency;
+  private final double _diskUtilizationThreshold;
+  private final String _diskUtilizationPath;
+  private static final String DISK_UTILIZATION_API_PATH = 
"/instance/diskUtilization";
+
+  private final PinotHelixResourceManager _helixResourceManager;
+
+  public DiskUtilizationChecker(PinotHelixResourceManager 
helixResourceManager, ControllerConf controllerConf) {
+    _helixResourceManager = helixResourceManager;
+    _diskUtilizationPath = controllerConf.getDiskUtilizationPath();
+    _diskUtilizationThreshold = controllerConf.getDiskUtilizationThreshold();
+    _resourceUtilizationCheckTimeoutMs = 
controllerConf.getDiskUtilizationCheckTimeoutMs();
+    _resourceUtilizationCheckerFrequency = 
controllerConf.getResourceUtilizationCheckerFrequency();
+  }
+
+  public static String getDiskUtilizationApiPath() {
+    return DISK_UTILIZATION_API_PATH;
+  }
+
+  /**
+   * Check if disk utilization for the requested table is within the 
configured limits.
+   */
+  public boolean isDiskUtilizationWithinLimits(String tableNameWithType) {
+    if (StringUtils.isEmpty(tableNameWithType)) {
+      throw new IllegalArgumentException("Table name found to be null or empty 
while computing disk utilization.");
+    }
+    TableConfig tableConfig = 
_helixResourceManager.getTableConfig(tableNameWithType);
+    if (tableConfig == null) {
+      return true; // table does not exist

Review Comment:
   Curious when will this happen? After a table is deleted at the same time? 
   Can you log an error here 



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java:
##########
@@ -641,6 +652,13 @@ protected TaskSchedulingInfo 
scheduleTask(PinotTaskGenerator taskGenerator, List
     for (TableConfig tableConfig : enabledTableConfigs) {
       String tableName = tableConfig.getTableName();
       try {
+        if 
(!_resourceUtilizationManager.isResourceUtilizationWithinLimits(tableName)) {
+          String message =
+              "Skipping tasks generation as resource utilization is not within 
limits for table: " + tableName;

Review Comment:
   Could we also add specific reason (out of disk capacity or something? )
   
   There are 2 things
   1. Should this be task generation failure or silent log ?  This can happen 
more frequently than we think :) 
   2. How will user take action after seeing this message. 
   
   
   
   
   



##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/DiskUtilizationChecker.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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.validation;
+
+import com.google.common.collect.BiMap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.restlet.resources.DiskUsageInfo;
+import org.apache.pinot.controller.ControllerConf;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.CompletionServiceHelper;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DiskUtilizationChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DiskUtilizationChecker.class);
+  private final int _resourceUtilizationCheckTimeoutMs;
+  private final long _resourceUtilizationCheckerFrequency;
+  private final double _diskUtilizationThreshold;
+  private final String _diskUtilizationPath;
+  private static final String DISK_UTILIZATION_API_PATH = 
"/instance/diskUtilization";
+
+  private final PinotHelixResourceManager _helixResourceManager;
+
+  public DiskUtilizationChecker(PinotHelixResourceManager 
helixResourceManager, ControllerConf controllerConf) {
+    _helixResourceManager = helixResourceManager;
+    _diskUtilizationPath = controllerConf.getDiskUtilizationPath();
+    _diskUtilizationThreshold = controllerConf.getDiskUtilizationThreshold();
+    _resourceUtilizationCheckTimeoutMs = 
controllerConf.getDiskUtilizationCheckTimeoutMs();
+    _resourceUtilizationCheckerFrequency = 
controllerConf.getResourceUtilizationCheckerFrequency();
+  }
+
+  public static String getDiskUtilizationApiPath() {
+    return DISK_UTILIZATION_API_PATH;
+  }
+
+  /**
+   * Check if disk utilization for the requested table is within the 
configured limits.
+   */
+  public boolean isDiskUtilizationWithinLimits(String tableNameWithType) {
+    if (StringUtils.isEmpty(tableNameWithType)) {
+      throw new IllegalArgumentException("Table name found to be null or empty 
while computing disk utilization.");
+    }
+    TableConfig tableConfig = 
_helixResourceManager.getTableConfig(tableNameWithType);
+    if (tableConfig == null) {
+      return true; // table does not exist
+    }
+    List<String> instances;
+    if (TableNameBuilder.isOfflineTableResource(tableNameWithType)) {
+      instances = 
_helixResourceManager.getServerInstancesForTable(tableNameWithType, 
TableType.OFFLINE);
+    } else {
+      instances = 
_helixResourceManager.getServerInstancesForTable(tableNameWithType, 
TableType.REALTIME);
+    }
+    return isDiskUtilizationWithinLimits(instances);
+  }
+
+  private boolean isDiskUtilizationWithinLimits(List<String> instances) {
+    for (String instance : instances) {
+      DiskUsageInfo diskUsageInfo = 
ResourceUtilizationInfo.getDiskUsageInfo(instance);
+      if (diskUsageInfo == null) {
+        LOGGER.warn("Disk utilization info for server: {} is null", instance);
+        continue;
+      }
+      // Ignore if the disk utilization info is stale. The info is considered 
stale if it is older than the
+      // ResourceUtilizationChecker tasks frequency.
+      if (diskUsageInfo.getLastUpdatedTimeInEpochMs()

Review Comment:
   Why do we need lastUpdatedTimeInEpoch. This means we have this additional 
field to be updated correctly :)
   Can we not rely on the checkerFrequency itself. 



##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/DiskUtilizationChecker.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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.validation;
+
+import com.google.common.collect.BiMap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.restlet.resources.DiskUsageInfo;
+import org.apache.pinot.controller.ControllerConf;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.CompletionServiceHelper;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DiskUtilizationChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DiskUtilizationChecker.class);
+  private final int _resourceUtilizationCheckTimeoutMs;
+  private final long _resourceUtilizationCheckerFrequency;
+  private final double _diskUtilizationThreshold;
+  private final String _diskUtilizationPath;
+  private static final String DISK_UTILIZATION_API_PATH = 
"/instance/diskUtilization";
+
+  private final PinotHelixResourceManager _helixResourceManager;
+
+  public DiskUtilizationChecker(PinotHelixResourceManager 
helixResourceManager, ControllerConf controllerConf) {
+    _helixResourceManager = helixResourceManager;
+    _diskUtilizationPath = controllerConf.getDiskUtilizationPath();
+    _diskUtilizationThreshold = controllerConf.getDiskUtilizationThreshold();
+    _resourceUtilizationCheckTimeoutMs = 
controllerConf.getDiskUtilizationCheckTimeoutMs();
+    _resourceUtilizationCheckerFrequency = 
controllerConf.getResourceUtilizationCheckerFrequency();
+  }
+
+  public static String getDiskUtilizationApiPath() {
+    return DISK_UTILIZATION_API_PATH;
+  }
+
+  /**
+   * Check if disk utilization for the requested table is within the 
configured limits.
+   */
+  public boolean isDiskUtilizationWithinLimits(String tableNameWithType) {
+    if (StringUtils.isEmpty(tableNameWithType)) {
+      throw new IllegalArgumentException("Table name found to be null or empty 
while computing disk utilization.");
+    }
+    TableConfig tableConfig = 
_helixResourceManager.getTableConfig(tableNameWithType);
+    if (tableConfig == null) {
+      return true; // table does not exist
+    }
+    List<String> instances;
+    if (TableNameBuilder.isOfflineTableResource(tableNameWithType)) {
+      instances = 
_helixResourceManager.getServerInstancesForTable(tableNameWithType, 
TableType.OFFLINE);
+    } else {
+      instances = 
_helixResourceManager.getServerInstancesForTable(tableNameWithType, 
TableType.REALTIME);
+    }
+    return isDiskUtilizationWithinLimits(instances);
+  }
+
+  private boolean isDiskUtilizationWithinLimits(List<String> instances) {
+    for (String instance : instances) {
+      DiskUsageInfo diskUsageInfo = 
ResourceUtilizationInfo.getDiskUsageInfo(instance);
+      if (diskUsageInfo == null) {
+        LOGGER.warn("Disk utilization info for server: {} is null", instance);
+        continue;
+      }
+      // Ignore if the disk utilization info is stale. The info is considered 
stale if it is older than the
+      // ResourceUtilizationChecker tasks frequency.
+      if (diskUsageInfo.getLastUpdatedTimeInEpochMs()
+          < System.currentTimeMillis() - _resourceUtilizationCheckerFrequency) 
{
+        LOGGER.warn("Disk utilization info for server: {} is stale", instance);
+        continue;
+      }
+      if (diskUsageInfo.getUsedSpaceBytes() > 
diskUsageInfo.getTotalSpaceBytes() * _diskUtilizationThreshold) {

Review Comment:
   Can we add a metric and an alert here when this happens, since this will 
block ingestion ? Can you also log the totalSpace, usedSpace as well here
    
   



##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/DiskUtilizationChecker.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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.validation;
+
+import com.google.common.collect.BiMap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.restlet.resources.DiskUsageInfo;
+import org.apache.pinot.controller.ControllerConf;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.CompletionServiceHelper;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DiskUtilizationChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DiskUtilizationChecker.class);
+  private final int _resourceUtilizationCheckTimeoutMs;
+  private final long _resourceUtilizationCheckerFrequency;
+  private final double _diskUtilizationThreshold;
+  private final String _diskUtilizationPath;
+  private static final String DISK_UTILIZATION_API_PATH = 
"/instance/diskUtilization";
+
+  private final PinotHelixResourceManager _helixResourceManager;
+
+  public DiskUtilizationChecker(PinotHelixResourceManager 
helixResourceManager, ControllerConf controllerConf) {
+    _helixResourceManager = helixResourceManager;
+    _diskUtilizationPath = controllerConf.getDiskUtilizationPath();
+    _diskUtilizationThreshold = controllerConf.getDiskUtilizationThreshold();
+    _resourceUtilizationCheckTimeoutMs = 
controllerConf.getDiskUtilizationCheckTimeoutMs();
+    _resourceUtilizationCheckerFrequency = 
controllerConf.getResourceUtilizationCheckerFrequency();

Review Comment:
   Is this in Millisecs. If so, can we add the time unit suffix.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/RealtimeSegmentValidationManager.java:
##########
@@ -135,6 +138,18 @@ private boolean shouldEnsureConsuming(String 
tableNameWithType) {
     if (isTablePaused && 
pauseStatus.getReasonCode().equals(PauseState.ReasonCode.ADMINISTRATIVE)) {
       return false;
     }
+    try {
+      boolean isResourceUtilizationWithinLimits =
+          
_resourceUtilizationManager.isResourceUtilizationWithinLimits(tableNameWithType);
+      if (!isResourceUtilizationWithinLimits) {
+        LOGGER.warn("Resource utilization limit exceeded for table: {}", 
tableNameWithType);
+        _llcRealtimeSegmentManager.pauseConsumption(tableNameWithType,

Review Comment:
   cc @9aman for pauseless implications if any 



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java:
##########
@@ -203,6 +206,14 @@ public Map<String, String> createTask(String taskType, 
String tableName, @Nullab
     for (String tableNameWithType : tableNameWithTypes) {
       TableConfig tableConfig = 
_pinotHelixResourceManager.getTableConfig(tableNameWithType);
       LOGGER.info("Trying to create tasks of type: {}, table: {}", taskType, 
tableNameWithType);
+      try {
+        if 
(!_resourceUtilizationManager.isResourceUtilizationWithinLimits(tableNameWithType))
 {

Review Comment:
   A metric & alert would be useful for the user. 



##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/DiskUtilizationChecker.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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.validation;
+
+import com.google.common.collect.BiMap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.restlet.resources.DiskUsageInfo;
+import org.apache.pinot.controller.ControllerConf;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.CompletionServiceHelper;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DiskUtilizationChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DiskUtilizationChecker.class);
+  private final int _resourceUtilizationCheckTimeoutMs;
+  private final long _resourceUtilizationCheckerFrequency;
+  private final double _diskUtilizationThreshold;
+  private final String _diskUtilizationPath;
+  private static final String DISK_UTILIZATION_API_PATH = 
"/instance/diskUtilization";
+
+  private final PinotHelixResourceManager _helixResourceManager;
+
+  public DiskUtilizationChecker(PinotHelixResourceManager 
helixResourceManager, ControllerConf controllerConf) {
+    _helixResourceManager = helixResourceManager;
+    _diskUtilizationPath = controllerConf.getDiskUtilizationPath();
+    _diskUtilizationThreshold = controllerConf.getDiskUtilizationThreshold();
+    _resourceUtilizationCheckTimeoutMs = 
controllerConf.getDiskUtilizationCheckTimeoutMs();
+    _resourceUtilizationCheckerFrequency = 
controllerConf.getResourceUtilizationCheckerFrequency();
+  }
+
+  public static String getDiskUtilizationApiPath() {
+    return DISK_UTILIZATION_API_PATH;
+  }
+
+  /**
+   * Check if disk utilization for the requested table is within the 
configured limits.
+   */
+  public boolean isDiskUtilizationWithinLimits(String tableNameWithType) {
+    if (StringUtils.isEmpty(tableNameWithType)) {
+      throw new IllegalArgumentException("Table name found to be null or empty 
while computing disk utilization.");
+    }
+    TableConfig tableConfig = 
_helixResourceManager.getTableConfig(tableNameWithType);
+    if (tableConfig == null) {
+      return true; // table does not exist
+    }
+    List<String> instances;
+    if (TableNameBuilder.isOfflineTableResource(tableNameWithType)) {
+      instances = 
_helixResourceManager.getServerInstancesForTable(tableNameWithType, 
TableType.OFFLINE);
+    } else {
+      instances = 
_helixResourceManager.getServerInstancesForTable(tableNameWithType, 
TableType.REALTIME);
+    }
+    return isDiskUtilizationWithinLimits(instances);
+  }
+
+  private boolean isDiskUtilizationWithinLimits(List<String> instances) {

Review Comment:
   What happens after table rebalance is initiated? Will we recover immediately 
in the next trigger. 



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