Skip to content

Commit 7995e64

Browse files
committed
Add a new BalancerResponse object
1 parent 4edd432 commit 7995e64

File tree

32 files changed

+292
-113
lines changed

32 files changed

+292
-113
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,18 +1252,19 @@ default boolean balancer() throws IOException {
12521252
* @throws IOException if a remote or network exception occurs
12531253
*/
12541254
default boolean balance() throws IOException {
1255-
return balance(BalanceRequest.defaultInstance());
1255+
return balance(BalanceRequest.defaultInstance())
1256+
.isBalancerRan();
12561257
}
12571258

12581259
/**
12591260
* Invoke the balancer with the given balance request. The BalanceRequest defines how the
12601261
* balancer will run. See {@link BalanceRequest} for more details.
12611262
*
12621263
* @param request defines how the balancer should run
1263-
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1264+
* @return {@link BalanceResponse} with details about the results of the invocation.
12641265
* @throws IOException if a remote or network exception occurs
12651266
*/
1266-
boolean balance(BalanceRequest request) throws IOException;
1267+
BalanceResponse balance(BalanceRequest request) throws IOException;
12671268

12681269
/**
12691270
* Invoke the balancer. Will run the balancer and if regions to move, it will
@@ -1298,7 +1299,7 @@ default boolean balance(boolean force) throws IOException {
12981299
BalanceRequest.newBuilder()
12991300
.setIgnoreRegionsInTransition(force)
13001301
.build()
1301-
);
1302+
).isBalancerRan();
13021303
}
13031304

13041305
/**

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,8 @@ default CompletableFuture<Boolean> balancerSwitch(boolean on) {
12571257
* {@link CompletableFuture}.
12581258
*/
12591259
default CompletableFuture<Boolean> balance() {
1260-
return balance(BalanceRequest.defaultInstance());
1260+
return balance(BalanceRequest.defaultInstance())
1261+
.thenApply(BalanceResponse::isBalancerRan);
12611262
}
12621263

12631264
/**
@@ -1275,17 +1276,17 @@ default CompletableFuture<Boolean> balance(boolean forcible) {
12751276
BalanceRequest.newBuilder()
12761277
.setIgnoreRegionsInTransition(forcible)
12771278
.build()
1278-
);
1279+
).thenApply(BalanceResponse::isBalancerRan);
12791280
}
12801281

12811282
/**
12821283
* Invoke the balancer with the given balance request. The BalanceRequest defines how the
12831284
* balancer will run. See {@link BalanceRequest} for more details.
12841285
*
12851286
* @param request defines how the balancer should run
1286-
* @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1287+
* @return {@link BalanceResponse} with details about the results of the invocation.
12871288
*/
1288-
CompletableFuture<Boolean> balance(BalanceRequest request);
1289+
CompletableFuture<BalanceResponse> balance(BalanceRequest request);
12891290

12901291
/**
12911292
* Query the current state of the balancer.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs)
684684
}
685685

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.yetus.audience.InterfaceStability;
2323

2424
/**
25-
* Encapsulates options for executing an unscheduled run of the Balancer.
25+
* Encapsulates options for executing a run of the Balancer.
2626
*/
2727
@InterfaceAudience.Public
2828
@InterfaceStability.Evolving
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.apache.hadoop.hbase.client;
2+
3+
import org.apache.yetus.audience.InterfaceAudience;
4+
import org.apache.yetus.audience.InterfaceStability;
5+
6+
/**
7+
* Response returned from a balancer invocation
8+
*/
9+
@InterfaceAudience.Public
10+
@InterfaceStability.Evolving
11+
public final class BalanceResponse {
12+
13+
@InterfaceAudience.Public
14+
@InterfaceStability.Evolving
15+
public final static class Builder {
16+
private boolean balancerRan;
17+
private int movesCalculated;
18+
private int movesExecuted;
19+
20+
private Builder() {}
21+
22+
public Builder setBalancerRan(boolean balancerRan) {
23+
this.balancerRan = balancerRan;
24+
return this;
25+
}
26+
27+
public Builder setMovesCalculated(int movesCalculated) {
28+
this.movesCalculated = movesCalculated;
29+
return this;
30+
}
31+
32+
public Builder setMovesExecuted(int movesExecuted) {
33+
this.movesExecuted = movesExecuted;
34+
return this;
35+
}
36+
37+
public BalanceResponse build() {
38+
return new BalanceResponse(balancerRan, movesCalculated, movesExecuted);
39+
}
40+
}
41+
42+
public static Builder newBuilder() {
43+
return new Builder();
44+
}
45+
46+
private final boolean balancerRan;
47+
private final int movesCalculated;
48+
private final int movesExecuted;
49+
50+
private BalanceResponse(boolean balancerRan, int movesCalculated, int movesExecuted) {
51+
this.balancerRan = balancerRan;
52+
this.movesCalculated = movesCalculated;
53+
this.movesExecuted = movesExecuted;
54+
}
55+
56+
/**
57+
* Determines whether the balancer ran or not. The balancer may not run for a variety of reasons,
58+
* such as: another balance is running, there are regions in transition, the cluster is in
59+
* maintenance mode, etc.
60+
*/
61+
public boolean isBalancerRan() {
62+
return balancerRan;
63+
}
64+
65+
/**
66+
* The number of moves calculated by the balancer if it ran. This may be zero if
67+
* no better balance could be found.
68+
*/
69+
public int getMovesCalculated() {
70+
return movesCalculated;
71+
}
72+
73+
/**
74+
* The number of moves actually executed by the balancer if it ran. This will be
75+
* zero if {@link #getMovesCalculated()} is zero or if {@link BalanceRequest#isDryRun()}
76+
* was true. It may also not be equal to {@link #getMovesCalculated()} if the balancer
77+
* was interrupted midway through executing the moves due to max run time.
78+
*/
79+
public int getMovesExecuted() {
80+
return movesExecuted;
81+
}
82+
}

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@
9292
import org.apache.hadoop.hbase.security.access.Permission;
9393
import org.apache.hadoop.hbase.security.access.ShadedAccessControlUtil;
9494
import org.apache.hadoop.hbase.security.access.UserPermission;
95+
import org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils;
96+
import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
97+
import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
98+
import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
99+
import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
100+
import org.apache.hadoop.hbase.util.Addressing;
101+
import org.apache.hadoop.hbase.util.Bytes;
102+
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
103+
import org.apache.hadoop.hbase.util.ForeignExceptionUtil;
104+
import org.apache.hadoop.hbase.util.Pair;
105+
import org.apache.hadoop.ipc.RemoteException;
106+
import org.apache.hadoop.util.StringUtils;
107+
import org.apache.yetus.audience.InterfaceAudience;
108+
import org.apache.yetus.audience.InterfaceStability;
109+
import org.slf4j.Logger;
110+
import org.slf4j.LoggerFactory;
111+
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
112+
import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
113+
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
95114
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
96115
import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
97116
import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos;
@@ -163,8 +182,7 @@
163182
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsProcedureDoneRequest;
164183
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsProcedureDoneResponse;
165184
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsRpcThrottleEnabledRequest;
166-
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos
167-
.IsSnapshotCleanupEnabledRequest;
185+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotCleanupEnabledRequest;
168186
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest;
169187
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse;
170188
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersRequest;
@@ -211,25 +229,6 @@
211229
import org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos.RemoveReplicationPeerResponse;
212230
import org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos.UpdateReplicationPeerConfigResponse;
213231
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos;
214-
import org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils;
215-
import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
216-
import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
217-
import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
218-
import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
219-
import org.apache.hadoop.hbase.util.Addressing;
220-
import org.apache.hadoop.hbase.util.Bytes;
221-
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
222-
import org.apache.hadoop.hbase.util.ForeignExceptionUtil;
223-
import org.apache.hadoop.hbase.util.Pair;
224-
import org.apache.hadoop.ipc.RemoteException;
225-
import org.apache.hadoop.util.StringUtils;
226-
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
227-
import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
228-
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
229-
import org.apache.yetus.audience.InterfaceAudience;
230-
import org.apache.yetus.audience.InterfaceStability;
231-
import org.slf4j.Logger;
232-
import org.slf4j.LoggerFactory;
233232

234233
/**
235234
* HBaseAdmin is no longer a client API. It is marked InterfaceAudience.Private indicating that
@@ -1476,14 +1475,14 @@ protected Boolean rpcCall() throws Exception {
14761475
});
14771476
}
14781477

1479-
@Override
1480-
public boolean balance(BalanceRequest request) throws IOException {
1481-
return executeCallable(new MasterCallable<Boolean>(getConnection(), getRpcControllerFactory()) {
1482-
@Override protected Boolean rpcCall() throws Exception {
1483-
return master.balance(getRpcController(), ProtobufUtil.toBalanceRequest(request))
1484-
.getBalancerRan();
1485-
}
1486-
});
1478+
@Override public BalanceResponse balance(BalanceRequest request) throws IOException {
1479+
return executeCallable(
1480+
new MasterCallable<BalanceResponse>(getConnection(), getRpcControllerFactory()) {
1481+
@Override protected BalanceResponse rpcCall() throws Exception {
1482+
MasterProtos.BalanceRequest req = ProtobufUtil.toBalanceRequest(request);
1483+
return ProtobufUtil.toBalanceResponse(master.balance(getRpcController(), req));
1484+
}
1485+
});
14871486
}
14881487

14891488
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,13 +3209,13 @@ public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs)
32093209
}
32103210

32113211
@Override
3212-
public CompletableFuture<Boolean> balance(BalanceRequest request) {
3212+
public CompletableFuture<BalanceResponse> balance(BalanceRequest request) {
32133213
return this
3214-
.<Boolean> newMasterCaller()
3214+
.<BalanceResponse> newMasterCaller()
32153215
.action(
3216-
(controller, stub) -> this.<MasterProtos.BalanceRequest, MasterProtos.BalanceResponse, Boolean> call(controller,
3216+
(controller, stub) -> this.<MasterProtos.BalanceRequest, MasterProtos.BalanceResponse, BalanceResponse> call(controller,
32173217
stub, ProtobufUtil.toBalanceRequest(request),
3218-
(s, c, req, done) -> s.balance(c, req, done), (resp) -> resp.getBalancerRan())).call();
3218+
(s, c, req, done) -> s.balance(c, req, done), (resp) -> ProtobufUtil.toBalanceResponse(resp))).call();
32193219
}
32203220

32213221

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.apache.hadoop.hbase.ServerName;
6969
import org.apache.hadoop.hbase.TableName;
7070
import org.apache.hadoop.hbase.client.Append;
71+
import org.apache.hadoop.hbase.client.BalanceResponse;
7172
import org.apache.hadoop.hbase.client.BalancerRejection;
7273
import org.apache.hadoop.hbase.client.BalancerDecision;
7374
import org.apache.hadoop.hbase.client.CheckAndMutate;
@@ -3768,4 +3769,20 @@ public static BalanceRequest toBalanceRequest(MasterProtos.BalanceRequest reques
37683769
.build();
37693770
}
37703771

3772+
public static MasterProtos.BalanceResponse toBalanceResponse(BalanceResponse response) {
3773+
return MasterProtos.BalanceResponse.newBuilder()
3774+
.setBalancerRan(response.isBalancerRan())
3775+
.setMovesCalculated(response.getMovesCalculated())
3776+
.setMovesExecuted(response.getMovesExecuted())
3777+
.build();
3778+
}
3779+
3780+
public static BalanceResponse toBalanceResponse(MasterProtos.BalanceResponse response) {
3781+
return BalanceResponse.newBuilder()
3782+
.setBalancerRan(response.hasBalancerRan() && response.getBalancerRan())
3783+
.setMovesCalculated(response.hasMovesCalculated() ? response.getMovesExecuted() : 0)
3784+
.setMovesExecuted(response.hasMovesExecuted() ? response.getMovesExecuted() : 0)
3785+
.build();
3786+
}
3787+
37713788
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ message BalanceRequest {
298298

299299
message BalanceResponse {
300300
required bool balancer_ran = 1;
301+
optional uint32 moves_calculated = 2;
302+
optional uint32 moves_executed = 3;
301303
}
302304

303305
message SetBalancerRunningRequest {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.apache.hadoop.hbase.TableName;
2626
import org.apache.hadoop.hbase.client.BalanceRequest;
27+
import org.apache.hadoop.hbase.client.BalanceResponse;
2728
import org.apache.hadoop.hbase.net.Address;
2829
import org.apache.yetus.audience.InterfaceAudience;
2930

@@ -68,7 +69,7 @@ public interface RSGroupAdmin {
6869
*
6970
* @return boolean Whether balance ran or not
7071
*/
71-
default boolean balanceRSGroup(String groupName) throws IOException {
72+
default BalanceResponse balanceRSGroup(String groupName) throws IOException {
7273
return balanceRSGroup(groupName, BalanceRequest.defaultInstance());
7374
}
7475

@@ -78,7 +79,7 @@ default boolean balanceRSGroup(String groupName) throws IOException {
7879
*
7980
* @return boolean Whether balance ran or not
8081
*/
81-
boolean balanceRSGroup(String groupName, BalanceRequest request) throws IOException;
82+
BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) throws IOException;
8283

8384
/**
8485
* Lists current set of RegionServer groups.

0 commit comments

Comments
 (0)