From b6282f55080ae1666b2fbf4c55c5e577764a701d Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 19 Jul 2010 22:59:51 +0000 Subject: [PATCH] HBASE-1511 Pseudo distributed mode in LocalHBaseCluster git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@965672 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 + bin/local-master-backup.sh | 35 +++++++++ bin/local-regionservers.sh | 35 +++++++++ ...hbase-site.xml.psuedo-distributed.template | 77 +++++++++++++++++++ .../apache/hadoop/hbase/master/HMaster.java | 50 ++++++++---- .../hbase/regionserver/HRegionServer.java | 50 ++++++++---- src/site/site.xml | 1 + src/site/xdoc/pseudo-distributed.xml | 77 +++++++++++++++++++ 8 files changed, 295 insertions(+), 33 deletions(-) create mode 100644 bin/local-master-backup.sh create mode 100644 bin/local-regionservers.sh create mode 100644 conf/hbase-site.xml.psuedo-distributed.template create mode 100644 src/site/xdoc/pseudo-distributed.xml diff --git a/CHANGES.txt b/CHANGES.txt index a4d6d8fcb8d..46e2a6afe23 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -440,6 +440,9 @@ Release 0.21.0 - Unreleased edits ordered by sequenceid HBASE-2843 Readd bloomfilter test over zealously removed by HBASE-2625 HBASE-2846 Make rest server be same as thrift and avro servers + HBASE-1511 Pseudo distributed mode in LocalHBaseCluster + (Nicolas Spiegelberg via Stack) + IMPROVEMENTS HBASE-1760 Cleanup TODOs in HTable diff --git a/bin/local-master-backup.sh b/bin/local-master-backup.sh new file mode 100644 index 00000000000..e08a736d909 --- /dev/null +++ b/bin/local-master-backup.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# This is used for starting multiple masters on the same machine. +# run it from hbase-dir/ just like 'bin/hbase' +# Supports up to 10 masters (limitation = overlapping ports) + +bin=`dirname "$0"` +bin=`cd "$bin" >/dev/null && pwd` + +if [ $# -lt 2 ]; then + S=`basename $0` + echo "Usage: $S [start|stop] offset(s)" + echo "" + echo " e.g. $S start 1" + exit +fi + +# sanity check: make sure your master opts don't use ports [i.e. JMX/DBG] +export HBASE_MASTER_OPTS=" " + +run_master () { + DN=$2 + export HBASE_IDENT_STRING="$USER-$DN" + HBASE_MASTER_ARGS="\ + -D hbase.master.port=`expr 60000 + $DN` \ + -D hbase.master.info.port=`expr 60010 + $DN`" + "$bin"/hbase-daemon.sh $1 master $HBASE_MASTER_ARGS +} + +cmd=$1 +shift; + +for i in $* +do + run_master $cmd $i +done diff --git a/bin/local-regionservers.sh b/bin/local-regionservers.sh new file mode 100644 index 00000000000..d36d4da9d43 --- /dev/null +++ b/bin/local-regionservers.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# This is used for starting multiple regionservers on the same machine. +# run it from hbase-dir/ just like 'bin/hbase' +# Supports up to 100 regionservers (limitation = overlapping ports) + +bin=`dirname "$0"` +bin=`cd "$bin" >/dev/null && pwd` + +if [ $# -lt 2 ]; then + S=`basename $0` + echo "Usage: $S [start|stop] offset(s)" + echo "" + echo " e.g. $S start 1 2" + exit +fi + +# sanity check: make sure your regionserver opts don't use ports [i.e. JMX/DBG] +export HBASE_REGIONSERVER_OPTS=" " + +run_regionserver () { + DN=$2 + export HBASE_IDENT_STRING="$USER-$DN" + HBASE_REGIONSERVER_ARGS="\ + -D hbase.regionserver.port=`expr 60200 + $DN` \ + -D hbase.regionserver.info.port=`expr 60300 + $DN`" + "$bin"/hbase-daemon.sh $1 regionserver $HBASE_REGIONSERVER_ARGS +} + +cmd=$1 +shift; + +for i in $* +do + run_regionserver $cmd $i +done diff --git a/conf/hbase-site.xml.psuedo-distributed.template b/conf/hbase-site.xml.psuedo-distributed.template new file mode 100644 index 00000000000..a960eb7b7da --- /dev/null +++ b/conf/hbase-site.xml.psuedo-distributed.template @@ -0,0 +1,77 @@ + + + + + + + + hbase.cluster.distributed + true + For psuedo-distributed, you want to set this to true. + false means that HBase tries to put Master + RegionServers in one process. + Pseudo-distributed = seperate processes/pids + + hbase.regionserver.hlog.replication + 1 + For HBase to offer good data durability, we roll logs if + filesystem replication falls below a certain amount. In psuedo-distributed + mode, you normally only have the local filesystem or 1 HDFS DataNode, so you + don't want to roll logs constantly. + + + hbase.tmp.dir + /tmp/hbase-testing + Temporary directory on the local filesystem. + + + + + + + + diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 83536e10f7e..b5a3b8f15ee 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -37,6 +37,10 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -1199,6 +1203,7 @@ public class HMaster extends Thread implements HMasterInterface, System.err.println(" stop Start cluster shutdown; Master signals RegionServer shutdown"); System.err.println(" where [opts] are:"); System.err.println(" --minServers= Minimum RegionServers needed to host user tables."); + System.err.println(" -D opt= Override HBase configuration settings."); System.exit(0); } @@ -1250,20 +1255,34 @@ public class HMaster extends Thread implements HMasterInterface, protected static void doMain(String [] args, Class masterClass) { - if (args.length < 1) { - printUsageAndExit(); - } Configuration conf = HBaseConfiguration.create(); - // Process command-line args. - for (String cmd: args) { - if (cmd.startsWith("--minServers=")) { + Options opt = new Options(); + opt.addOption("minServers", true, "Minimum RegionServers needed to host user tables"); + opt.addOption("D", true, "Override HBase Configuration Settings"); + try { + CommandLine cmd = new GnuParser().parse(opt, args); + + if (cmd.hasOption("minServers")) { + String val = cmd.getOptionValue("minServers"); conf.setInt("hbase.regions.server.count.min", - Integer.valueOf(cmd.substring(13))); - continue; + Integer.valueOf(val)); + LOG.debug("minServers set to " + val); } - if (cmd.equalsIgnoreCase("start")) { + if (cmd.hasOption("D")) { + for (String confOpt : cmd.getOptionValues("D")) { + String[] kv = confOpt.split("=", 2); + if (kv.length == 2) { + conf.set(kv[0], kv[1]); + LOG.debug("-D configuration override: " + kv[0] + "=" + kv[1]); + } else { + throw new ParseException("-D option format invalid: " + confOpt); + } + } + } + + if (cmd.getArgList().contains("start")) { try { // Print out vm stats before starting up. RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); @@ -1312,10 +1331,7 @@ public class HMaster extends Thread implements HMasterInterface, LOG.error("Failed to start master", t); System.exit(-1); } - break; - } - - if (cmd.equalsIgnoreCase("stop")) { + } else if (cmd.getArgList().contains("stop")) { HBaseAdmin adm = null; try { adm = new HBaseAdmin(conf); @@ -1329,10 +1345,12 @@ public class HMaster extends Thread implements HMasterInterface, LOG.error("Failed to stop master", t); System.exit(-1); } - break; + } else { + throw new ParseException("Unknown argument(s): " + + org.apache.commons.lang.StringUtils.join(cmd.getArgs(), " ")); } - - // Print out usage if we get to here. + } catch (ParseException e) { + LOG.error("Could not parse: ", e); printUsageAndExit(); } } diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index b5ad9d9d873..e6b365ea70b 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -50,6 +50,10 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -2433,7 +2437,7 @@ public class HRegionServer implements HRegionInterface, if (message != null) { System.err.println(message); } - System.err.println("Usage: java org.apache.hbase.HRegionServer start|stop"); + System.err.println("Usage: java org.apache.hbase.HRegionServer start|stop [-D ]"); System.exit(0); } @@ -2467,15 +2471,26 @@ public class HRegionServer implements HRegionInterface, */ protected static void doMain(final String [] args, final Class regionServerClass) { - if (args.length < 1) { - printUsageAndExit(); - } Configuration conf = HBaseConfiguration.create(); - // Process command-line args. TODO: Better cmd-line processing - // (but hopefully something not as painful as cli options). - for (String cmd: args) { - if (cmd.equals("start")) { + Options opt = new Options(); + opt.addOption("D", true, "Override HBase Configuration Settings"); + try { + CommandLine cmd = new GnuParser().parse(opt, args); + + if (cmd.hasOption("D")) { + for (String confOpt : cmd.getOptionValues("D")) { + String[] kv = confOpt.split("=", 2); + if (kv.length == 2) { + conf.set(kv[0], kv[1]); + LOG.debug("-D configuration override: " + kv[0] + "=" + kv[1]); + } else { + throw new ParseException("-D option format invalid: " + confOpt); + } + } + } + + if (cmd.getArgList().contains("start")) { try { // If 'local', don't start a region server here. Defer to // LocalHBaseCluster. It manages 'local' clusters. @@ -2493,17 +2508,18 @@ public class HRegionServer implements HRegionInterface, } catch (Throwable t) { LOG.error( "Can not start region server because "+ StringUtils.stringifyException(t) ); + System.exit(-1); } - break; + } else if (cmd.getArgList().contains("stop")) { + throw new ParseException("To shutdown the regionserver run " + + "bin/hbase-daemon.sh stop regionserver or send a kill signal to" + + "the regionserver pid"); + } else { + throw new ParseException("Unknown argument(s): " + + org.apache.commons.lang.StringUtils.join(cmd.getArgs(), " ")); } - - if (cmd.equals("stop")) { - printUsageAndExit("To shutdown the regionserver run " + - "bin/hbase-daemon.sh stop regionserver or send a kill signal to" + - "the regionserver pid"); - } - - // Print out usage if we get to here. + } catch (ParseException e) { + LOG.error("Could not parse", e); printUsageAndExit(); } } diff --git a/src/site/site.xml b/src/site/site.xml index 7f8ffa098da..716932b6a3c 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -36,6 +36,7 @@ + diff --git a/src/site/xdoc/pseudo-distributed.xml b/src/site/xdoc/pseudo-distributed.xml new file mode 100644 index 00000000000..1b3e5e65141 --- /dev/null +++ b/src/site/xdoc/pseudo-distributed.xml @@ -0,0 +1,77 @@ + + + + + + + + +Running HBase in pseudo-distributed mode + + + + +

