HBASE-26688 Threads shared EMPTY_RESULT may lead to unexpected client job down. ...
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / BalanceResponse.java
blob143878209d1172c70af3ad8547b02ae7cae66a26
1 /*
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org.apache.hadoop.hbase.client;
21 import org.apache.yetus.audience.InterfaceAudience;
23 /**
24 * Response returned from a balancer invocation
26 @InterfaceAudience.Public
27 public final class BalanceResponse {
29 /**
30 * Used in HMaster to build a {@link BalanceResponse} for returning results of a balance invocation to callers
32 @InterfaceAudience.Private
33 public final static class Builder {
34 private boolean balancerRan;
35 private int movesCalculated;
36 private int movesExecuted;
38 private Builder() {}
40 /**
41 * Set true if the balancer ran, otherwise false. The balancer may not run in some
42 * circumstances, such as if a balance is already running or there are regions already
43 * in transition.
45 * @param balancerRan true if balancer ran, false otherwise
47 public Builder setBalancerRan(boolean balancerRan) {
48 this.balancerRan = balancerRan;
49 return this;
52 /**
53 * Set how many moves were calculated by the balancer. This will be zero if the cluster is
54 * already balanced.
56 * @param movesCalculated moves calculated by the balance run
58 public Builder setMovesCalculated(int movesCalculated) {
59 this.movesCalculated = movesCalculated;
60 return this;
63 /**
64 * Set how many of the calculated moves were actually executed by the balancer. This should be
65 * zero if the balancer is run with {@link BalanceRequest#isDryRun()}. It may also not equal
66 * movesCalculated if the balancer ran out of time while executing the moves.
68 * @param movesExecuted moves executed by the balance run
70 public Builder setMovesExecuted(int movesExecuted) {
71 this.movesExecuted = movesExecuted;
72 return this;
75 /**
76 * Build the {@link BalanceResponse}
78 public BalanceResponse build() {
79 return new BalanceResponse(balancerRan, movesCalculated, movesExecuted);
83 /**
84 * Creates a new {@link BalanceResponse.Builder}
86 public static Builder newBuilder() {
87 return new Builder();
90 private final boolean balancerRan;
91 private final int movesCalculated;
92 private final int movesExecuted;
94 private BalanceResponse(boolean balancerRan, int movesCalculated, int movesExecuted) {
95 this.balancerRan = balancerRan;
96 this.movesCalculated = movesCalculated;
97 this.movesExecuted = movesExecuted;
101 * Returns true if the balancer ran, otherwise false. The balancer may not run for a
102 * variety of reasons, such as: another balance is running, there are regions in
103 * transition, the cluster is in maintenance mode, etc.
105 public boolean isBalancerRan() {
106 return balancerRan;
110 * The number of moves calculated by the balancer if {@link #isBalancerRan()} is true. This will
111 * be zero if no better balance could be found.
113 public int getMovesCalculated() {
114 return movesCalculated;
118 * The number of moves actually executed by the balancer if it ran. This will be
119 * zero if {@link #getMovesCalculated()} is zero or if {@link BalanceRequest#isDryRun()}
120 * was true. It may also not be equal to {@link #getMovesCalculated()} if the balancer
121 * was interrupted midway through executing the moves due to max run time.
123 public int getMovesExecuted() {
124 return movesExecuted;