HDFS-15613. RBF: Router FSCK fails after HDFS-14442. (#2360)

* Support getHAServiceState in DFSRouter

(cherry picked from commit 074f0d46af)
This commit is contained in:
Akira Ajisaka 2020-10-07 13:37:45 +09:00
parent c789e944b7
commit 89314a7bae
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
3 changed files with 22 additions and 6 deletions

View File

@ -1768,10 +1768,11 @@ public void satisfyStoragePolicy(String path) throws IOException {
}
@Override
public HAServiceProtocol.HAServiceState getHAServiceState()
throws IOException {
rpcServer.checkOperation(NameNode.OperationCategory.READ, false);
return null;
public HAServiceProtocol.HAServiceState getHAServiceState() {
if (rpcServer.isSafeMode()) {
return HAServiceProtocol.HAServiceState.STANDBY;
}
return HAServiceProtocol.HAServiceState.ACTIVE;
}
/**

View File

@ -526,8 +526,7 @@ void checkOperation(OperationCategory op)
* client requests.
*/
private void checkSafeMode() throws StandbyException {
RouterSafemodeService safemodeService = router.getSafemodeService();
if (safemodeService != null && safemodeService.isInSafeMode()) {
if (isSafeMode()) {
// Throw standby exception, router is not available
if (rpcMonitor != null) {
rpcMonitor.routerFailureSafemode();
@ -538,6 +537,16 @@ private void checkSafeMode() throws StandbyException {
}
}
/**
* 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.
*

View File

@ -932,6 +932,10 @@ public void testSafeModeStatus() throws Exception {
// ensure the Router become RUNNING state
waitState(RouterServiceState.RUNNING);
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
final RouterClientProtocol clientProtocol =
routerContext.getRouter().getRpcServer().getClientProtocolModule();
assertEquals(HAServiceState.ACTIVE, clientProtocol.getHAServiceState());
assertEquals(0,
ToolRunner.run(admin, new String[] {"-safemode", "enter" }));
@ -944,6 +948,7 @@ public void testSafeModeStatus() throws Exception {
// verify state using RBFMetrics
assertEquals(RouterServiceState.SAFEMODE.toString(), jsonString);
assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
assertEquals(HAServiceState.STANDBY, clientProtocol.getHAServiceState());
System.setOut(new PrintStream(out));
assertEquals(0,
@ -955,6 +960,7 @@ public void testSafeModeStatus() throws Exception {
// verify state
assertEquals(RouterServiceState.RUNNING.toString(), jsonString);
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
assertEquals(HAServiceState.ACTIVE, clientProtocol.getHAServiceState());
out.reset();
assertEquals(0, ToolRunner.run(admin, new String[] {"-safemode", "get" }));