bbeaudreault commented on a change in pull request #3536: URL: https://github.com/apache/hbase/pull/3536#discussion_r685958760
########## File path: hbase-client/src/main/java/org/apache/hadoop/hbase/BalanceRequest.java ########## @@ -0,0 +1,96 @@ +/* + * + * 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.hadoop.hbase; + +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; + +/** + * Encapsulates options for executing an unscheduled run of the Balancer. + */ [email protected] [email protected] +public class BalanceRequest { + + private final boolean dryRun; + private final boolean ignoreRIT; + + private BalanceRequest(boolean dryRun, boolean ignoreRIT) { + this.dryRun = dryRun; + this.ignoreRIT = ignoreRIT; + } + + /** + * Creates a BalancerRequest which runs the balancer normally. + * In this mode, the balancer will execute all region moves if an improved + * plan is found. + * + * The balancer will not run if the balance switch is disabled, the master + * is in maintenance mode, or there are currently regions in transition. You + * can force the balancer to run despite regions being in transition by + * using {@link #ignoreRegionsInTransition()} + */ + public static BalanceRequest execute() { + return new BalanceRequest(false, false); + } + + + /** + * Creates a BalancerRequest which runs the balancer in dryRun mode. + * In this mode, the balancer will try to find a plan but WILL NOT + * execute any region moves or call any coprocessors. + * + * You can run in dryRun mode regardless of whether the balancer switch + * is enabled or disabled, but dryRun mode will not run over an existing + * request or chore. + * + * Dry run is useful for testing out new balance configs. See the logs + * on the active HMaster for the results of the dry run. + */ + public static BalanceRequest dryRun() { + return new BalanceRequest(true, false); + } + + /** + * For internal use only. Used to support deprecated interface in Admin/AsyncAdmin. + */ + @InterfaceAudience.Private + public static BalanceRequest execute(boolean force) { + BalanceRequest request = BalanceRequest.execute(); + return force ? request.ignoreRegionsInTransition() : request; + } + + /** + * Updates the BalancerRequest to cause the balancer to run even if there + * are regions in transition. + * + * WARNING: Advanced usage only, this could cause more issues than it fixes. + */ + public BalanceRequest ignoreRegionsInTransition() { Review comment: I'll convert to a more standard builder pattern. Since we don't have many arguments in this builder, I was trying to avoid unnecessarily verbose builders for the basic case of dry run/execute. We wanted a builder here because we intend to add other options in the near future. I figured we could iterate on the interface since it's marked as Evolving. But I'll just do the more verbose builder now. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
