klsince commented on code in PR #11740: URL: https://github.com/apache/pinot/pull/11740#discussion_r1355830231
########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/RebalanceChecker.java: ########## @@ -0,0 +1,279 @@ +/** + * 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.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.pinot.common.metadata.ZKMetadataProvider; +import org.apache.pinot.common.metadata.controllerjob.ControllerJobType; +import org.apache.pinot.common.metrics.ControllerMeter; +import org.apache.pinot.common.metrics.ControllerMetrics; +import org.apache.pinot.controller.ControllerConf; +import org.apache.pinot.controller.LeadControllerManager; +import org.apache.pinot.controller.helix.core.PinotHelixResourceManager; +import org.apache.pinot.controller.helix.core.periodictask.ControllerPeriodicTask; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.JsonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Periodic task to check whether a user triggered rebalance job is completed or not, and retry if failed. The retry + * job is started with the same rebalance configs provided by the user and does best effort to stop the other jobs + * for the same table. This task can be configured to just check failures and report metrics, and not to do retry. + */ +public class RebalanceChecker extends ControllerPeriodicTask<Void> { + private static final Logger LOGGER = LoggerFactory.getLogger(RebalanceChecker.class); + private static final double RETRY_DELAY_SCALE_FACTOR = 2.0; + private final boolean _checkOnly; + private final ExecutorService _executorService; + + public RebalanceChecker(PinotHelixResourceManager pinotHelixResourceManager, + LeadControllerManager leadControllerManager, ControllerConf config, ControllerMetrics controllerMetrics, + ExecutorService executorService) { + super(RebalanceChecker.class.getSimpleName(), config.getRebalanceCheckerFrequencyInSeconds(), + config.getRebalanceCheckerInitialDelayInSeconds(), pinotHelixResourceManager, leadControllerManager, + controllerMetrics); + _checkOnly = config.isRebalanceCheckerCheckOnly(); + _executorService = executorService; + } + + @Override + protected void processTable(String tableNameWithType) { + _executorService.submit(() -> { + try { + LOGGER.info("Start to retry rebalance for table: {}", tableNameWithType); + TableConfig tableConfig = _pinotHelixResourceManager.getTableConfig(tableNameWithType); + Preconditions.checkState(tableConfig != null, "Failed to find table config for table: {}", tableNameWithType); + retryRebalanceTable(tableNameWithType, tableConfig); + } catch (Throwable t) { + LOGGER.error("Failed to retry rebalance for table: {}", tableNameWithType, t); + } + }); + } + + @VisibleForTesting + void retryRebalanceTable(String tableNameWithType, TableConfig tableConfig) + throws Exception { + // Get all rebalance jobs as tracked in ZK for this table to check if there is any failure to retry. + Map<String, Map<String, String>> allJobMetadata = _pinotHelixResourceManager.getAllJobsForTable(tableNameWithType, Review Comment: All tables' rebalance job status is kept in one ZNode, and there is cache for zkclient.get(), so I think it'd be fine to process tables separately. But good point that `_executorService.submit` shouldn't be called immediately in processTable() but when a retry is really needed for the table. -- 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