You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/03/19 09:55:11 UTC

svn commit: r755877 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java

Author: stack
Date: Thu Mar 19 08:55:11 2009
New Revision: 755877

URL: http://svn.apache.org/viewvc?rev=755877&view=rev
Log:
HBASE-1268 ZooKeeper config parsing can break HBase startup

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
    hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=755877&r1=755876&r2=755877&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Mar 19 08:55:11 2009
@@ -50,6 +50,8 @@
                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

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java?rev=755877&r1=755876&r2=755877&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java Thu Mar 19 08:55:11 2009
@@ -55,7 +55,8 @@
    */
   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 @@
   }
 
   /**
-   * 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 @@
       String key = entry.getKey().toString().trim();
       properties.setProperty(key, newValue.toString());
     }
-
-    QuorumPeerConfig.parseProperties(properties);
+    return properties;
   }
 }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java?rev=755877&r1=755876&r2=755877&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java Thu Mar 19 08:55:11 2009
@@ -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 @@
   }
 
   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;

Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java?rev=755877&r1=755876&r2=755877&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/zookeeper/HQuorumPeerTest.java Thu Mar 19 08:55:11 2009
@@ -22,6 +22,7 @@
 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 @@
       "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 @@
     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();