-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for performing pre-checks for TableRebalance (#15029)
* Add support for performing pre-checks for TableRebalance
- Loading branch information
Showing
17 changed files
with
529 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...ain/java/org/apache/pinot/controller/helix/core/rebalance/DefaultRebalancePreChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* 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 javax.annotation.Nullable; | ||
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, @Nullable 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" : String.valueOf(needsReload)); | ||
// 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) { | ||
LOGGER.info("Fetching whether reload is needed for table: {} with rebalanceJobId: {}", tableNameWithType, | ||
rebalanceJobId); | ||
Boolean needsReload = null; | ||
if (_executorService == null) { | ||
LOGGER.warn("Executor service is null, skipping needsReload check for table: {} rebalanceJobId: {}", | ||
tableNameWithType, rebalanceJobId); | ||
return needsReload; | ||
} | ||
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) { | ||
return needsReload; | ||
} | ||
if (failedResponses > 0) { | ||
LOGGER.warn("Received {} failed responses from servers and needsReload is false from returned responses, " | ||
+ "check needsReload status manually", failedResponses); | ||
needsReload = null; | ||
} | ||
} catch (InvalidConfigException | IOException e) { | ||
LOGGER.warn("Caught exception while trying to fetch reload status from servers", e); | ||
} | ||
|
||
return needsReload; | ||
} | ||
|
||
/** | ||
* Checks if minimize data movement is set for the given table in the TableConfig | ||
*/ | ||
private boolean checkIsMinimizeDataMovement(String rebalanceJobId, String tableNameWithType, | ||
TableConfig tableConfig) { | ||
LOGGER.info("Checking whether minimizeDataMovement is set for table: {} with rebalanceJobId: {}", tableNameWithType, | ||
rebalanceJobId); | ||
try { | ||
if (tableConfig.getTableType() == TableType.OFFLINE) { | ||
InstanceAssignmentConfig instanceAssignmentConfig = | ||
InstanceAssignmentConfigUtils.getInstanceAssignmentConfig(tableConfig, InstancePartitionsType.OFFLINE); | ||
return instanceAssignmentConfig.isMinimizeDataMovement(); | ||
} else { | ||
InstanceAssignmentConfig instanceAssignmentConfigConsuming = | ||
InstanceAssignmentConfigUtils.getInstanceAssignmentConfig(tableConfig, InstancePartitionsType.CONSUMING); | ||
// For REALTIME tables need to check for both CONSUMING and COMPLETED segments if relocation is enabled | ||
if (!InstanceAssignmentConfigUtils.shouldRelocateCompletedSegments(tableConfig)) { | ||
return instanceAssignmentConfigConsuming.isMinimizeDataMovement(); | ||
} | ||
|
||
InstanceAssignmentConfig instanceAssignmentConfigCompleted = | ||
InstanceAssignmentConfigUtils.getInstanceAssignmentConfig(tableConfig, InstancePartitionsType.COMPLETED); | ||
return instanceAssignmentConfigConsuming.isMinimizeDataMovement() | ||
&& instanceAssignmentConfigCompleted.isMinimizeDataMovement(); | ||
} | ||
} catch (IllegalStateException e) { | ||
LOGGER.warn("Error while trying to fetch instance assignment config, assuming minimizeDataMovement is false", e); | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.