You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:00:44 UTC
svn commit: r1181348 - in /hbase/branches/0.89: bin/
src/main/java/org/apache/hadoop/hbase/
src/main/java/org/apache/hadoop/hbase/master/
src/main/java/org/apache/hadoop/hbase/zookeeper/
Author: nspiegelberg
Date: Tue Oct 11 02:00:44 2011
New Revision: 1181348
URL: http://svn.apache.org/viewvc?rev=1181348&view=rev
Log:
HBASE-2870: Add Backup CLI Option to HMaster
Summary:
Adds '--backup' option to HMaster. All backup masters will wait until a
primary master has written the /hbase/master znode before poll waiting. This
allows us to have a deterministic primary master while starting up multiple
masters.
Test Plan:
mvn test
DiffCamp Revision: 143527
Reviewed By: kranganathan
CC: davidrecordon, nspiegelberg, achao, kranganathan
Tasks:
#287209: Create secondary master for HBase in deployment and code
Revert Plan:
OK
Added:
hbase/branches/0.89/bin/master-backup.sh (with props)
Modified:
hbase/branches/0.89/bin/hbase-config.sh
hbase/branches/0.89/bin/hbase-daemons.sh
hbase/branches/0.89/bin/local-master-backup.sh
hbase/branches/0.89/bin/start-hbase.sh
hbase/branches/0.89/bin/stop-hbase.sh
hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java
hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
Modified: hbase/branches/0.89/bin/hbase-config.sh
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/hbase-config.sh?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/bin/hbase-config.sh (original)
+++ hbase/branches/0.89/bin/hbase-config.sh Tue Oct 11 02:00:44 2011
@@ -73,6 +73,8 @@ done
HBASE_CONF_DIR="${HBASE_CONF_DIR:-$HBASE_HOME/conf}"
# List of hbase regions servers.
HBASE_REGIONSERVERS="${HBASE_REGIONSERVERS:-$HBASE_CONF_DIR/regionservers}"
+# List of hbase secondary masters.
+HBASE_BACKUP_MASTERS="${HBASE_BACKUP_MASTERS:-$HBASE_CONF_DIR/backup-masters}"
# Source the hbase-env.sh. Will have JAVA_HOME defined.
if [ -f "${HBASE_CONF_DIR}/hbase-env.sh" ]; then
Modified: hbase/branches/0.89/bin/hbase-daemons.sh
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/hbase-daemons.sh?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/bin/hbase-daemons.sh (original)
+++ hbase/branches/0.89/bin/hbase-daemons.sh Tue Oct 11 02:00:44 2011
@@ -45,6 +45,9 @@ case $command in
(zookeeper)
exec "$bin/zookeepers.sh" $args
;;
+ (master-backup)
+ exec "$bin/master-backup.sh" $args
+ ;;
(*)
exec "$bin/regionservers.sh" $args
;;
Modified: hbase/branches/0.89/bin/local-master-backup.sh
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/local-master-backup.sh?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/bin/local-master-backup.sh (original)
+++ hbase/branches/0.89/bin/local-master-backup.sh Tue Oct 11 02:00:44 2011
@@ -21,6 +21,7 @@ run_master () {
DN=$2
export HBASE_IDENT_STRING="$USER-$DN"
HBASE_MASTER_ARGS="\
+ --backup \
-D hbase.master.port=`expr 60000 + $DN` \
-D hbase.master.info.port=`expr 60010 + $DN`"
"$bin"/hbase-daemon.sh $1 master $HBASE_MASTER_ARGS
Added: hbase/branches/0.89/bin/master-backup.sh
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/master-backup.sh?rev=1181348&view=auto
==============================================================================
--- hbase/branches/0.89/bin/master-backup.sh (added)
+++ hbase/branches/0.89/bin/master-backup.sh Tue Oct 11 02:00:44 2011
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+#
+#/**
+# * Copyright 2010 The Apache Software Foundation
+# *
+# * Licensed to the Apache Software Foundation (ASF) under one
+# * or more contributor license agreements. See the NOTICE file
+# * distributed with this work for additional information
+# * regarding copyright ownership. The ASF licenses this file
+# * to you under the Apache License, Version 2.0 (the
+# * "License"); you may not use this file except in compliance
+# * with the License. You may obtain a copy of the License at
+# *
+# * http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+# */
+#
+# Run a shell command on all backup master hosts.
+#
+# Environment Variables
+#
+# HBASE_BACKUP_MASTERS File naming remote hosts.
+# Default is ${HADOOP_CONF_DIR}/backup-masters
+# HADOOP_CONF_DIR Alternate conf dir. Default is ${HADOOP_HOME}/conf.
+# HBASE_CONF_DIR Alternate hbase conf dir. Default is ${HBASE_HOME}/conf.
+# HADOOP_SLAVE_SLEEP Seconds to sleep between spawning remote commands.
+# HADOOP_SSH_OPTS Options passed to ssh when running remote commands.
+#
+# Modelled after $HADOOP_HOME/bin/slaves.sh.
+
+usage="Usage: $0 [--config <hbase-confdir>] command..."
+
+# if no args specified, show usage
+if [ $# -le 0 ]; then
+ echo $usage
+ exit 1
+fi
+
+bin=`dirname "${BASH_SOURCE-$0}"`
+bin=`cd "$bin">/dev/null; pwd`
+
+. "$bin"/hbase-config.sh
+
+# If the master backup file is specified in the command line,
+# then it takes precedence over the definition in
+# hbase-env.sh. Save it here.
+HOSTLIST=$HBASE_BACKUP_MASTERS
+
+if [ "$HOSTLIST" = "" ]; then
+ if [ "$HBASE_BACKUP_MASTERS" = "" ]; then
+ export HOSTLIST="${HBASE_CONF_DIR}/backup-masters"
+ else
+ export HOSTLIST="${HBASE_BACKUP_MASTERS}"
+ fi
+fi
+
+
+args=${@// /\\ }
+args=${args/master-backup/master}
+
+if [ -f $HOSTLIST ]; then
+ for hmaster in `cat "$HOSTLIST"`; do
+ ssh $HBASE_SSH_OPTS $hmaster $"$args --backup" \
+ 2>&1 | sed "s/^/$hmaster: /" &
+ if [ "$HBASE_SLAVE_SLEEP" != "" ]; then
+ sleep $HBASE_SLAVE_SLEEP
+ fi
+ done
+fi
+
+wait
Propchange: hbase/branches/0.89/bin/master-backup.sh
------------------------------------------------------------------------------
svn:executable = *
Modified: hbase/branches/0.89/bin/start-hbase.sh
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/start-hbase.sh?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/bin/start-hbase.sh (original)
+++ hbase/branches/0.89/bin/start-hbase.sh Tue Oct 11 02:00:44 2011
@@ -49,4 +49,6 @@ else
"$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
Modified: hbase/branches/0.89/bin/stop-hbase.sh
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/stop-hbase.sh?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/bin/stop-hbase.sh (original)
+++ hbase/branches/0.89/bin/stop-hbase.sh Tue Oct 11 02:00:44 2011
@@ -60,5 +60,10 @@ done
distMode=`$bin/hbase org.apache.hadoop.hbase.HBaseConfTool hbase.cluster.distributed`
if [ "$distMode" == 'true' ]
then
+ # TODO: store backup masters in ZooKeeper and have the primary send them a shutdown message
+ # stop any backup masters
+ "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \
+ --hosts "${HBASE_BACKUP_MASTERS}" stop master-backup
+
"$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" stop zookeeper
fi
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java Tue Oct 11 02:00:44 2011
@@ -81,6 +81,12 @@ public final class HConstants {
/** default port for master web api */
public static final int DEFAULT_MASTER_INFOPORT = 60010;
+ /** Parameter name for the master type being backup (waits for primary to go inactive). */
+ public static final String MASTER_TYPE_BACKUP = "hbase.master.backup";
+
+ /** by default every master is a possible primary master unless the conf explicitly overrides it */
+ public static final boolean DEFAULT_MASTER_TYPE_BACKUP = false;
+
/** Name of ZooKeeper quorum configuration parameter. */
public static final String ZOOKEEPER_QUORUM = "hbase.zookeeper.quorum";
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Tue Oct 11 02:00:44 2011
@@ -231,6 +231,22 @@ public class HMaster extends Thread impl
this.zkMasterAddressWatcher =
new ZKMasterAddressWatcher(this.zooKeeperWrapper, this.shutdownRequested);
zooKeeperWrapper.registerListener(zkMasterAddressWatcher);
+
+ // if we're a backup master, stall until a primary to writes his address
+ if(conf.getBoolean(HConstants.MASTER_TYPE_BACKUP, HConstants.DEFAULT_MASTER_TYPE_BACKUP)) {
+ // this will only be a minute or so while the cluster starts up,
+ // so don't worry about setting watches on the parent znode
+ while (!zooKeeperWrapper.masterAddressExists()) {
+ try {
+ LOG.debug("Waiting for master address ZNode to be written " +
+ "(Also watching cluster state node)");
+ Thread.sleep(conf.getInt("zookeeper.session.timeout", 60 * 1000));
+ } catch (InterruptedException e) {
+ // interrupted = user wants to kill us. Don't continue
+ throw new IOException("Interrupted waiting for master address");
+ }
+ }
+ }
this.zkMasterAddressWatcher.writeAddressToZooKeeper(this.address, true);
this.regionServerOperationQueue =
new RegionServerOperationQueue(this.conf, this.closed);
@@ -1266,6 +1282,7 @@ public class HMaster extends Thread impl
Options opt = new Options();
opt.addOption("minServers", true, "Minimum RegionServers needed to host user tables");
opt.addOption("D", true, "Override HBase Configuration Settings");
+ opt.addOption("backup", false, "Do not try to become HMaster until the primary fails");
try {
CommandLine cmd = new GnuParser().parse(opt, args);
@@ -1288,6 +1305,11 @@ public class HMaster extends Thread impl
}
}
+ // check if we are the backup master - override the conf if so
+ if (cmd.hasOption("backup")) {
+ conf.setBoolean(HConstants.MASTER_TYPE_BACKUP, true);
+ }
+
if (cmd.getArgList().contains("start")) {
try {
// Print out vm stats before starting up.
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java?rev=1181348&r1=1181347&r2=1181348&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java Tue Oct 11 02:00:44 2011
@@ -465,6 +465,13 @@ public class ZooKeeperWrapper implements
return true;
}
+ /**
+ * @return true if zookeeper has a master address.
+ */
+ public boolean masterAddressExists() {
+ return checkExistenceOf(masterElectionZNode);
+ }
+
private HServerAddress readAddress(String znode, Watcher watcher) {
try {
LOG.debug("<" + instanceName + ">" + "Trying to read " + znode);