From 45d6834d4cd995e0ea24470a828e68c6366497a7 Mon Sep 17 00:00:00 2001 From: Chao Sun Date: Sat, 24 Nov 2018 13:55:43 -0800 Subject: [PATCH] HDFS-14067. [SBN read] Allow manual failover between standby and observer. Contributed by Chao Sun. --- .../src/main/java/org/apache/hadoop/ha/HAAdmin.java | 1 + .../apache/hadoop/hdfs/tools/TestDFSHAAdmin.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java index 59e20d75bc1..426b68e0bb5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java @@ -476,6 +476,7 @@ public abstract class HAAdmin extends Configured implements Tool { // 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"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java index dda6f6c2489..db827bf0c38 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java @@ -216,11 +216,16 @@ public class TestDFSHAAdmin { 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 class TestDFSHAAdmin { 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());