Apache – Hadoop – HBase – Script – bin/start-hbase.sh

Apache – Hadoop – HBase – Script – bin/start-hbase.sh

Review bin/start-hbase.sh



# Modelled after $HADOOP_HOME/bin/start-hbase.sh.

# Start hadoop hbase daemons.
# Run this on master node.
usage="Usage: start-hbase.sh"

bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd`

. "$bin"/hbase-config.sh

# start hbase daemons
errCode=$?
if [ $errCode -ne 0 ]
then
  exit $errCode
fi

# HBASE-6504 - only take the first line of the output in case verbose gc is on
distMode=`$bin/hbase --config "$HBASE_CONF_DIR" org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed | head -n 1`

if [ "$distMode" == 'false' ]
then
  "$bin"/hbase-daemon.sh start master
else
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" start zookeeper
  "$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" start master
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" 
    --hosts "${HBASE_REGIONSERVERS}" start regionserver
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" 
    --hosts "${HBASE_BACKUP_MASTERS}" start master-backup
fi

The first few lines:


bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd` 

… captures the full path name to the script.

Let us see how it does so:

"${BASH_SOURCE-$0}"
bin=`dirname "${BASH_SOURCE-$0}"`
  • The dirname function says give me the directory portion – It strips off the script file name, while leaving in place its directory name
  • Concise information available @ http://linux.die.net/man/1/dirname
bin=`cd "$bin">/dev/null; pwd` 
  • cd <folder> –> Change current folder to script’s folder
  • /dev/null –> do not display any messages
  • pwd –> display post cd current folder

And, I thought that was it.  But, after reading a very good web posting by Chris Home – “Which directory is that bash script in?” @ http://www.electrictoolbox.com/bash-script-directory/ I am thinking a bit otherwise.

Here is Chris Home’s posting:



#!/bin/bash
DIRECTORY=$(cd `dirname $0` && pwd)
echo $DIRECTORY

Why do I like it:

  • It cleverly uses both the new and old style command substitution
  • The old style being the use of the inner`
  • And, the new style using the enclosing $

A bit off-topic there are other good discussion items:

The next code segment is:

. "$bin"/hbase-config.sh

 

  • With all the earlier struggles of understanding variable substitution, this is a bit easier
  • It seems to say use $bin variable we captured earlier and invoke the hbase-config.sh script
  • As the name indicates hbase-config.h handles the underlying plumbing for initiating the HBase Runtime

The next bit of code is good in that it handles any residual errors that we might have encountered while processing the hbase-config.sh:



# start hbase daemons
errCode=$?
if [ $errCode -ne 0 ]
then
exit $errCode
fi

  • Though not Google friendly the $? seems to be a global variable that serves as a keepsake for last error code.  
  • In this case, the error code is numeric and not a message
  • The result of the error code is kept in errCode
  • With that out of the way, the rest of the code block gains familiarity
  • It is a basic if error code is not equal (-ne) to 0, then exit script returning the error code
  • In essence, the if/-ne operator / then / exit  fi are the familiar get out of here upon finding errors
# HBASE-6504 - only take the first line of the output in case verbose gc is on
distMode=`$bin/hbase --config "$HBASE_CONF_DIR" org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed | head -n 1`

A quick breakdown of:


distMode=`$bin/hbase --config "$HBASE_CONF_DIR" org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed

$HBASE_CONF_DIR

  • The code above invokes bin/HBASE passing on the configuration element $HBASE_CONF_DIR
  • Keep in mind that by default HBASE_CONF_DIR is defined implicitly as <HBASE_HOME>/conf.
  • And, that HBASE_HOME is defined in the service account’s ~/.bashrc
  • If you will like to define an alternate location for HBASE_CONF_DIR please do so by modifying ./bin/hbase-daemon.sh

org.apache.hbase.util.HBaseConfTool

  • Also, passes in org.apache.hbase.util.HBaseConfTool — the class name for HBase Configuration Tool

hbase.cluster.distributed

  • And, hbase.cluster.distributed
  • hbase.cluster.distributed is defined in conf/hbase-site.xml
  • In our case, we define distributed as “Y”

head -n 1

 | head -n 1


  • Just the topmost output statement

Contents of conf/hbase-site.xml


    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    <property>     

In summary, the line of code:

  • invokes bin/hbase and indicates that we are querying for a configuration item
  • That item being hbase.cluster.distributed
  • And, we will like to know whether it is true or false
  • The result of our inquiry is saved in variable distMode

Based on Distribution Mode, Invokes HBASE Components



if [ "$distMode" == 'false' ]
then
  "$bin"/hbase-daemon.sh start master
else
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" start zookeeper
  "$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" start master
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" 
    --hosts "${HBASE_REGIONSERVERS}" start regionserver
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" 
    --hosts "${HBASE_BACKUP_MASTERS}" start master-backup
fi

  • If we are not in distribution mode, then invoke bin/hbase-daemon.sh and start master
  • If in distribution mode, then invoke bin/hbase-daemon.sh and start zookeeper
  • If in distribution mode, then invoke bin/hbase-daemon.sh and start master
  • If in distribution mode, then invoke bin/hbase-daemon.sh and start regionserver
  • If in distribution mode, then invoke bin/hbase-daemon.sh and start master-backup

 

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s