This document augments what is described in the HBase 'Getting Started' in the + Distributed Operation: Pseudo- and Fully-distributed modes section. + In particular it describes scripts that allow you start extra masters and regionservers when running in pseudo-distributed mode. +

+ +
  1. Copy the psuedo-distributed suggested configuration file (feel free to take a peek and understand what it's doing) + % cp conf/hbase-site.xml{.psuedo-distributed.template,} +
  2. +
  3. (Optional) Start up Pseudo-distributed HDFS. +
    1. If you do, go to conf/hbase-site.xml. Uncomment the 'hbase.rootdir' property. +
    2. +
    3. Additionally, if you want to test HBase with high data durability enabled, also uncomment the 'dfs.support.append' property. +
    4. +
    +
  4. +
  5. Start up the initial HBase cluster + % bin/start-hbase.sh +
    1. To start up an extra backup master(s) on the same server run + % bin/local-master-backup.sh start 1 + Here the '1' means use ports 60001 & 60011, and this backup master's logfile will be at logs/hbase-${USER}-1-master-${HOSTNAME}.log. + To startup multiple backup masters run % bin/local-master-backup.sh start 2 3 You can start up to 9 backup masters (10 total). +
    2. +
    3. To start up more regionservers + % bin/local-regionservers.sh start 1 + where '1' means use ports 60201 & 60301 and its logfile will be at logs/hbase-${USER}-1-regionserver-${HOSTNAME}.log. + To add 4 more regionservers in addition to the one you just started by running % bin/local-regionservers.sh start 2 3 4 5 + Supports up to 99 extra regionservers (100 total). +
    4. +
    +
  6. +
  7. To stop the cluster +
      +
    1. Assuming you want to stop master backup # 1, run + % cat /tmp/hbase-${USER}-1-master.pid |xargs kill -9 + Note that bin/local-master-backup.sh stop 1 will try to stop the cluster along with the master +
    2. +
    3. To stop an individual regionserver, run + % bin/local-regionservers.sh stop 1 + +
    4. +
    +
  8. +
+ + +
+