001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Encapsulates options for executing a run of the Balancer. 024 */ 025@InterfaceAudience.Public 026public final class BalanceRequest { 027 private static final BalanceRequest DEFAULT = BalanceRequest.newBuilder().build(); 028 029 /** 030 * Builder for constructing a {@link BalanceRequest} 031 */ 032 @InterfaceAudience.Public 033 public final static class Builder { 034 private boolean dryRun = false; 035 private boolean ignoreRegionsInTransition = false; 036 037 private Builder() { 038 } 039 040 /** 041 * Updates BalancerRequest to run the balancer in dryRun mode. In this mode, the balancer will 042 * try to find a plan but WILL NOT execute any region moves or call any coprocessors. You can 043 * run in dryRun mode regardless of whether the balancer switch is enabled or disabled, but 044 * dryRun mode will not run over an existing request or chore. Dry run is useful for testing out 045 * new balance configs. See the logs on the active HMaster for the results of the dry run. 046 */ 047 public Builder setDryRun(boolean dryRun) { 048 this.dryRun = dryRun; 049 return this; 050 } 051 052 /** 053 * Updates BalancerRequest to run the balancer even if there are regions in transition. WARNING: 054 * Advanced usage only, this could cause more issues than it fixes. 055 */ 056 public Builder setIgnoreRegionsInTransition(boolean ignoreRegionsInTransition) { 057 this.ignoreRegionsInTransition = ignoreRegionsInTransition; 058 return this; 059 } 060 061 /** 062 * Build the {@link BalanceRequest} 063 */ 064 public BalanceRequest build() { 065 return new BalanceRequest(dryRun, ignoreRegionsInTransition); 066 } 067 } 068 069 /** 070 * Create a builder to construct a custom {@link BalanceRequest}. 071 */ 072 public static Builder newBuilder() { 073 return new Builder(); 074 } 075 076 /** 077 * Get a BalanceRequest for a default run of the balancer. The default mode executes any moves 078 * calculated and will not run if regions are already in transition. 079 */ 080 public static BalanceRequest defaultInstance() { 081 return DEFAULT; 082 } 083 084 private final boolean dryRun; 085 private final boolean ignoreRegionsInTransition; 086 087 private BalanceRequest(boolean dryRun, boolean ignoreRegionsInTransition) { 088 this.dryRun = dryRun; 089 this.ignoreRegionsInTransition = ignoreRegionsInTransition; 090 } 091 092 /** 093 * Returns true if the balancer should run in dry run mode, otherwise false. In dry run mode, 094 * moves will be calculated but not executed. 095 */ 096 public boolean isDryRun() { 097 return dryRun; 098 } 099 100 /** 101 * Returns true if the balancer should execute even if regions are in transition, otherwise false. 102 * This is an advanced usage feature, as it can cause more issues than it fixes. 103 */ 104 public boolean isIgnoreRegionsInTransition() { 105 return ignoreRegionsInTransition; 106 } 107}