From 845a34e88040e6ca576358d7f644ce05fdb508dc Mon Sep 17 00:00:00 2001 From: Kartik Bhatia Date: Tue, 20 Aug 2019 14:36:33 +0530 Subject: [PATCH] new: usr: HADTWO-1973: Namenode out of safe mode (#18) Provided a function that attempts to bring out namenode out of safe mode --- hadoop/util.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hadoop/util.sh b/hadoop/util.sh index 67ffb16..10d7be6 100644 --- a/hadoop/util.sh +++ b/hadoop/util.sh @@ -73,3 +73,37 @@ function use_java8() { restart_worker_services fi } + +# Wait until namenode is out of safe mode. Takes 2 optional params +# first : Number of attempts function will make to get namenode out of safemode. Default is 50 +# second : Number of seconds each attempt will sleep for waiting for namenode to come out of sleep mode. Default is 5sec +function wait_until_namenode_out_of_safe() { + n=0 + attempts=${1:-50} + sleep_sec=${2:-5} + + nn_out_of_safe_mode=0 + until [ $n -ge $attempts ] + do + n=$[$n+1] + safe_mode_stat=`hadoop dfsadmin -safemode get|awk '{print $4}'` + if [[ $safe_mode_stat = "ON" ]]; then + hdfs hadoop dfsadmin -safemode leave + echo "Attempt $n/$attempts" + sleep $sleep_sec + else + echo "NN is out of safemode..." + nn_out_of_safe_mode=1 + break + fi + done + if [[ $nn_out_of_safe_mode -eq 0 ]]; then + safe_mode_stat=`hadoop dfsadmin -safemode get|awk '{print $4}'` + if [[ $safe_mode_stat = "ON" ]]; then + echo "Node still in safe mode after all attempts exhausted!" + else + echo "NN is out of safemode..." + fi + fi + +}