Skip to content

Commit ee1dec2

Browse files
committed
Use a BalancerRequest for handling all of the balance args
1 parent 2df1125 commit ee1dec2

File tree

35 files changed

+403
-318
lines changed

35 files changed

+403
-318
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.apache.hadoop.hbase;
20+
21+
import org.apache.yetus.audience.InterfaceAudience;
22+
import org.apache.yetus.audience.InterfaceStability;
23+
24+
/**
25+
* Encapsulates options for executing an unscheduled run of the Balancer.
26+
*/
27+
@InterfaceAudience.Public
28+
@InterfaceStability.Evolving
29+
public class BalanceRequest {
30+
31+
/**
32+
* Dictates how the balancer should be run based on the request
33+
*/
34+
@InterfaceAudience.Private
35+
public enum RunMode {
36+
/**
37+
* The default mode for the balancer, will exit if there are already regions in transition.
38+
*/
39+
DEFAULT,
40+
41+
/**
42+
* Force the balancer to run, even if it normally wouldn't due to regions in transition.
43+
* WARNING: Advanced usage only, this could cause more issues than it fixes.
44+
*/
45+
IGNORE_RIT,
46+
47+
/**
48+
* Used when the user wants to run the balancer in dry run mode, where the balancer
49+
* attempts to find a balance plan but does not actually execute it.
50+
*/
51+
DRY_RUN;
52+
}
53+
54+
private final RunMode runMode;
55+
56+
private BalanceRequest(RunMode runMode) {
57+
this.runMode = runMode;
58+
}
59+
60+
/**
61+
* Creates a BalancerRequest which runs the balancer normally.
62+
* In this mode, the balancer will execute all region moves if an improved
63+
* plan is found.
64+
*
65+
* The balancer will not run if the balance switch is disabled, the master
66+
* is in maintenance mode, or there are currently regions in transition. You
67+
* can force the balancer to run despite regions being in transition by
68+
* using {@link #ignoringRegionsInTransition()}
69+
*/
70+
public static BalanceRequest runNormally() {
71+
return new BalanceRequest(RunMode.DEFAULT);
72+
}
73+
74+
/**
75+
* Creates a BalancerRequest which forces the balancer to run even if there
76+
* are regions in transition. The balancer will attempt to find a plan and
77+
* execute the region moves accordingly.
78+
*
79+
* The balancer will not run if the balance switch is disabled or the master
80+
* is in maintenance mode.
81+
*
82+
* WARNING: Advanced usage only, this could cause more issues than it fixes.
83+
*/
84+
public static BalanceRequest ignoringRegionsInTransition() {
85+
return new BalanceRequest(RunMode.IGNORE_RIT);
86+
}
87+
88+
/**
89+
* Creates a BalancerRequest which runs the balancer in dryRun mode.
90+
* In this mode, the balancer will try to find a plan but WILL NOT
91+
* execute any region moves or call any coprocessors.
92+
*
93+
* You can run in dryRun mode regardless of whether the balancer switch
94+
* is enabled or disabled, but dryRun mode will not run over an existing
95+
* request or chore.
96+
*
97+
* Dry run is useful for testing out new balance configs. See the logs
98+
* on the active HMaster for the results of the dry run.
99+
*/
100+
public static BalanceRequest dryRun() {
101+
return new BalanceRequest(RunMode.DRY_RUN);
102+
}
103+
104+
105+
/**
106+
* For internal use in supporting deprecated methods which accept a boolean argument.
107+
* Use one of {@link #runNormally()}, {@link #ignoringRegionsInTransition()},
108+
* or {@link #dryRun()}.
109+
*/
110+
@InterfaceAudience.Private
111+
public static BalanceRequest forExecution(boolean force) {
112+
return force ? ignoringRegionsInTransition() : runNormally();
113+
}
114+
115+
116+
/**
117+
* For internal use in converting across RPC layer. Use one of {@link #runNormally()},
118+
* {@link #ignoringRegionsInTransition()}, or {@link #dryRun()}.
119+
*/
120+
@InterfaceAudience.Private
121+
public static BalanceRequest forRunMode(RunMode runMode) {
122+
return new BalanceRequest(runMode);
123+
}
124+
125+
public RunMode getRunMode() {
126+
return runMode;
127+
}
128+
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.stream.Collectors;
3434
import org.apache.hadoop.conf.Configuration;
3535
import org.apache.hadoop.hbase.Abortable;
36+
import org.apache.hadoop.hbase.BalanceRequest;
3637
import org.apache.hadoop.hbase.CacheEvictionStats;
3738
import org.apache.hadoop.hbase.ClusterMetrics;
3839
import org.apache.hadoop.hbase.ClusterMetrics.Option;
@@ -1251,16 +1252,19 @@ default boolean balancer() throws IOException {
12511252
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12521253
* @throws IOException if a remote or network exception occurs
12531254
*/
1254-
boolean balance() throws IOException;
1255+
default boolean balance() throws IOException {
1256+
return balance(BalanceRequest.runNormally());
1257+
}
12551258

12561259
/**
1257-
* Invoke the balancer in dry run mode. Will show plan but not actually move any regions.
1258-
* Can NOT run for various reasons. Check logs.
1260+
* Invoke the balancer with the given balance request. The BalanceRequest defines how the
1261+
* balancer will run. See {@link BalanceRequest} for more details.
12591262
*
1260-
* @return <code>true</code> if dry run ran, <code>false</code> otherwise.
1263+
* @param request defines how the balancer should run
1264+
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12611265
* @throws IOException if a remote or network exception occurs
12621266
*/
1263-
boolean dryRunBalance() throws IOException;
1267+
boolean balance(BalanceRequest request) throws IOException;
12641268

12651269
/**
12661270
* Invoke the balancer. Will run the balancer and if regions to move, it will
@@ -1271,7 +1275,7 @@ default boolean balancer() throws IOException {
12711275
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12721276
* @throws IOException if a remote or network exception occurs
12731277
* @deprecated Since 2.0.0. Will be removed in 3.0.0.
1274-
* Use {@link #balance(boolean)} instead.
1278+
* Use {@link #balance(BalanceRequest)} instead.
12751279
*/
12761280
@Deprecated
12771281
default boolean balancer(boolean force) throws IOException {
@@ -1286,8 +1290,13 @@ default boolean balancer(boolean force) throws IOException {
12861290
* @param force whether we should force balance even if there is region in transition
12871291
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12881292
* @throws IOException if a remote or network exception occurs
1293+
* @deprecated Since 2.5.0. Will be removed in 4.0.0.
1294+
* Use {@link #balance(BalanceRequest)} instead.
12891295
*/
1290-
boolean balance(boolean force) throws IOException;
1296+
@Deprecated
1297+
default boolean balance(boolean force) throws IOException {
1298+
return balance(BalanceRequest.forExecution(force));
1299+
}
12911300

12921301
/**
12931302
* Query the current state of the balancer.

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
2121

2222
import com.google.protobuf.RpcChannel;
23-
import java.io.IOException;
2423
import java.util.Arrays;
2524
import java.util.Collection;
2625
import java.util.EnumSet;
@@ -33,6 +32,7 @@
3332
import java.util.function.Function;
3433
import java.util.regex.Pattern;
3534
import java.util.stream.Collectors;
35+
import org.apache.hadoop.hbase.BalanceRequest;
3636
import org.apache.hadoop.hbase.CacheEvictionStats;
3737
import org.apache.hadoop.hbase.ClusterMetrics;
3838
import org.apache.hadoop.hbase.ClusterMetrics.Option;
@@ -1258,7 +1258,7 @@ default CompletableFuture<Boolean> balancerSwitch(boolean on) {
12581258
* {@link CompletableFuture}.
12591259
*/
12601260
default CompletableFuture<Boolean> balance() {
1261-
return balance(false);
1261+
return balance(BalanceRequest.runNormally());
12621262
}
12631263

12641264
/**
@@ -1268,16 +1268,14 @@ default CompletableFuture<Boolean> balance() {
12681268
* @param forcible whether we should force balance even if there is region in transition.
12691269
* @return True if balancer ran, false otherwise. The return value will be wrapped by a
12701270
* {@link CompletableFuture}.
1271+
* @deprecated Since 2.5.0. Will be removed in 4.0.0.
1272+
* Use {@link #balance(BalanceRequest)} instead.
12711273
*/
1272-
CompletableFuture<Boolean> balance(boolean forcible);
1274+
default CompletableFuture<Boolean> balance(boolean forcible) {
1275+
return balance(BalanceRequest.forExecution(forcible));
1276+
}
12731277

1274-
/**
1275-
* Invoke the balancer in dry run mode. Will show plan but not actually move any regions.
1276-
* Can NOT run for various reasons. Check logs.
1277-
*
1278-
* @return <code>true</code> if dry run ran, <code>false</code> otherwise.
1279-
*/
1280-
CompletableFuture<Boolean> dryRunBalance();
1278+
CompletableFuture<Boolean> balance(BalanceRequest request);
12811279

12821280
/**
12831281
* Query the current state of the balancer.

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.ExecutorService;
2929
import java.util.function.Function;
3030
import java.util.regex.Pattern;
31+
import org.apache.hadoop.hbase.BalanceRequest;
3132
import org.apache.hadoop.hbase.CacheEvictionStats;
3233
import org.apache.hadoop.hbase.ClusterMetrics;
3334
import org.apache.hadoop.hbase.ClusterMetrics.Option;
@@ -684,13 +685,8 @@ public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs)
684685
}
685686

686687
@Override
687-
public CompletableFuture<Boolean> balance(boolean forcible) {
688-
return wrap(rawAdmin.balance(forcible));
689-
}
690-
691-
@Override
692-
public CompletableFuture<Boolean> dryRunBalance() {
693-
return wrap(rawAdmin.dryRunBalance());
688+
public CompletableFuture<Boolean> balance(BalanceRequest request) {
689+
return wrap(rawAdmin.balance(request));
694690
}
695691

696692
@Override

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,12 +1488,6 @@ public MasterProtos.BalanceResponse balance(RpcController controller,
14881488
return stub.balance(controller, request);
14891489
}
14901490

1491-
@Override
1492-
public MasterProtos.BalanceResponse dryRunBalance(RpcController controller,
1493-
MasterProtos.BalanceRequest request) throws ServiceException {
1494-
return stub.dryRunBalance(controller, request);
1495-
}
1496-
14971491
@Override
14981492
public MasterProtos.SetBalancerRunningResponse setBalancerRunning(
14991493
RpcController controller, MasterProtos.SetBalancerRunningRequest request)

hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.stream.Stream;
4848
import org.apache.hadoop.conf.Configuration;
4949
import org.apache.hadoop.hbase.Abortable;
50+
import org.apache.hadoop.hbase.BalanceRequest;
5051
import org.apache.hadoop.hbase.CacheEvictionStats;
5152
import org.apache.hadoop.hbase.CacheEvictionStatsBuilder;
5253
import org.apache.hadoop.hbase.ClusterMetrics;
@@ -1476,35 +1477,11 @@ protected Boolean rpcCall() throws Exception {
14761477
});
14771478
}
14781479

1479-
@Override
1480-
public boolean balance() throws IOException {
1481-
return executeCallable(new MasterCallable<Boolean>(getConnection(), getRpcControllerFactory()) {
1482-
@Override
1483-
protected Boolean rpcCall() throws Exception {
1484-
return master.balance(getRpcController(),
1485-
RequestConverter.buildBalanceRequest(false)).getBalancerRan();
1486-
}
1487-
});
1488-
}
1489-
1490-
@Override
1491-
public boolean balance(final boolean force) throws IOException {
1480+
@Override public boolean balance(BalanceRequest request) throws IOException {
14921481
return executeCallable(new MasterCallable<Boolean>(getConnection(), getRpcControllerFactory()) {
1493-
@Override
1494-
protected Boolean rpcCall() throws Exception {
1495-
return master.balance(getRpcController(),
1496-
RequestConverter.buildBalanceRequest(force)).getBalancerRan();
1497-
}
1498-
});
1499-
}
1500-
1501-
@Override
1502-
public boolean dryRunBalance() throws IOException {
1503-
return executeCallable(new MasterCallable<Boolean>(getConnection(), getRpcControllerFactory()) {
1504-
@Override
1505-
protected Boolean rpcCall() throws Exception {
1506-
return master.dryRunBalance(getRpcController(),
1507-
RequestConverter.buildBalanceRequest(false)).getBalancerRan();
1482+
@Override protected Boolean rpcCall() throws Exception {
1483+
return master.balance(getRpcController(), RequestConverter.toBalanceRequest(request))
1484+
.getBalancerRan();
15081485
}
15091486
});
15101487
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
import org.apache.hadoop.conf.Configuration;
5151
import org.apache.hadoop.hbase.AsyncMetaTableAccessor;
52+
import org.apache.hadoop.hbase.BalanceRequest;
5253
import org.apache.hadoop.hbase.CacheEvictionStats;
5354
import org.apache.hadoop.hbase.CacheEvictionStatsAggregator;
5455
import org.apache.hadoop.hbase.ClusterMetrics;
@@ -126,14 +127,13 @@
126127
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription;
127128
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
128129
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema;
130+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
129131
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureRequest;
130132
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureResponse;
131133
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest;
132134
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnResponse;
133135
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionRequest;
134136
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionResponse;
135-
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceRequest;
136-
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceResponse;
137137
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersRequest;
138138
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersResponse;
139139
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest;
@@ -3210,24 +3210,15 @@ public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs)
32103210
}
32113211

32123212
@Override
3213-
public CompletableFuture<Boolean> balance(boolean forcible) {
3213+
public CompletableFuture<Boolean> balance(BalanceRequest request) {
32143214
return this
32153215
.<Boolean> newMasterCaller()
32163216
.action(
3217-
(controller, stub) -> this.<BalanceRequest, BalanceResponse, Boolean> call(controller,
3218-
stub, RequestConverter.buildBalanceRequest(forcible),
3217+
(controller, stub) -> this.<MasterProtos.BalanceRequest, MasterProtos.BalanceResponse, Boolean> call(controller,
3218+
stub, RequestConverter.toBalanceRequest(request),
32193219
(s, c, req, done) -> s.balance(c, req, done), (resp) -> resp.getBalancerRan())).call();
32203220
}
32213221

3222-
@Override
3223-
public CompletableFuture<Boolean> dryRunBalance() {
3224-
return this
3225-
.<Boolean> newMasterCaller()
3226-
.action(
3227-
(controller, stub) -> this.<BalanceRequest, BalanceResponse, Boolean> call(controller,
3228-
stub, RequestConverter.buildBalanceRequest(false),
3229-
(s, c, req, done) -> s.dryRunBalance(c, req, done), (resp) -> resp.getBalancerRan())).call();
3230-
}
32313222

32323223
@Override
32333224
public CompletableFuture<Boolean> isBalancerEnabled() {

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ShortCircuitMasterConnection.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,6 @@ public BalanceResponse balance(RpcController controller, BalanceRequest request)
599599
return stub.balance(controller, request);
600600
}
601601

602-
@Override
603-
public BalanceResponse dryRunBalance(RpcController controller, BalanceRequest request)
604-
throws ServiceException {
605-
return stub.dryRunBalance(controller, request);
606-
}
607-
608602
@Override
609603
public AssignRegionResponse assignRegion(RpcController controller, AssignRegionRequest request)
610604
throws ServiceException {

0 commit comments

Comments
 (0)