hbase中balance的status一会儿为true,一会儿为false

各位大神,我在hbase集群上执行了“balance_switch true”
随后执行“balance_switch status”的时候,结果一会儿为true,一会儿为false。
请问这个是什么原因?
已邀请:

ProgramGeek

赞同来自: beyond Leo Peng

首先看balance_switch命令对应的rb文件源码:
module Shell
module Commands
class BalanceSwitch < Command
def help
<<-EOF
Enable/Disable balancer. Returns previous balancer state.
Examples:

hbase> balance_switch true
hbase> balance_switch false
EOF
end

def command(enableDisable)
prev_state = admin.balance_switch(enableDisable) ? 'true' : 'false'
formatter.row(["Previous balancer state : #{prev_state}"])
prev_state
end
end
end
end
该命令输出的是之前balancer的状态,其次再看balance_switch的处理源码:
public SetBalancerRunningResponse setBalancerRunning(RpcController c,
SetBalancerRunningRequest req) throws ServiceException {
try {
master.checkInitialized();
boolean prevValue = (req.getSynchronous())?
synchronousBalanceSwitch(req.getOn()) : master.balanceSwitch(req.getOn());
return SetBalancerRunningResponse.newBuilder().setPrevBalanceValue(prevValue).build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}

public boolean balanceSwitch(final boolean b) throws IOException {
return getMasterRpcServices().switchBalancer(b, BalanceSwitchMode.ASYNC);
}

/**
* Assigns balancer switch according to BalanceSwitchMode
* @param b new balancer switch
* @param mode BalanceSwitchMode
* @return old balancer switch
*/
boolean switchBalancer(final boolean b, BalanceSwitchMode mode) throws IOException {
boolean oldValue = master.loadBalancerTracker.isBalancerOn();
boolean newValue = b;
try {
if (master.cpHost != null) {
master.cpHost.preBalanceSwitch(newValue);
}
try {
if (mode == BalanceSwitchMode.SYNC) {
synchronized (master.getLoadBalancer()) {
master.loadBalancerTracker.setBalancerOn(newValue);
}
} else {
master.loadBalancerTracker.setBalancerOn(newValue);
}
} catch (KeeperException ke) {
throw new IOException(ke);
}
LOG.info(master.getClientIdAuditPrefix() " set balanceSwitch=" newValue);
if (master.cpHost != null) {
master.cpHost.postBalanceSwitch(oldValue, newValue);
}
} catch (IOException ioe) {
LOG.warn("Error flipping balance switch", ioe);
}
return oldValue;
}
从switchBalancer方法也能看到返回的是之前balancer的状态值。
至于status参数设置的balanceSwitch为false是因为admin.rb文件在处理参数的时候如果传status则
java.lang.Boolean.valueOf(enableDisable)为false,并且shell.rb文件指定了哪些参数是符合要求的,status是其中之一,而其他的譬如state这种参数会报异常。
#----------------------------------------------------------------------------------------------
# Enable/disable balancer
# Returns previous balancer switch setting.
def balance_switch(enableDisable)
@admin.setBalancerRunning(
java.lang.Boolean.valueOf(enableDisable), java.lang.Boolean.valueOf(false)
)
end

# Load all commands
Shell.load_command_group(
'general',
full_name: 'GENERAL HBASE SHELL COMMANDS',
commands: %w[
status
version
table_help
whoami
processlist
]
)

beyond

赞同来自: Leo hbasegroup

balancer_enabled 显示负载均衡状态
balance_switch status 会把负载均衡状态关闭
 

beyond

赞同来自: hbasegroup point

楼上正解,balance_switch  status    其中status是shell命令的系统字段,state不是,所以执行state会报错,另外执行balance_switch ‘xx'也是会出现balance_switch 变为false,其中xx为任意字段。
 
另外开关负载均衡命令是:balance_switch true|false,没有balance_switch status这样的命令。
balancer_enabled 才是查看负载均衡状态 
 

Leo

赞同来自: 闻帅

问题已解决,结论是 "balance_switch status"语句的作用并不是查询当前是否开启自动balance,而是会强制将balance状态改为false
真正查询是否开启自动balance的语句为“balancer_enabled"

oysl - 90后

赞同来自: Leo

balance_switch status 转换负载均衡状态
balancer_enabled 负载均衡是否可用

Leo

赞同来自:

还是大神厉害!

hmaster - HBase 从业者

赞同来自:

balance_switch  xxx 只是切换状态
balancer_enabled 是查看
balancer 才是立刻执行

要回复问题请先登录注册


中国HBase技术社区微信公众号:
hbasegroup

欢迎加入HBase生态+Spark社区钉钉大群