From f8bbc92358209498f219a14a4eea99c8563c22e8 Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Fri, 13 Jan 2023 15:29:20 +0100 Subject: [PATCH] PR feedback --- .../actions/DumpHdfsClusterStatusAction.java | 2 +- .../actions/RestartActiveNameNodeAction.java | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/DumpHdfsClusterStatusAction.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/DumpHdfsClusterStatusAction.java index 88c2aea65058..932590f84b23 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/DumpHdfsClusterStatusAction.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/DumpHdfsClusterStatusAction.java @@ -73,6 +73,6 @@ public void perform() throws Exception { } // TODO: add more on NN, JNs, and ZK. // TODO: Print how long process has been up. - LOG.info(sb.toString()); + getLogger().info(sb.toString()); } } diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveNameNodeAction.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveNameNodeAction.java index 178a4ab067e6..13e67b8e7eed 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveNameNodeAction.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveNameNodeAction.java @@ -17,7 +17,9 @@ */ package org.apache.hadoop.hbase.chaos.actions; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper; @@ -78,26 +80,30 @@ public void perform() throws Exception { final String hadoopHAZkNodePath = ZNodePaths.joinZNode( (hadoopHAZkNode != null && hadoopHAZkNode.equals("/")) ? "" : hadoopHAZkNode, nameServiceID); - final List subChildren = ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath); + final List subChildren = + Optional.ofNullable(ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath)) + .orElse(Collections.emptyList()); 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 (!eachEntry.contains(ACTIVE_NN_LOCK_NAME)) { + continue; } + 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 { - getLogger().info("Found Active NameNode host: {}", activeNamenode); - final ServerName activeNNHost = ServerName.valueOf(activeNamenode, activeNamenodePort, -1L); - getLogger().info("Restarting Active NameNode: {}", activeNamenode); - restartNameNode(activeNNHost, this.sleepTime); + getLogger().info("No active Name node found in zookeeper under '{}'", hadoopHAZkNode); + return; } + + getLogger().info("Found Active NameNode host: {}", activeNamenode); + final ServerName activeNNHost = ServerName.valueOf(activeNamenode, activeNamenodePort, -1L); + getLogger().info("Restarting Active NameNode: {}", activeNamenode); + restartNameNode(activeNNHost, this.sleepTime); } }