Skip to content

Commit 4edd432

Browse files
committed
HBASE-26147: Add dry_run_balancer and related Admin interfaces for running the balancer without executing any region moves
1 parent 6ad7eb8 commit 4edd432

File tree

37 files changed

+629
-137
lines changed

37 files changed

+629
-137
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,19 @@ default boolean balancer() throws IOException {
12511251
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12521252
* @throws IOException if a remote or network exception occurs
12531253
*/
1254-
boolean balance() throws IOException;
1254+
default boolean balance() throws IOException {
1255+
return balance(BalanceRequest.defaultInstance());
1256+
}
1257+
1258+
/**
1259+
* Invoke the balancer with the given balance request. The BalanceRequest defines how the
1260+
* balancer will run. See {@link BalanceRequest} for more details.
1261+
*
1262+
* @param request defines how the balancer should run
1263+
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1264+
* @throws IOException if a remote or network exception occurs
1265+
*/
1266+
boolean balance(BalanceRequest request) throws IOException;
12551267

12561268
/**
12571269
* Invoke the balancer. Will run the balancer and if regions to move, it will
@@ -1262,7 +1274,7 @@ default boolean balancer() throws IOException {
12621274
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12631275
* @throws IOException if a remote or network exception occurs
12641276
* @deprecated Since 2.0.0. Will be removed in 3.0.0.
1265-
* Use {@link #balance(boolean)} instead.
1277+
* Use {@link #balance(BalanceRequest)} instead.
12661278
*/
12671279
@Deprecated
12681280
default boolean balancer(boolean force) throws IOException {
@@ -1277,8 +1289,17 @@ default boolean balancer(boolean force) throws IOException {
12771289
* @param force whether we should force balance even if there is region in transition
12781290
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12791291
* @throws IOException if a remote or network exception occurs
1292+
* @deprecated Since 2.5.0. Will be removed in 4.0.0.
1293+
* Use {@link #balance(BalanceRequest)} instead.
12801294
*/
1281-
boolean balance(boolean force) throws IOException;
1295+
@Deprecated
1296+
default boolean balance(boolean force) throws IOException {
1297+
return balance(
1298+
BalanceRequest.newBuilder()
1299+
.setIgnoreRegionsInTransition(force)
1300+
.build()
1301+
);
1302+
}
12821303

12831304
/**
12841305
* Query the current state of the balancer.

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ default CompletableFuture<Boolean> balancerSwitch(boolean on) {
12571257
* {@link CompletableFuture}.
12581258
*/
12591259
default CompletableFuture<Boolean> balance() {
1260-
return balance(false);
1260+
return balance(BalanceRequest.defaultInstance());
12611261
}
12621262

12631263
/**
@@ -1267,8 +1267,25 @@ default CompletableFuture<Boolean> balance() {
12671267
* @param forcible whether we should force balance even if there is region in transition.
12681268
* @return True if balancer ran, false otherwise. The return value will be wrapped by a
12691269
* {@link CompletableFuture}.
1270+
* @deprecated Since 2.5.0. Will be removed in 4.0.0.
1271+
* Use {@link #balance(BalanceRequest)} instead.
1272+
*/
1273+
default CompletableFuture<Boolean> balance(boolean forcible) {
1274+
return balance(
1275+
BalanceRequest.newBuilder()
1276+
.setIgnoreRegionsInTransition(forcible)
1277+
.build()
1278+
);
1279+
}
1280+
1281+
/**
1282+
* Invoke the balancer with the given balance request. The BalanceRequest defines how the
1283+
* balancer will run. See {@link BalanceRequest} for more details.
1284+
*
1285+
* @param request defines how the balancer should run
1286+
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
12701287
*/
1271-
CompletableFuture<Boolean> balance(boolean forcible);
1288+
CompletableFuture<Boolean> balance(BalanceRequest request);
12721289

12731290
/**
12741291
* Query the current state of the balancer.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs)
684684
}
685685

686686
@Override
687-
public CompletableFuture<Boolean> balance(boolean forcible) {
688-
return wrap(rawAdmin.balance(forcible));
687+
public CompletableFuture<Boolean> balance(BalanceRequest request) {
688+
return wrap(rawAdmin.balance(request));
689689
}
690690

691691
@Override
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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.client;
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 final class BalanceRequest {
30+
private static final BalanceRequest DEFAULT = BalanceRequest.newBuilder().build();
31+
32+
@InterfaceAudience.Public
33+
@InterfaceStability.Evolving
34+
public final static class Builder {
35+
private boolean dryRun = false;
36+
private boolean ignoreRegionsInTransition = false;
37+
38+
private Builder() {}
39+
40+
/**
41+
* Creates a BalancerRequest which runs the balancer in dryRun mode.
42+
* In this mode, the balancer will try to find a plan but WILL NOT
43+
* execute any region moves or call any coprocessors.
44+
*
45+
* You can run in dryRun mode regardless of whether the balancer switch
46+
* is enabled or disabled, but dryRun mode will not run over an existing
47+
* request or chore.
48+
*
49+
* Dry run is useful for testing out new balance configs. See the logs
50+
* on the active HMaster for the results of the dry run.
51+
*/
52+
public Builder setDryRun(boolean dryRun) {
53+
this.dryRun = dryRun;
54+
return this;
55+
}
56+
57+
/**
58+
* Creates a BalancerRequest to cause the balancer to run even if there
59+
* are regions in transition.
60+
*
61+
* WARNING: Advanced usage only, this could cause more issues than it fixes.
62+
*/
63+
public Builder setIgnoreRegionsInTransition(boolean ignoreRegionsInTransition) {
64+
this.ignoreRegionsInTransition = ignoreRegionsInTransition;
65+
return this;
66+
}
67+
68+
public BalanceRequest build() {
69+
return new BalanceRequest(dryRun, ignoreRegionsInTransition);
70+
}
71+
}
72+
73+
public static Builder newBuilder() {
74+
return new Builder();
75+
}
76+
77+
public static BalanceRequest defaultInstance() {
78+
return DEFAULT;
79+
}
80+
81+
private final boolean dryRun;
82+
private final boolean ignoreRegionsInTransition;
83+
84+
private BalanceRequest(boolean dryRun, boolean ignoreRegionsInTransition) {
85+
this.dryRun = dryRun;
86+
this.ignoreRegionsInTransition = ignoreRegionsInTransition;
87+
}
88+
89+
public boolean isDryRun() {
90+
return dryRun;
91+
}
92+
93+
public boolean isIgnoreRegionsInTransition() {
94+
return ignoreRegionsInTransition;
95+
}
96+
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,23 +1477,11 @@ protected Boolean rpcCall() throws Exception {
14771477
}
14781478

14791479
@Override
1480-
public boolean balance() throws IOException {
1480+
public boolean balance(BalanceRequest request) throws IOException {
14811481
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();
1482+
@Override protected Boolean rpcCall() throws Exception {
1483+
return master.balance(getRpcController(), ProtobufUtil.toBalanceRequest(request))
1484+
.getBalancerRan();
14971485
}
14981486
});
14991487
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,13 @@
126126
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription;
127127
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
128128
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema;
129+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
129130
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureRequest;
130131
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureResponse;
131132
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest;
132133
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnResponse;
133134
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionRequest;
134135
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;
137136
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersRequest;
138137
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersResponse;
139138
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest;
@@ -3210,15 +3209,16 @@ public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs)
32103209
}
32113210

32123211
@Override
3213-
public CompletableFuture<Boolean> balance(boolean forcible) {
3212+
public CompletableFuture<Boolean> balance(BalanceRequest request) {
32143213
return this
32153214
.<Boolean> newMasterCaller()
32163215
.action(
3217-
(controller, stub) -> this.<BalanceRequest, BalanceResponse, Boolean> call(controller,
3218-
stub, RequestConverter.buildBalanceRequest(forcible),
3216+
(controller, stub) -> this.<MasterProtos.BalanceRequest, MasterProtos.BalanceResponse, Boolean> call(controller,
3217+
stub, ProtobufUtil.toBalanceRequest(request),
32193218
(s, c, req, done) -> s.balance(c, req, done), (resp) -> resp.getBalancerRan())).call();
32203219
}
32213220

3221+
32223222
@Override
32233223
public CompletableFuture<Boolean> isBalancerEnabled() {
32243224
return this

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

Lines changed: 15 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.client.BalanceRequest;
4950
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
5051
import org.apache.hadoop.hbase.CacheEvictionStats;
5152
import org.apache.hadoop.hbase.CacheEvictionStatsBuilder;
@@ -3753,4 +3754,18 @@ public static HBaseProtos.LogRequest toBalancerRejectionRequest(int limit) {
37533754
.build();
37543755
}
37553756

3757+
public static MasterProtos.BalanceRequest toBalanceRequest(BalanceRequest request) {
3758+
return MasterProtos.BalanceRequest.newBuilder()
3759+
.setDryRun(request.isDryRun())
3760+
.setIgnoreRit(request.isIgnoreRegionsInTransition())
3761+
.build();
3762+
}
3763+
3764+
public static BalanceRequest toBalanceRequest(MasterProtos.BalanceRequest request) {
3765+
return BalanceRequest.newBuilder()
3766+
.setDryRun(request.hasDryRun() && request.getDryRun())
3767+
.setIgnoreRegionsInTransition(request.hasIgnoreRit() && request.getIgnoreRit())
3768+
.build();
3769+
}
3770+
37563771
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
107107
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest;
108108
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionRequest;
109-
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceRequest;
110109
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersRequest;
111110
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest;
112111
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableRequest;
@@ -1576,15 +1575,6 @@ public static IsMasterRunningRequest buildIsMasterRunningRequest() {
15761575
return IsMasterRunningRequest.newBuilder().build();
15771576
}
15781577

1579-
/**
1580-
* Creates a protocol buffer BalanceRequest
1581-
*
1582-
* @return a BalanceRequest
1583-
*/
1584-
public static BalanceRequest buildBalanceRequest(boolean force) {
1585-
return BalanceRequest.newBuilder().setForce(force).build();
1586-
}
1587-
15881578
/**
15891579
* Creates a protocol buffer SetBalancerRunningRequest
15901580
*

hbase-protocol-shaded/src/main/protobuf/Master.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ message IsInMaintenanceModeResponse {
292292
}
293293

294294
message BalanceRequest {
295-
optional bool force = 1;
295+
optional bool ignore_rit = 1;
296+
optional bool dry_run = 2;
296297
}
297298

298299
message BalanceResponse {

hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdmin.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Set;
2424

2525
import org.apache.hadoop.hbase.TableName;
26+
import org.apache.hadoop.hbase.client.BalanceRequest;
2627
import org.apache.hadoop.hbase.net.Address;
2728
import org.apache.yetus.audience.InterfaceAudience;
2829

@@ -67,7 +68,17 @@ public interface RSGroupAdmin {
6768
*
6869
* @return boolean Whether balance ran or not
6970
*/
70-
boolean balanceRSGroup(String groupName) throws IOException;
71+
default boolean balanceRSGroup(String groupName) throws IOException {
72+
return balanceRSGroup(groupName, BalanceRequest.defaultInstance());
73+
}
74+
75+
/**
76+
* Balance regions in the given RegionServer group, running based on
77+
* the given {@link BalanceRequest}.
78+
*
79+
* @return boolean Whether balance ran or not
80+
*/
81+
boolean balanceRSGroup(String groupName, BalanceRequest request) throws IOException;
7182

7283
/**
7384
* Lists current set of RegionServer groups.

0 commit comments

Comments
 (0)