HDFS-14067. [SBN read] Allow manual failover between standby and observer. Contributed by Chao Sun.

This commit is contained in:
Chao Sun 2018-11-24 13:55:43 -08:00 committed by Konstantin V Shvachko
parent a3aab48df0
commit cbc2f932eb
2 changed files with 12 additions and 2 deletions

View File

@ -476,6 +476,7 @@ protected int runCmd(String[] argv) throws Exception {
// Mutative commands take FORCEMANUAL option
if ("-transitionToActive".equals(cmd) ||
"-transitionToStandby".equals(cmd) ||
"-transitionToObserver".equals(cmd) ||
"-failover".equals(cmd)) {
opts.addOption(FORCEMANUAL, false,
"force manual control even if auto-failover is enabled");

View File

@ -216,11 +216,16 @@ public void testMutativeOperationsWithAutoHaEnabled() throws Exception {
assertTrue(errOutput.contains("Refusing to manually manage"));
assertEquals(-1, runTool("-transitionToStandby", "nn1"));
assertTrue(errOutput.contains("Refusing to manually manage"));
assertEquals(-1, runTool("-transitionToObserver", "nn1"));
assertTrue(errOutput.contains("Refusing to manually manage"));
Mockito.verify(mockProtocol, Mockito.never())
.transitionToActive(anyReqInfo());
Mockito.verify(mockProtocol, Mockito.never())
.transitionToStandby(anyReqInfo());
.transitionToStandby(anyReqInfo());
Mockito.verify(mockProtocol, Mockito.never())
.transitionToObserver(anyReqInfo());
// Force flag should bypass the check and change the request source
// for the RPC
@ -228,12 +233,16 @@ public void testMutativeOperationsWithAutoHaEnabled() throws Exception {
assertEquals(0, runTool("-transitionToActive", "-forcemanual", "nn1"));
setupConfirmationOnSystemIn();
assertEquals(0, runTool("-transitionToStandby", "-forcemanual", "nn1"));
setupConfirmationOnSystemIn();
assertEquals(0, runTool("-transitionToObserver", "-forcemanual", "nn1"));
Mockito.verify(mockProtocol, Mockito.times(1)).transitionToActive(
reqInfoCaptor.capture());
Mockito.verify(mockProtocol, Mockito.times(1)).transitionToStandby(
reqInfoCaptor.capture());
Mockito.verify(mockProtocol, Mockito.times(1)).transitionToObserver(
reqInfoCaptor.capture());
// All of the RPCs should have had the "force" source
for (StateChangeRequestInfo ri : reqInfoCaptor.getAllValues()) {
assertEquals(RequestSource.REQUEST_BY_USER_FORCED, ri.getSource());