diff options
author | Bharat Viswanadham <bharat@apache.org> | 2018-05-23 10:15:40 -0700 |
---|---|---|
committer | Bharat Viswanadham <bharat@apache.org> | 2018-05-23 10:15:40 -0700 |
commit | bc6d9d4c796d3c9d27dbbe3266031bf2adecde4f (patch) | |
tree | 9878515c33322c50cd8bcba527a09ef30783af53 /hadoop-hdfs-project/hadoop-hdfs/src/main | |
parent | 699a6918aca2b57ae9ad0bff2c3aaf5a776da614 (diff) |
HDFS-13589: Add dfsAdmin command to query if upgrade is finalized. Contributed by Hanisha Koneru
Diffstat (limited to 'hadoop-hdfs-project/hadoop-hdfs/src/main')
3 files changed, 120 insertions, 0 deletions
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java index d68669f2b0..ac46d5291e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java @@ -157,6 +157,8 @@ import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.GetSto import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.GetStoragePolicyResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.IsFileClosedRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.IsFileClosedResponseProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.UpgradeStatusRequestProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.UpgradeStatusResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListCacheDirectivesRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListCacheDirectivesResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListCachePoolsRequestProto; @@ -900,6 +902,21 @@ public class ClientNamenodeProtocolServerSideTranslatorPB implements } @Override + public UpgradeStatusResponseProto upgradeStatus( + RpcController controller, UpgradeStatusRequestProto req) + throws ServiceException { + try { + final boolean isUpgradeFinalized = server.upgradeStatus(); + UpgradeStatusResponseProto.Builder b = + UpgradeStatusResponseProto.newBuilder(); + b.setUpgradeFinalized(isUpgradeFinalized); + return b.build(); + } catch (IOException e) { + throw new ServiceException(e); + } + } + + @Override public RollingUpgradeResponseProto rollingUpgrade(RpcController controller, RollingUpgradeRequestProto req) throws ServiceException { try { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index 1b7a63650d..c5b9d5a053 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -1322,6 +1322,12 @@ public class NameNodeRpcServer implements NamenodeProtocols { } @Override // ClientProtocol + public boolean upgradeStatus() throws IOException { + checkNNStartup(); + return namesystem.isUpgradeFinalized(); + } + + @Override // ClientProtocol public RollingUpgradeInfo rollingUpgrade(RollingUpgradeAction action) throws IOException { checkNNStartup(); LOG.info("rollingUpgrade " + action); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java index 023fea9608..f793557218 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java @@ -78,6 +78,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; +import org.apache.hadoop.hdfs.protocol.HdfsConstants.UpgradeAction; import org.apache.hadoop.hdfs.protocol.OpenFileEntry; import org.apache.hadoop.hdfs.protocol.OpenFilesIterator; import org.apache.hadoop.hdfs.protocol.ReconfigurationProtocol; @@ -443,6 +444,7 @@ public class DFSAdmin extends FsShell { "\t[" + ClearSpaceQuotaCommand.USAGE +"]\n" + "\t[-finalizeUpgrade]\n" + "\t[" + RollingUpgradeCommand.USAGE +"]\n" + + "\t[-upgrade <query | finalize>]\n" + "\t[-refreshServiceAcl]\n" + "\t[-refreshUserToGroupsMappings]\n" + "\t[-refreshSuperUserGroupsConfiguration]\n" + @@ -1147,6 +1149,11 @@ public class DFSAdmin extends FsShell { "\t\tfollowed by Namenode doing the same.\n" + "\t\tThis completes the upgrade process.\n"; + String upgrade = "-upgrade <query | finalize>:\n" + + " query: query the current upgrade status.\n" + + " finalize: finalize the upgrade of HDFS (equivalent to " + + "-finalizeUpgrade."; + String metaSave = "-metasave <filename>: \tSave Namenode's primary data structures\n" + "\t\tto <filename> in the directory specified by hadoop.log.dir property.\n" + "\t\t<filename> is overwritten if it exists.\n" + @@ -1278,6 +1285,8 @@ public class DFSAdmin extends FsShell { System.out.println(finalizeUpgrade); } else if (RollingUpgradeCommand.matches("-"+cmd)) { System.out.println(RollingUpgradeCommand.DESCRIPTION); + } else if ("upgrade".equals(cmd)) { + System.out.println(upgrade); } else if ("metasave".equals(cmd)) { System.out.println(metaSave); } else if (SetQuotaCommand.matches("-"+cmd)) { @@ -1338,6 +1347,7 @@ public class DFSAdmin extends FsShell { System.out.println(refreshNodes); System.out.println(finalizeUpgrade); System.out.println(RollingUpgradeCommand.DESCRIPTION); + System.out.println(upgrade); System.out.println(metaSave); System.out.println(SetQuotaCommand.DESCRIPTION); System.out.println(ClearQuotaCommand.DESCRIPTION); @@ -1417,6 +1427,83 @@ public class DFSAdmin extends FsShell { } /** + * Command to get the upgrade status of each namenode in the nameservice. + * Usage: hdfs dfsadmin -upgrade query + * @exception IOException + */ + public int getUpgradeStatus() throws IOException { + DistributedFileSystem dfs = getDFS(); + + Configuration dfsConf = dfs.getConf(); + URI dfsUri = dfs.getUri(); + + boolean isHaAndLogicalUri = HAUtilClient.isLogicalUri(dfsConf, dfsUri); + if (isHaAndLogicalUri) { + // In the case of HA and logical URI, run upgrade query for all + // NNs in this nameservice. + String nsId = dfsUri.getHost(); + List<ProxyAndInfo<ClientProtocol>> proxies = + HAUtil.getProxiesForAllNameNodesInNameservice(dfsConf, + nsId, ClientProtocol.class); + List<IOException> exceptions = new ArrayList<>(); + for (ProxyAndInfo<ClientProtocol> proxy : proxies) { + try { + boolean upgradeFinalized = proxy.getProxy().upgradeStatus(); + if (upgradeFinalized) { + System.out.println("Upgrade finalized for " + proxy.getAddress()); + } else { + System.out.println("Upgrade not finalized for " + + proxy.getAddress()); + } + } catch (IOException ioe){ + System.err.println("Getting upgrade status failed for " + + proxy.getAddress()); + exceptions.add(ioe); + } + } + if (!exceptions.isEmpty()){ + throw MultipleIOException.createIOException(exceptions); + } + } else { + if (dfs.upgradeStatus()) { + System.out.println("Upgrade finalized"); + } else { + System.out.println("Upgrade not finalized"); + } + } + + return 0; + } + + /** + * Upgrade command to get the status of upgrade or ask NameNode to finalize + * the previously performed upgrade. + * Usage: hdfs dfsadmin -upgrade [query | finalize] + * @exception IOException + */ + public int upgrade(String arg) throws IOException { + UpgradeAction action; + if ("query".equalsIgnoreCase(arg)) { + action = UpgradeAction.QUERY; + } else if ("finalize".equalsIgnoreCase(arg)) { + action = UpgradeAction.FINALIZE; + } else { + printUsage("-upgrade"); + return -1; + } + + switch (action) { + case QUERY: + return getUpgradeStatus(); + case FINALIZE: + return finalizeUpgrade(); + default: + printUsage("-upgrade"); + return -1; + } + } + + /** * Dumps DFS data structures into specified file. * Usage: hdfs dfsadmin -metasave filename * @param argv List of of command line parameters. @@ -1997,6 +2084,9 @@ public class DFSAdmin extends FsShell { } else if (RollingUpgradeCommand.matches(cmd)) { System.err.println("Usage: hdfs dfsadmin" + " [" + RollingUpgradeCommand.USAGE+"]"); + } else if ("-upgrade".equals(cmd)) { + System.err.println("Usage: hdfs dfsadmin" + + " [-upgrade query | finalize]"); } else if ("-metasave".equals(cmd)) { System.err.println("Usage: hdfs dfsadmin" + " [-metasave filename]"); @@ -2146,6 +2236,11 @@ public class DFSAdmin extends FsShell { printUsage(cmd); return exitCode; } + } else if ("-upgrade".equals(cmd)) { + if (argv.length != 2) { + printUsage(cmd); + return exitCode; + } } else if ("-metasave".equals(cmd)) { if (argv.length != 2) { printUsage(cmd); @@ -2263,6 +2358,8 @@ public class DFSAdmin extends FsShell { exitCode = finalizeUpgrade(); } else if (RollingUpgradeCommand.matches(cmd)) { exitCode = RollingUpgradeCommand.run(getDFS(), argv, i); + } else if ("-upgrade".equals(cmd)) { + exitCode = upgrade(argv[i]); } else if ("-metasave".equals(cmd)) { exitCode = metaSave(argv, i); } else if (ClearQuotaCommand.matches(cmd)) { |