Repository: ambari Updated Branches: refs/heads/branch-2.2 8fd439789 -> 0c270f9d1 refs/heads/trunk 1be0e6c8f -> 356cb9432
AMBARI-15789. If initial NN start runs into problem while communicating with JN, restart does not work (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/356cb943 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/356cb943 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/356cb943 Branch: refs/heads/trunk Commit: 356cb943221f6bfe75d6eb1cbfb3376ef35f85c7 Parents: 1be0e6c Author: Andrew Onishuk <[email protected]> Authored: Sat Apr 9 16:07:06 2016 +0300 Committer: Andrew Onishuk <[email protected]> Committed: Sat Apr 9 16:07:06 2016 +0300 ---------------------------------------------------------------------- .../2.1.0.2.0/package/scripts/hdfs_namenode.py | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/356cb943/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py index 70e27a5..8b6c924 100644 --- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py +++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py @@ -323,11 +323,20 @@ def format_namenode(force=None): bin_dir=params.hadoop_bin_dir, conf_dir=hadoop_conf_dir) else: + nn_name_dirs = params.dfs_name_dir.split(',') if not is_namenode_formatted(params): - Execute(format("yes Y | hdfs --config {hadoop_conf_dir} namenode -format"), - user = params.hdfs_user, - path = [params.hadoop_bin_dir] - ) + try: + Execute(format("yes Y | hdfs --config {hadoop_conf_dir} namenode -format"), + user = params.hdfs_user, + path = [params.hadoop_bin_dir] + ) + except Fail: + # We need to clean-up mark directories, so we can re-run format next time. + for nn_name_dir in nn_name_dirs: + Execute(format("rm -rf {nn_name_dir}/*"), + user = params.hdfs_user, + ) + raise for m_dir in mark_dir: Directory(m_dir, create_parents = True @@ -342,7 +351,7 @@ def is_namenode_formatted(params): for mark_dir in mark_dirs: if os.path.isdir(mark_dir): marked = True - print format("{mark_dir} exists. Namenode DFS already formatted") + Logger.info(format("{mark_dir} exists. Namenode DFS already formatted")) # Ensure that all mark dirs created for all name directories if marked: @@ -379,9 +388,9 @@ def is_namenode_formatted(params): Execute(format("ls {name_dir} | wc -l | grep -q ^0$"), ) marked = False - except Exception: + except Fail: marked = True - print format("ERROR: Namenode directory(s) is non empty. Will not format the namenode. List of non-empty namenode dirs {nn_name_dirs}") + Logger.info(format("ERROR: Namenode directory(s) is non empty. Will not format the namenode. List of non-empty namenode dirs {nn_name_dirs}")) break return marked
