HBASE-2147 - run zookeeper in the same jvm as master during non-distributed mode

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@901030 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan Rawson 2010-01-20 01:42:12 +00:00
parent 7a8f4c08e3
commit 44572e6a2d
5 changed files with 83 additions and 3 deletions

View File

@ -178,6 +178,7 @@ Release 0.21.0 - Unreleased
HBASE-2140 findbugs issues - 2 performance warnings as suggested by findbugs
(Kay Kay via Stack)
HBASE-2139 findbugs task in build.xml (Kay Kay via Stack)
HBASE-2147 run zookeeper in the same jvm as master during non-distributed mode
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable

View File

@ -38,7 +38,16 @@ then
exit $errCode
fi
distMode=`$bin/hbase org.apache.hadoop.hbase.HBaseConfTool hbase.cluster.distributed`
if [ $distMode == 'false' ]
then
echo "Non distributed mode startup"
"$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
fi

View File

@ -0,0 +1,34 @@
/*
* 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.
*/
package org.apache.hadoop.hbase;
import org.apache.hadoop.conf.Configuration;
public class HBaseConfTool {
public static void main(String args[]) {
if (args.length < 1)
return;
Configuration conf = HBaseConfiguration.create();
System.out.println(conf.get(args[0]));
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright 2009 The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one
@ -43,7 +43,6 @@ import org.apache.zookeeper.server.persistence.FileTxnLog;
public class MiniZooKeeperCluster {
private static final Log LOG = LogFactory.getLog(MiniZooKeeperCluster.class);
// TODO: make this more configurable?
private static final int TICK_TIME = 2000;
private static final int CONNECTION_TIMEOUT = 30000;
@ -51,12 +50,21 @@ public class MiniZooKeeperCluster {
private int clientPort = 21810; // use non-standard port
private NIOServerCnxn.Factory standaloneServerFactory;
private int tickTime = 0;
/** Create mini ZooKeeper cluster. */
public MiniZooKeeperCluster() {
this.started = false;
}
public void setClientPort(int clientPort) {
this.clientPort = clientPort;
}
public void setTickTime(int tickTime) {
this.tickTime = tickTime;
}
// / XXX: From o.a.zk.t.ClientBase
private static void setupTestEnv() {
// during the tests we run with 100K prealloc in the logs.
@ -75,6 +83,7 @@ public class MiniZooKeeperCluster {
*/
public int startup(File baseDir) throws IOException,
InterruptedException {
setupTestEnv();
shutdown();
@ -82,7 +91,13 @@ public class MiniZooKeeperCluster {
File dir = new File(baseDir, "zookeeper").getAbsoluteFile();
recreateDir(dir);
ZooKeeperServer server = new ZooKeeperServer(dir, dir, TICK_TIME);
int tickTimeToUse;
if (this.tickTime > 0) {
tickTimeToUse = this.tickTime;
} else {
tickTimeToUse = TICK_TIME;
}
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse);
while (true) {
try {
standaloneServerFactory = new NIOServerCnxn.Factory(clientPort);

View File

@ -20,6 +20,7 @@
package org.apache.hadoop.hbase.master;
import java.io.IOException;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Constructor;
@ -59,6 +60,7 @@ import org.apache.hadoop.hbase.LocalHBaseCluster;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.RemoteExceptionHandler;
import org.apache.hadoop.hbase.TableExistsException;
import org.apache.hadoop.hbase.MiniZooKeeperCluster;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.Result;
@ -1196,6 +1198,25 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
// If 'local', defer to LocalHBaseCluster instance. Starts master
// and regionserver both in the one JVM.
if (LocalHBaseCluster.isLocal(conf)) {
// TODO make zookeepercluster a field and do an orderly shutdown
MiniZooKeeperCluster zooKeeperCluster = new MiniZooKeeperCluster();
File zkDataPath = new File(conf.get("hbase.zookeeper.property.dataDir"));
int zkClientPort = conf.getInt("hbase.zookeeper.property.clientPort", 0);
if (zkClientPort == 0) {
throw new IOException("No config value for hbase.zookeeper.property.clientPort");
}
zooKeeperCluster.setTickTime(conf.getInt("hbase.zookeeper.property.tickTime", 3000));
zooKeeperCluster.setClientPort(zkClientPort);
int clientPort = zooKeeperCluster.startup(zkDataPath);
if (clientPort != zkClientPort) {
String errorMsg = "Couldnt start ZK at requested address of " +
zkClientPort + ", instead got: " + clientPort + ". Aborting. Why? " +
"Because clients (eg shell) wont be able to find this ZK quorum";
System.err.println(errorMsg);
throw new IOException(errorMsg);
}
conf.set("hbase.zookeeper.property.clientPort", Integer.toString(clientPort));
(new LocalHBaseCluster(conf)).startup();
} else {
Constructor<? extends HMaster> c =