You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2023/01/13 11:12:21 UTC

[GitHub] [hbase] Apache9 commented on a diff in pull request #4959: HBASE-27567 Introduce ChaosMonkey Action to print HDFS Cluster status

Apache9 commented on code in PR #4959:
URL: https://github.com/apache/hbase/pull/4959#discussion_r1069259752


##########
hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/DumpHdfsClusterStatusAction.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.chaos.actions;
+
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.util.List;
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.DistributedFileSystem;
+import org.apache.hadoop.hdfs.HAUtil;
+import org.apache.hadoop.hdfs.HAUtilClient;
+import org.apache.hadoop.hdfs.protocol.ClientProtocol;
+import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
+import org.apache.hadoop.hdfs.protocol.HdfsConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DumpHdfsClusterStatusAction extends Action {
+  private static final Logger LOG = LoggerFactory.getLogger(DumpHdfsClusterStatusAction.class);
+  private static final String PREFIX = "\n  ";
+
+  @Override
+  protected Logger getLogger() {
+    return LOG;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    StringBuilder sb = new StringBuilder();
+    try (final DistributedFileSystem dfs = HdfsActionUtils.createDfs(getConf())) {
+      final Configuration dfsConf = dfs.getConf();
+      final URI dfsUri = dfs.getUri();
+      final boolean isHaAndLogicalUri = HAUtilClient.isLogicalUri(dfsConf, dfsUri);
+      sb.append("Cluster status").append('\n');
+      if (isHaAndLogicalUri) {
+        final String nsId = dfsUri.getHost();
+        final List<ClientProtocol> namenodes =
+          HAUtil.getProxiesForAllNameNodesInNameservice(dfsConf, nsId);
+        final boolean atLeastOneActive = HAUtil.isAtLeastOneActive(namenodes);
+        final InetSocketAddress activeAddress = HAUtil.getAddressOfActive(dfs);
+        sb.append("Active NameNode=").append(activeAddress).append(", isAtLeastOneActive=")
+          .append(atLeastOneActive).append('\n');
+      }
+      DatanodeInfo[] dns = dfs.getClient().datanodeReport(HdfsConstants.DatanodeReportType.LIVE);
+      sb.append("Number of live DataNodes: ").append(dns.length);
+      for (DatanodeInfo dni : dns) {
+        sb.append(PREFIX).append("name=").append(dni.getName()).append(", used%=")
+          .append(dni.getDfsUsedPercent()).append(", capacity=")
+          .append(FileUtils.byteCountToDisplaySize(dni.getCapacity()));
+      }
+      sb.append('\n');
+      dns = dfs.getClient().datanodeReport(HdfsConstants.DatanodeReportType.DEAD);
+      sb.append("Number of dead DataNodes: ").append(dns.length);
+      for (DatanodeInfo dni : dns) {
+        sb.append(PREFIX).append(dni.getName()).append("/").append(dni.getNetworkLocation());
+      }
+    }
+    // TODO: add more on NN, JNs, and ZK.
+    // TODO: Print how long process has been up.
+    LOG.info(sb.toString());

Review Comment:
   getLogger().info?



##########
hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveNameNodeAction.java:
##########
@@ -57,39 +57,47 @@ protected Logger getLogger() {
   @Override
   public void perform() throws Exception {
     getLogger().info("Performing action: Restart active namenode");
-    Configuration conf = CommonFSUtils.getRootDir(getConf()).getFileSystem(getConf()).getConf();
-    String nameServiceID = DFSUtil.getNamenodeNameServiceId(conf);
-    if (!HAUtil.isHAEnabled(conf, nameServiceID)) {
-      throw new Exception("HA for namenode is not enabled");
-    }
-    ZKWatcher zkw = null;
-    RecoverableZooKeeper rzk = null;
+
+    final String hadoopHAZkNode;
     String activeNamenode = null;
-    String hadoopHAZkNode = conf.get(ZK_PARENT_ZNODE_KEY, ZK_PARENT_ZNODE_DEFAULT);
-    try {
-      zkw = new ZKWatcher(conf, "get-active-namenode", null);
-      rzk = zkw.getRecoverableZooKeeper();
-      String hadoopHAZkNodePath = ZNodePaths.joinZNode(hadoopHAZkNode, nameServiceID);
-      List<String> subChildern = ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath);
-      for (String eachEntry : subChildern) {
-        if (eachEntry.contains(ACTIVE_NN_LOCK_NAME)) {
-          byte[] data =
-            rzk.getData(ZNodePaths.joinZNode(hadoopHAZkNodePath, ACTIVE_NN_LOCK_NAME), false, null);
-          ActiveNodeInfo proto = ActiveNodeInfo.parseFrom(data);
-          activeNamenode = proto.getHostname();
-        }
+    int activeNamenodePort = -1;
+    try (final DistributedFileSystem dfs = HdfsActionUtils.createDfs(getConf())) {
+      final Configuration conf = dfs.getConf();
+      hadoopHAZkNode = conf.get(ZK_PARENT_ZNODE_KEY, ZK_PARENT_ZNODE_DEFAULT);
+      final String nameServiceID = DFSUtil.getNamenodeNameServiceId(conf);
+
+      if (!HAUtil.isHAEnabled(conf, nameServiceID)) {
+        getLogger().info("HA for HDFS is not enabled; skipping");
+        return;
       }
-    } finally {
-      if (zkw != null) {
-        zkw.close();
+      try (final ZKWatcher zkw = new ZKWatcher(conf, "get-active-namenode", null)) {
+        final RecoverableZooKeeper rzk = zkw.getRecoverableZooKeeper();
+        // If hadoopHAZkNode == '/', pass '' instead because then joinZNode will return '//' as a
+        // prefix
+        // which zk doesn't like as a prefix on the path.
+        final String hadoopHAZkNodePath = ZNodePaths.joinZNode(
+          (hadoopHAZkNode != null && hadoopHAZkNode.equals("/")) ? "" : hadoopHAZkNode,
+          nameServiceID);
+        final List<String> subChildren = ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath);
+        for (final String eachEntry : subChildren) {
+          if (eachEntry.contains(ACTIVE_NN_LOCK_NAME)) {
+            byte[] data = rzk.getData(ZNodePaths.joinZNode(hadoopHAZkNodePath, ACTIVE_NN_LOCK_NAME),
+              false, null);
+            ActiveNodeInfo proto = ActiveNodeInfo.parseFrom(data);
+            activeNamenode = proto.getHostname();
+            activeNamenodePort = proto.getPort();
+          }
+        }
       }
     }
+
     if (activeNamenode == null) {
       throw new Exception("No active Name node found in zookeeper under " + hadoopHAZkNode);
+    } else {

Review Comment:
   Why an else here? Seems not necessary,,,



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org