[hadoop] 04/50: HDFS-13286. [SBN read] Add haadmin commands to transition between standby and observer. Contributed by Chao Sun.
This is an automated email from the ASF dual-hosted git repository. cliang pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/hadoop.git commit 849e1f018e4e315a5475bed20b9a14a0437c84cf Author: Erik Krogen AuthorDate: Fri May 4 12:22:12 2018 -0700 HDFS-13286. [SBN read] Add haadmin commands to transition between standby and observer. Contributed by Chao Sun. --- .../org/apache/hadoop/ha/FailoverController.java | 2 +- .../main/java/org/apache/hadoop/ha/HAAdmin.java| 42 + .../org/apache/hadoop/ha/HAServiceProtocol.java| 18 + .../apache/hadoop/ha/HAServiceProtocolHelper.java | 9 + .../java/org/apache/hadoop/ha/HAServiceTarget.java | 7 .../HAServiceProtocolClientSideTranslatorPB.java | 16 .../HAServiceProtocolServerSideTranslatorPB.java | 20 ++ .../src/main/proto/HAServiceProtocol.proto | 20 ++ .../java/org/apache/hadoop/ha/DummyHAService.java | 18 - .../java/org/apache/hadoop/ha/MiniZKFCCluster.java | 4 ++ .../resolver/FederationNamenodeServiceState.java | 3 ++ .../apache/hadoop/hdfs/protocolPB/PBHelper.java| 4 ++ .../hdfs/server/datanode/BPServiceActor.java | 2 +- .../hadoop/hdfs/server/namenode/FSNamesystem.java | 3 +- .../hadoop/hdfs/server/namenode/NameNode.java | 27 - .../hdfs/server/namenode/NameNodeRpcServer.java| 8 .../hdfs/server/namenode/ha/StandbyState.java | 12 +++--- .../hadoop/hdfs/tools/NNHAServiceTarget.java | 5 +++ .../hadoop-hdfs/src/main/proto/HdfsServer.proto| 1 + .../apache/hadoop/hdfs/tools/TestDFSHAAdmin.java | 6 +++ .../hdfs/tools/TestDFSHAAdminMiniCluster.java | 44 ++ .../yarn/server/resourcemanager/AdminService.java | 7 22 files changed, 258 insertions(+), 20 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java index b86ae29..4fc52d5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java @@ -129,7 +129,7 @@ public class FailoverController { if (!toSvcStatus.getState().equals(HAServiceState.STANDBY)) { throw new FailoverFailedException( - "Can't failover to an active service"); + "Can't failover to an " + toSvcStatus.getState() + " service"); } if (!toSvcStatus.isReadyToBecomeActive()) { 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 9b7d7ba..61700f9 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 @@ -72,6 +72,9 @@ public abstract class HAAdmin extends Configured implements Tool { new UsageInfo("[--"+FORCEACTIVE+"] ", "Transitions the service into Active state")) .put("-transitionToStandby", new UsageInfo("", "Transitions the service into Standby state")) + .put("-transitionToObserver", + new UsageInfo("", + "Transitions the service into Observer state")) .put("-failover", new UsageInfo("[--"+FORCEFENCE+"] [--"+FORCEACTIVE+"] ", "Failover from the first service to the second.\n" + @@ -221,6 +224,28 @@ public abstract class HAAdmin extends Configured implements Tool { HAServiceProtocolHelper.transitionToStandby(proto, createReqInfo()); return 0; } + + private int transitionToObserver(final CommandLine cmd) + throws IOException, ServiceFailedException { +String[] argv = cmd.getArgs(); +if (argv.length != 1) { + errOut.println("transitionToObserver: incorrect number of arguments"); + printUsage(errOut, "-transitionToObserver"); + return -1; +} + +HAServiceTarget target = resolveTarget(argv[0]); +if (!checkSupportObserver(target)) { + return -1; +} +if (!checkManualStateManagementOK(target)) { + return -1; +} +HAServiceProtocol proto = target.getProxy(getConf(), 0); +HAServiceProtocolHelper.transitionToObserver(proto, createReqInfo()); +return 0; + } + /** * Ensure that we are allowed to manually manage the HA state of the target * service. If automatic failover is configured, then the automatic @@ -249,6 +274,21 @@ public abstract class HAAdmin extends Configured implements Tool { return true; } + /** + * Check if the target supports the Observer state. + * @param target the target to check + * @return true if the target support Observer state, false otherwise. + */ + private boolean
[hadoop] 04/50: HDFS-13286. [SBN read] Add haadmin commands to transition between standby and observer. Contributed by Chao Sun.
This is an automated email from the ASF dual-hosted git repository. cliang pushed a commit to branch branch-3.2 in repository https://gitbox.apache.org/repos/asf/hadoop.git commit 49d7bb6a92026ab34eb1a9f06c059b0f98c2698b Author: Erik Krogen AuthorDate: Fri May 4 12:22:12 2018 -0700 HDFS-13286. [SBN read] Add haadmin commands to transition between standby and observer. Contributed by Chao Sun. --- .../org/apache/hadoop/ha/FailoverController.java | 2 +- .../main/java/org/apache/hadoop/ha/HAAdmin.java| 42 + .../org/apache/hadoop/ha/HAServiceProtocol.java| 18 + .../apache/hadoop/ha/HAServiceProtocolHelper.java | 9 + .../java/org/apache/hadoop/ha/HAServiceTarget.java | 7 .../HAServiceProtocolClientSideTranslatorPB.java | 16 .../HAServiceProtocolServerSideTranslatorPB.java | 20 ++ .../src/main/proto/HAServiceProtocol.proto | 20 ++ .../java/org/apache/hadoop/ha/DummyHAService.java | 18 - .../java/org/apache/hadoop/ha/MiniZKFCCluster.java | 4 ++ .../resolver/FederationNamenodeServiceState.java | 3 ++ .../apache/hadoop/hdfs/protocolPB/PBHelper.java| 4 ++ .../hdfs/server/datanode/BPServiceActor.java | 2 +- .../hadoop/hdfs/server/namenode/FSNamesystem.java | 3 +- .../hadoop/hdfs/server/namenode/NameNode.java | 27 - .../hdfs/server/namenode/NameNodeRpcServer.java| 8 .../hdfs/server/namenode/ha/StandbyState.java | 12 +++--- .../hadoop/hdfs/tools/NNHAServiceTarget.java | 5 +++ .../hadoop-hdfs/src/main/proto/HdfsServer.proto| 1 + .../apache/hadoop/hdfs/tools/TestDFSHAAdmin.java | 6 +++ .../hdfs/tools/TestDFSHAAdminMiniCluster.java | 44 ++ .../yarn/server/resourcemanager/AdminService.java | 7 22 files changed, 258 insertions(+), 20 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java index b86ae29..4fc52d5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java @@ -129,7 +129,7 @@ public class FailoverController { if (!toSvcStatus.getState().equals(HAServiceState.STANDBY)) { throw new FailoverFailedException( - "Can't failover to an active service"); + "Can't failover to an " + toSvcStatus.getState() + " service"); } if (!toSvcStatus.isReadyToBecomeActive()) { 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 e955979..59e20d7 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 @@ -72,6 +72,9 @@ public abstract class HAAdmin extends Configured implements Tool { new UsageInfo("[--"+FORCEACTIVE+"] ", "Transitions the service into Active state")) .put("-transitionToStandby", new UsageInfo("", "Transitions the service into Standby state")) + .put("-transitionToObserver", + new UsageInfo("", + "Transitions the service into Observer state")) .put("-failover", new UsageInfo("[--"+FORCEFENCE+"] [--"+FORCEACTIVE+"] ", "Failover from the first service to the second.\n" + @@ -221,6 +224,28 @@ public abstract class HAAdmin extends Configured implements Tool { HAServiceProtocolHelper.transitionToStandby(proto, createReqInfo()); return 0; } + + private int transitionToObserver(final CommandLine cmd) + throws IOException, ServiceFailedException { +String[] argv = cmd.getArgs(); +if (argv.length != 1) { + errOut.println("transitionToObserver: incorrect number of arguments"); + printUsage(errOut, "-transitionToObserver"); + return -1; +} + +HAServiceTarget target = resolveTarget(argv[0]); +if (!checkSupportObserver(target)) { + return -1; +} +if (!checkManualStateManagementOK(target)) { + return -1; +} +HAServiceProtocol proto = target.getProxy(getConf(), 0); +HAServiceProtocolHelper.transitionToObserver(proto, createReqInfo()); +return 0; + } + /** * Ensure that we are allowed to manually manage the HA state of the target * service. If automatic failover is configured, then the automatic @@ -249,6 +274,21 @@ public abstract class HAAdmin extends Configured implements Tool { return true; } + /** + * Check if the target supports the Observer state. + * @param target the target to check + * @return true if the target support Observer state, false otherwise. + */ + private boolean