HDFS-16411 RBF: RouterId is NULL when disable RourterRpcServer (#3878)

This commit is contained in:
YulongZ 2022-02-09 00:40:57 +08:00 committed by GitHub
parent b39b334873
commit 3e7a7c3c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -196,6 +196,8 @@ public class Router extends CompositeService implements
this.setRpcServerAddress(rpcServer.getRpcAddress());
}
checkRouterId();
if (conf.getBoolean(
RBFConfigKeys.DFS_ROUTER_ADMIN_ENABLE,
RBFConfigKeys.DFS_ROUTER_ADMIN_ENABLE_DEFAULT)) {
@ -308,6 +310,21 @@ public class Router extends CompositeService implements
}
}
/**
* Set the router id if not set to prevent RouterHeartbeatService
* update state store with a null router id.
*/
private void checkRouterId() {
if (this.routerId == null) {
InetSocketAddress confRpcAddress = conf.getSocketAddr(
RBFConfigKeys.DFS_ROUTER_RPC_BIND_HOST_KEY,
RBFConfigKeys.DFS_ROUTER_RPC_ADDRESS_KEY,
RBFConfigKeys.DFS_ROUTER_RPC_ADDRESS_DEFAULT,
RBFConfigKeys.DFS_ROUTER_RPC_PORT_DEFAULT);
setRpcServerAddress(confRpcAddress);
}
}
private String getDisabledDependentServices() {
if (this.stateStore == null && this.adminServer == null) {
return StateStoreService.class.getSimpleName() + ","

View File

@ -223,10 +223,14 @@ public class TestRouter {
@Test
public void testSwitchRouter() throws IOException {
assertRouterHeartbeater(true, true);
assertRouterHeartbeater(true, false);
assertRouterHeartbeater(false, true);
assertRouterHeartbeater(false, false);
assertRouterHeartbeater(true, true, true);
assertRouterHeartbeater(true, true, false);
assertRouterHeartbeater(true, false, true);
assertRouterHeartbeater(true, false, false);
assertRouterHeartbeater(false, true, true);
assertRouterHeartbeater(false, true, false);
assertRouterHeartbeater(false, false, true);
assertRouterHeartbeater(false, false, false);
}
/**
@ -235,15 +239,19 @@ public class TestRouter {
* @param expectedRouterHeartbeat expect the routerHeartbeat enable state.
* @param expectedNNHeartbeat expect the nnHeartbeat enable state.
*/
private void assertRouterHeartbeater(boolean expectedRouterHeartbeat,
private void assertRouterHeartbeater(boolean enableRpcServer, boolean expectedRouterHeartbeat,
boolean expectedNNHeartbeat) throws IOException {
final Router router = new Router();
Configuration baseCfg = new RouterConfigBuilder(conf).rpc().build();
Configuration baseCfg = new RouterConfigBuilder(conf).rpc(enableRpcServer).build();
baseCfg.setBoolean(RBFConfigKeys.DFS_ROUTER_HEARTBEAT_ENABLE,
expectedRouterHeartbeat);
baseCfg.setBoolean(RBFConfigKeys.DFS_ROUTER_NAMENODE_HEARTBEAT_ENABLE,
expectedNNHeartbeat);
router.init(baseCfg);
// RouterId can not be null , used by RouterHeartbeatService.updateStateStore()
assertNotNull(router.getRouterId());
RouterHeartbeatService routerHeartbeatService =
router.getRouterHeartbeatService();
if (expectedRouterHeartbeat) {