Skip to content

Commit 8bedb53

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

File tree

36 files changed

+407
-345
lines changed

36 files changed

+407
-345
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
private final boolean dryRun;
32+
private final boolean ignoreRIT;
33+
34+
private BalanceRequest(boolean dryRun, boolean ignoreRIT) {
35+
this.dryRun = dryRun;
36+
this.ignoreRIT = ignoreRIT;
37+
}
38+
39+
/**
40+
* Creates a BalancerRequest which runs the balancer normally.
41+
* In this mode, the balancer will execute all region moves if an improved
42+
* plan is found.
43+
*
44+
* The balancer will not run if the balance switch is disabled, the master
45+
* is in maintenance mode, or there are currently regions in transition. You
46+
* can force the balancer to run despite regions being in transition by
47+
* using {@link #ignoreRegionsInTransition()}
48+
*/
49+
public static BalanceRequest execute() {
50+
return new BalanceRequest(false, false);
51+
}
52+
53+
54+
/**
55+
* Creates a BalancerRequest which runs the balancer in dryRun mode.
56+
* In this mode, the balancer will try to find a plan but WILL NOT
57+
* execute any region moves or call any coprocessors.
58+
*
59+
* You can run in dryRun mode regardless of whether the balancer switch
60+
* is enabled or disabled, but dryRun mode will not run over an existing
61+
* request or chore.
62+
*
63+
* Dry run is useful for testing out new balance configs. See the logs
64+
* on the active HMaster for the results of the dry run.
65+
*/
66+
public static BalanceRequest dryRun() {
67+
return new BalanceRequest(true, false);
68+
}
69+
70+
/**
71+
* Updates the BalancerRequest to cause the balancer to run even if there
72+
* are regions in transition.
73+
*
74+
* WARNING: Advanced usage only, this could cause more issues than it fixes.
75+
*/
76+
public BalanceRequest ignoreRegionsInTransition() {
77+
return new BalanceRequest(dryRun, true);
78+
}
79+
80+
public boolean isDryRun() {
81+
return dryRun;
82+
}
83+
84+
public boolean isIgnoreRegionsInTransition() {
85+
return ignoreRIT;
86+
}
87+
}

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 & 27 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;
@@ -1477,34 +1478,11 @@ protected Boolean rpcCall() throws Exception {
14771478
}
14781479

14791480
@Override
1480-
public boolean balance() throws IOException {
1481+
public boolean balance(BalanceRequest request) throws IOException {
14811482
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 {
1492-
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();
1483+
@Override protected Boolean rpcCall() throws Exception {
1484+
return master.balance(getRpcController(), RequestConverter.toBalanceRequest(request))
1485+
.getBalancerRan();
15081486
}
15091487
});
15101488
}

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 {

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import org.apache.hadoop.conf.Configuration;
4848
import org.apache.hadoop.fs.Path;
49+
import org.apache.hadoop.hbase.BalanceRequest;
4950
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
5051
import org.apache.hadoop.hbase.CacheEvictionStats;
5152
import org.apache.hadoop.hbase.CacheEvictionStatsBuilder;
@@ -2946,6 +2947,26 @@ public static TableDescriptor toTableDescriptor(final TableSchema ts) {
29462947
return builder.build();
29472948
}
29482949

2950+
/**
2951+
* Creates a {@link org.apache.hadoop.hbase.BalanceRequest.RunMode} from a
2952+
* {@link org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceRequest.RunMode}
2953+
* @param runMode the client model RunMode
2954+
* @return the protobuf RunMode
2955+
*/
2956+
public static MasterProtos.BalanceRequest.RunMode createRunMode(BalanceRequest.RunMode runMode) {
2957+
return MasterProtos.BalanceRequest.RunMode.valueOf(runMode.toString());
2958+
}
2959+
2960+
/**
2961+
* Creates a {@link org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceRequest.RunMode}
2962+
* from a {@link org.apache.hadoop.hbase.BalanceRequest.RunMode}
2963+
* @param runMode the protobuf RunMode
2964+
* @return the client RunMode
2965+
*/
2966+
public static BalanceRequest.RunMode createRunMode(MasterProtos.BalanceRequest.RunMode runMode) {
2967+
return BalanceRequest.RunMode.valueOf(runMode.toString());
2968+
}
2969+
29492970
/**
29502971
* Creates {@link CompactionState} from
29512972
* {@link org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState}

0 commit comments

Comments
 (0)