HBASE-1268 ZooKeeper config parsing can break HBase startup

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@755877 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-03-19 08:55:11 +00:00
parent 4f9c466426
commit d8bf82b984
4 changed files with 32 additions and 26 deletions

View File

@ -50,6 +50,8 @@ Release 0.20.0 - Unreleased
Improve lease handling
HBASE-1267 binary keys broken in trunk (again) -- part 2 and 3
(Ryan Rawson via Stack)
HBASE-1268 ZooKeeper config parsing can break HBase startup
(Nitay Joffe via Stack)
IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage

View File

@ -55,7 +55,8 @@ public class HQuorumPeer implements HConstants {
*/
public static void main(String[] args) {
try {
parseConfig();
Properties properties = parseZooKeeperConfig();
QuorumPeerConfig.parseProperties(properties);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
@ -68,23 +69,24 @@ public class HQuorumPeer implements HConstants {
}
/**
* Parse zoo.cfg, injecting HBase Configuration variables in.
* @throws Exception if anything goes wrong parsing config
* Parse ZooKeeper's zoo.cfg, injecting HBase Configuration variables in.
* @return Properties parsed from config stream with variables substituted.
* @throws IOException if anything goes wrong parsing config
*/
public static void parseConfig() throws Exception {
public static Properties parseZooKeeperConfig() throws IOException {
ClassLoader cl = HQuorumPeer.class.getClassLoader();
InputStream inputStream = cl.getResourceAsStream(ZOOKEEPER_CONFIG_NAME);
parseConfig(inputStream);
return parseConfig(inputStream);
}
/**
* This is a separate method from parseConfig() so that we can test by passing
* in our own InputStreams rather than reading directly from zoo.cfg.
* Parse zoo.cfg, injecting HBase Configuration variables in.
* @param inputStream InputStream to parse.
* @throws Exception if anything goes wrong parsing config
* Parse ZooKeeper's zoo.cfg, injecting HBase Configuration variables in.
* This method is used for testing so we can pass our own InputStream.
* @param inputStream InputStream to read from.
* @return Properties parsed from config stream with variables substituted.
* @throws IOException if anything goes wrong parsing config
*/
public static void parseConfig(InputStream inputStream) throws Exception {
public static Properties parseConfig(InputStream inputStream) throws IOException {
HBaseConfiguration conf = new HBaseConfiguration();
Properties properties = new Properties();
try {
@ -129,7 +131,6 @@ public class HQuorumPeer implements HConstants {
String key = entry.getKey().toString().trim();
properties.setProperty(key, newValue.toString());
}
QuorumPeerConfig.parseProperties(properties);
return properties;
}
}

View File

@ -20,7 +20,6 @@
package org.apache.hadoop.hbase.zookeeper;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@ -123,16 +122,9 @@ public class ZooKeeperWrapper implements HConstants {
}
private static void loadZooKeeperConfig() {
InputStream inputStream =
ZooKeeperWrapper.class.getClassLoader().getResourceAsStream(ZOOKEEPER_CONFIG_NAME);
if (inputStream == null) {
LOG.error("fail to open ZooKeeper config file " + ZOOKEEPER_CONFIG_NAME);
return;
}
Properties properties = new Properties();
Properties properties = null;
try {
properties.load(inputStream);
properties = HQuorumPeer.parseZooKeeperConfig();
} catch (IOException e) {
LOG.error("fail to read properties from " + ZOOKEEPER_CONFIG_NAME);
return;

View File

@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.zookeeper;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.apache.hadoop.hbase.HBaseTestCase;
import org.apache.zookeeper.server.ServerConfig;
@ -43,7 +44,19 @@ public class HQuorumPeerTest extends HBaseTestCase {
"server.0=${hbase.master.hostname}:2888:3888\n";
InputStream is = new ByteArrayInputStream(s.getBytes());
HQuorumPeer.parseConfig(is);
Properties properties = HQuorumPeer.parseConfig(is);
String userName = System.getProperty("user.name");
String dataDir = "/tmp/hbase-" + userName + "/zookeeper";
assertEquals(Integer.valueOf(2000), Integer.valueOf(properties.getProperty("tickTime")));
assertEquals(Integer.valueOf(10), Integer.valueOf(properties.getProperty("initLimit")));
assertEquals(Integer.valueOf(5), Integer.valueOf(properties.getProperty("syncLimit")));
assertEquals(dataDir, properties.get("dataDir"));
assertEquals(Integer.valueOf(2181), Integer.valueOf(properties.getProperty("clientPort")));
assertEquals("localhost:2888:3888", properties.get("server.0"));
QuorumPeerConfig.parseProperties(properties);
int tickTime = QuorumPeerConfig.getTickTime();
assertEquals(2000, tickTime);
@ -51,8 +64,6 @@ public class HQuorumPeerTest extends HBaseTestCase {
assertEquals(10, initLimit);
int syncLimit = QuorumPeerConfig.getSyncLimit();
assertEquals(5, syncLimit);
String userName = System.getProperty("user.name");
String dataDir = "/tmp/hbase-" + userName + "/zookeeper";
assertEquals(dataDir, ServerConfig.getDataDir());
assertEquals(2181, ServerConfig.getClientPort());
Map<Long,QuorumServer> servers = QuorumPeerConfig.getServers();