各位大神,我在hbase集群上执行了“balance_switch true”
随后执行“balance_switch status”的时候,结果一会儿为true,一会儿为false。
请问这个是什么原因?
balance_switch status 是将balance状态强制转换为false, 无论之前是true还是false, 返回的是之前的状态。 查看balance_switch 状态的命令是使用balancer_enabled
首先看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 balancerReturns 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
]
)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。