klsince commented on code in PR #15029:
URL: https://github.com/apache/pinot/pull/15029#discussion_r1957014459


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/DefaultRebalancePreChecker.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.rebalance;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.pinot.common.assignment.InstanceAssignmentConfigUtils;
+import org.apache.pinot.common.exception.InvalidConfigException;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.TableMetadataReader;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.config.table.assignment.InstanceAssignmentConfig;
+import org.apache.pinot.spi.config.table.assignment.InstancePartitionsType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DefaultRebalancePreChecker implements RebalancePreChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DefaultRebalancePreChecker.class);
+
+  public static final String NEEDS_RELOAD_STATUS = "needsReloadStatus";
+  public static final String IS_MINIMIZE_DATA_MOVEMENT = 
"isMinimizeDataMovement";
+
+  private PinotHelixResourceManager _pinotHelixResourceManager;
+  private ExecutorService _executorService;
+
+  @Override
+  public void init(PinotHelixResourceManager pinotHelixResourceManager, 
ExecutorService executorService) {
+    _pinotHelixResourceManager = pinotHelixResourceManager;
+    _executorService = executorService;
+  }
+
+  @Override
+  public Map<String, String> check(String rebalanceJobId, String 
tableNameWithType,
+      TableConfig tableConfig) {
+    LOGGER.info("Start pre-checks for table: {} with rebalanceJobId: {}", 
tableNameWithType, rebalanceJobId);
+
+    Map<String, String> preCheckResult = new HashMap<>();
+    // Check for reload status
+    Boolean needsReload = checkReloadNeededOnServers(rebalanceJobId, 
tableNameWithType);
+    preCheckResult.put(NEEDS_RELOAD_STATUS,
+        needsReload == null ? "error" : needsReload ? String.valueOf(true) : 
String.valueOf(false));
+    // Check whether minimizeDataMovement is set in TableConfig
+    boolean isMinimizeDataMovement = 
checkIsMinimizeDataMovement(rebalanceJobId, tableNameWithType, tableConfig);
+    preCheckResult.put(IS_MINIMIZE_DATA_MOVEMENT, 
String.valueOf(isMinimizeDataMovement));
+
+    LOGGER.info("End pre-checks for table: {} with rebalanceJobId: {}", 
tableNameWithType, rebalanceJobId);
+    return preCheckResult;
+  }
+
+  /**
+   * Checks if the current segments on any servers needs a reload (table 
config or schema change that hasn't been
+   * applied yet). This check does not guarantee that the segments in deep 
store are up to date.
+   * TODO: Add an API to check for whether segments in deep store are up to 
date with the table configs and schema
+   *       and add a pre-check here to call that API.
+   */
+  private Boolean checkReloadNeededOnServers(String rebalanceJobId, String 
tableNameWithType) {
+    // Use at most 10 threads to get whether reload is needed from servers

Review Comment:
   can remove this comment?



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/RebalancePreCheckerFactory.java:
##########
@@ -0,0 +1,40 @@
+/**
+ * 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.rebalance;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class RebalancePreCheckerFactory {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(RebalancePreCheckerFactory.class);
+
+  private RebalancePreCheckerFactory() {
+  }
+
+  public static RebalancePreChecker create(String 
rebalancePreCheckerClassName) {
+    try {
+      LOGGER.info("Trying to create rebalance pre-checker object for class: 
{}", rebalancePreCheckerClassName);
+      return (RebalancePreChecker) 
Class.forName(rebalancePreCheckerClassName).newInstance();
+    } catch (Exception e) {
+      LOGGER.error("RebalancePreChecker not found: {}", 
rebalancePreCheckerClassName);

Review Comment:
   nit: log.error("Failed to create ...", e), to be generic as perhaps this 
fails due to unexpected error than ClassNotFound.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkDriver.java:
##########
@@ -291,7 +292,7 @@ private void startHelixResourceManager()
       // participant with the same host and port.
       ControllerConf controllerConf = getControllerConf();
       
controllerConf.setControllerPort(Integer.toString(_conf.getControllerPort() + 
1));
-      _helixResourceManager = new PinotHelixResourceManager(controllerConf);
+      _helixResourceManager = new PinotHelixResourceManager(controllerConf, 
Executors.newFixedThreadPool(10));

Review Comment:
   nit: add a constructor that allows null executor and skip the precheck 
logics if so? those tmp executor is not closed after use iiuc



##########
pinot-controller/src/main/java/org/apache/pinot/controller/util/TableMetadataReader.java:
##########
@@ -213,4 +220,22 @@ public Map<String, TableStaleSegmentResponse> 
getStaleSegments(String tableNameW
     return 
serverSegmentMetadataReader.getStaleSegmentsFromServer(tableNameWithType, 
serverInstanceSet, endpoints,
         timeoutMs);
   }
+
+  public class TableReloadJsonResponse {

Review Comment:
   I'm a bit confused about TableReloadJsonResponse and TableReloadResponse 
classes as both look pretty similar. Is some of them for internal results? 
perhaps can be made private if so.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/DefaultRebalancePreChecker.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.rebalance;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.pinot.common.assignment.InstanceAssignmentConfigUtils;
+import org.apache.pinot.common.exception.InvalidConfigException;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.TableMetadataReader;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.config.table.assignment.InstanceAssignmentConfig;
+import org.apache.pinot.spi.config.table.assignment.InstancePartitionsType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DefaultRebalancePreChecker implements RebalancePreChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DefaultRebalancePreChecker.class);
+
+  public static final String NEEDS_RELOAD_STATUS = "needsReloadStatus";
+  public static final String IS_MINIMIZE_DATA_MOVEMENT = 
"isMinimizeDataMovement";
+
+  private PinotHelixResourceManager _pinotHelixResourceManager;
+  private ExecutorService _executorService;
+
+  @Override
+  public void init(PinotHelixResourceManager pinotHelixResourceManager, 
ExecutorService executorService) {
+    _pinotHelixResourceManager = pinotHelixResourceManager;
+    _executorService = executorService;
+  }
+
+  @Override
+  public Map<String, String> check(String rebalanceJobId, String 
tableNameWithType,
+      TableConfig tableConfig) {
+    LOGGER.info("Start pre-checks for table: {} with rebalanceJobId: {}", 
tableNameWithType, rebalanceJobId);
+
+    Map<String, String> preCheckResult = new HashMap<>();
+    // Check for reload status
+    Boolean needsReload = checkReloadNeededOnServers(rebalanceJobId, 
tableNameWithType);
+    preCheckResult.put(NEEDS_RELOAD_STATUS,
+        needsReload == null ? "error" : needsReload ? String.valueOf(true) : 
String.valueOf(false));
+    // Check whether minimizeDataMovement is set in TableConfig
+    boolean isMinimizeDataMovement = 
checkIsMinimizeDataMovement(rebalanceJobId, tableNameWithType, tableConfig);
+    preCheckResult.put(IS_MINIMIZE_DATA_MOVEMENT, 
String.valueOf(isMinimizeDataMovement));
+
+    LOGGER.info("End pre-checks for table: {} with rebalanceJobId: {}", 
tableNameWithType, rebalanceJobId);
+    return preCheckResult;
+  }
+
+  /**
+   * Checks if the current segments on any servers needs a reload (table 
config or schema change that hasn't been
+   * applied yet). This check does not guarantee that the segments in deep 
store are up to date.
+   * TODO: Add an API to check for whether segments in deep store are up to 
date with the table configs and schema
+   *       and add a pre-check here to call that API.
+   */
+  private Boolean checkReloadNeededOnServers(String rebalanceJobId, String 
tableNameWithType) {
+    // Use at most 10 threads to get whether reload is needed from servers
+    LOGGER.info("Fetching whether reload is needed for table: {} with 
rebalanceJobId: {}", tableNameWithType,
+        rebalanceJobId);
+    Boolean needsReload = null;
+    try (PoolingHttpClientConnectionManager connectionManager = new 
PoolingHttpClientConnectionManager()) {
+      TableMetadataReader metadataReader = new 
TableMetadataReader(_executorService, connectionManager,
+          _pinotHelixResourceManager);
+      TableMetadataReader.TableReloadJsonResponse needsReloadMetadataPair =
+          
metadataReader.getServerCheckSegmentsReloadMetadata(tableNameWithType, 30_000);
+      Map<String, JsonNode> needsReloadMetadata = 
needsReloadMetadataPair.getServerReloadJsonResponses();
+      int failedResponses = needsReloadMetadataPair.getNumFailedResponses();
+      LOGGER.info("Received {} needs reload responses and {} failed responses 
from servers for table: {} with "
+              + "rebalanceJobId: {}", needsReloadMetadata.size(), 
failedResponses, tableNameWithType, rebalanceJobId);
+      needsReload =
+          needsReloadMetadata.values().stream().anyMatch(value -> 
value.get("needReload").booleanValue());
+      if (!needsReload && failedResponses > 0) {
+        LOGGER.warn("Received some failed responses from servers and needs 
reload indicates false from servers that "
+            + "returned responses. Setting return to 'null' to force a manual 
check");

Review Comment:
   Should we simply set null when failedResponse > 0? Or maybe split it to be a 
bit more clear, iiuc:
   ```
   if (needReloads) {
     return needReloads;
   }
   if (failedResponses > 0) {
    log ... 
    return null
   }
   return false;
   ```
   
   And consider to remove `Setting return to 'null' to` as setting `null` seems 
pretty internal detail.
   
   



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/DefaultRebalancePreChecker.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.rebalance;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.pinot.common.assignment.InstanceAssignmentConfigUtils;
+import org.apache.pinot.common.exception.InvalidConfigException;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.util.TableMetadataReader;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.config.table.assignment.InstanceAssignmentConfig;
+import org.apache.pinot.spi.config.table.assignment.InstancePartitionsType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DefaultRebalancePreChecker implements RebalancePreChecker {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DefaultRebalancePreChecker.class);
+
+  public static final String NEEDS_RELOAD_STATUS = "needsReloadStatus";
+  public static final String IS_MINIMIZE_DATA_MOVEMENT = 
"isMinimizeDataMovement";
+
+  private PinotHelixResourceManager _pinotHelixResourceManager;
+  private ExecutorService _executorService;
+
+  @Override
+  public void init(PinotHelixResourceManager pinotHelixResourceManager, 
ExecutorService executorService) {
+    _pinotHelixResourceManager = pinotHelixResourceManager;
+    _executorService = executorService;
+  }
+
+  @Override
+  public Map<String, String> check(String rebalanceJobId, String 
tableNameWithType,
+      TableConfig tableConfig) {
+    LOGGER.info("Start pre-checks for table: {} with rebalanceJobId: {}", 
tableNameWithType, rebalanceJobId);
+
+    Map<String, String> preCheckResult = new HashMap<>();
+    // Check for reload status
+    Boolean needsReload = checkReloadNeededOnServers(rebalanceJobId, 
tableNameWithType);
+    preCheckResult.put(NEEDS_RELOAD_STATUS,
+        needsReload == null ? "error" : needsReload ? String.valueOf(true) : 
String.valueOf(false));

Review Comment:
   simply `needsReload == null ? "error" : String.valueOf(needsReload)`? 



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