diff --git a/CHANGES.txt b/CHANGES.txt index 1d8ec455ad1..50894d78dc4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java b/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java index 6e091733e40..0de8615a341 100644 --- a/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java +++ b/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java @@ -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; } } diff --git a/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java b/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java index e9110e7da20..c37c6b2bfe6 100644 --- a/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java +++ b/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java @@ -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; diff --git a/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java b/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java index ecbf7ccce36..5338d661703 100644 --- a/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java +++ b/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java @@ -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 servers = QuorumPeerConfig.getServers();