HDFS-15613. RBF: Router FSCK fails after HDFS-14442. (#2360)
* Support getHAServiceState in DFSRouter
(cherry picked from commit 074f0d46af
)
This commit is contained in:
parent
c789e944b7
commit
89314a7bae
|
@ -1768,10 +1768,11 @@ public class RouterClientProtocol implements ClientProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HAServiceProtocol.HAServiceState getHAServiceState()
|
public HAServiceProtocol.HAServiceState getHAServiceState() {
|
||||||
throws IOException {
|
if (rpcServer.isSafeMode()) {
|
||||||
rpcServer.checkOperation(NameNode.OperationCategory.READ, false);
|
return HAServiceProtocol.HAServiceState.STANDBY;
|
||||||
return null;
|
}
|
||||||
|
return HAServiceProtocol.HAServiceState.ACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -526,8 +526,7 @@ public class RouterRpcServer extends AbstractService implements ClientProtocol,
|
||||||
* client requests.
|
* client requests.
|
||||||
*/
|
*/
|
||||||
private void checkSafeMode() throws StandbyException {
|
private void checkSafeMode() throws StandbyException {
|
||||||
RouterSafemodeService safemodeService = router.getSafemodeService();
|
if (isSafeMode()) {
|
||||||
if (safemodeService != null && safemodeService.isInSafeMode()) {
|
|
||||||
// Throw standby exception, router is not available
|
// Throw standby exception, router is not available
|
||||||
if (rpcMonitor != null) {
|
if (rpcMonitor != null) {
|
||||||
rpcMonitor.routerFailureSafemode();
|
rpcMonitor.routerFailureSafemode();
|
||||||
|
@ -538,6 +537,16 @@ public class RouterRpcServer extends AbstractService implements ClientProtocol,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the Router is in safe mode.
|
||||||
|
*
|
||||||
|
* @return true if the Router is in safe mode.
|
||||||
|
*/
|
||||||
|
boolean isSafeMode() {
|
||||||
|
RouterSafemodeService safemodeService = router.getSafemodeService();
|
||||||
|
return (safemodeService != null && safemodeService.isInSafeMode());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the method that is calling this function.
|
* Get the name of the method that is calling this function.
|
||||||
*
|
*
|
||||||
|
|
|
@ -932,6 +932,10 @@ public class TestRouterAdminCLI {
|
||||||
// ensure the Router become RUNNING state
|
// ensure the Router become RUNNING state
|
||||||
waitState(RouterServiceState.RUNNING);
|
waitState(RouterServiceState.RUNNING);
|
||||||
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
||||||
|
final RouterClientProtocol clientProtocol =
|
||||||
|
routerContext.getRouter().getRpcServer().getClientProtocolModule();
|
||||||
|
assertEquals(HAServiceState.ACTIVE, clientProtocol.getHAServiceState());
|
||||||
|
|
||||||
assertEquals(0,
|
assertEquals(0,
|
||||||
ToolRunner.run(admin, new String[] {"-safemode", "enter" }));
|
ToolRunner.run(admin, new String[] {"-safemode", "enter" }));
|
||||||
|
|
||||||
|
@ -944,6 +948,7 @@ public class TestRouterAdminCLI {
|
||||||
// verify state using RBFMetrics
|
// verify state using RBFMetrics
|
||||||
assertEquals(RouterServiceState.SAFEMODE.toString(), jsonString);
|
assertEquals(RouterServiceState.SAFEMODE.toString(), jsonString);
|
||||||
assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
||||||
|
assertEquals(HAServiceState.STANDBY, clientProtocol.getHAServiceState());
|
||||||
|
|
||||||
System.setOut(new PrintStream(out));
|
System.setOut(new PrintStream(out));
|
||||||
assertEquals(0,
|
assertEquals(0,
|
||||||
|
@ -955,6 +960,7 @@ public class TestRouterAdminCLI {
|
||||||
// verify state
|
// verify state
|
||||||
assertEquals(RouterServiceState.RUNNING.toString(), jsonString);
|
assertEquals(RouterServiceState.RUNNING.toString(), jsonString);
|
||||||
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
||||||
|
assertEquals(HAServiceState.ACTIVE, clientProtocol.getHAServiceState());
|
||||||
|
|
||||||
out.reset();
|
out.reset();
|
||||||
assertEquals(0, ToolRunner.run(admin, new String[] {"-safemode", "get" }));
|
assertEquals(0, ToolRunner.run(admin, new String[] {"-safemode", "get" }));
|
||||||
|
|
Loading…
Reference in New Issue