Author: jimk
Date: Tue Apr 15 14:45:28 2008
New Revision: 648427

URL: http://svn.apache.org/viewvc?rev=648427&view=rev
Log:
HBASE-575   master dies with stack overflow error if rootdir isn't qualified

Added:
    hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/util/TestRootPath.java
Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/FSUtils.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=648427&r1=648426&r2=648427&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Apr 15 14:45:28 2008
@@ -6,6 +6,7 @@
    HBASE-11    Unexpected exits corrupt DFS
    HBASE-12    When hbase regionserver restarts, it says "impossible state for
                createLease()"
+   HBASE-575   master dies with stack overflow error if rootdir isn't qualified
 
   IMPROVEMENTS
    HBASE-559   MR example job to count table rows

Modified: 
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java?rev=648427&r1=648426&r2=648427&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java 
(original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java Tue 
Apr 15 14:45:28 2008
@@ -172,6 +172,14 @@
   public HMaster(Path rd, HServerAddress address, HBaseConfiguration conf)
   throws IOException {
     this.conf = conf;
+    try {
+      FSUtils.validateRootPath(rd);
+    } catch (IOException e) {
+      LOG.fatal("Not starting HMaster because the root directory path '" +
+          rd.toString() + "' is not valid. Check the setting of the" +
+          " configuration parameter '" + HBASE_DIR + "'", e);
+      throw e;
+    }
     this.rootdir = rd;
     this.threadWakeFrequency = conf.getInt(THREAD_WAKE_FREQUENCY, 10 * 1000);
     // The filesystem hbase wants to use is probably not what is set into

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/FSUtils.java
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/FSUtils.java?rev=648427&r1=648426&r2=648427&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/FSUtils.java 
(original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/FSUtils.java Tue 
Apr 15 14:45:28 2008
@@ -21,6 +21,8 @@
 
 import java.io.DataInputStream;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -140,4 +142,23 @@
     s.close();
   }
 
+  /**
+   * Verifies root directory path is a valid URI with a scheme
+   * 
+   * @param root root directory path
+   * @throws IOException if not a valid URI with a scheme
+   */
+  public static void validateRootPath(Path root) throws IOException {
+    try {
+      URI rootURI = new URI(root.toString());
+      String scheme = rootURI.getScheme();
+      if (scheme == null) {
+        throw new IOException("Root directory does not contain a scheme");
+      }
+    } catch (URISyntaxException e) {
+      IOException io = new IOException("Root directory path is not a valid 
URI");
+      io.initCause(e);
+      throw io;
+    }
+  }
 }

Added: 
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/util/TestRootPath.java
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/util/TestRootPath.java?rev=648427&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/util/TestRootPath.java 
(added)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/util/TestRootPath.java 
Tue Apr 15 14:45:28 2008
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2008 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.util;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.fs.Path;
+
+/**
+ * Test requirement that root directory must be a URI
+ */
+public class TestRootPath extends TestCase {
+  private static final Log LOG = LogFactory.getLog(TestRootPath.class);
+  
+  /** The test */
+  public void testRootPath() {
+    try {
+      // Try good path
+      FSUtils.validateRootPath(new Path("file:///tmp/hbase/hbase"));
+    } catch (IOException e) {
+      LOG.fatal("Unexpected exception checking valid path:", e);
+      fail();
+    }
+    try {
+      // Try good path
+      FSUtils.validateRootPath(new Path("hdfs://a:9000/hbase"));
+    } catch (IOException e) {
+      LOG.fatal("Unexpected exception checking valid path:", e);
+      fail();
+    }
+    try {
+      // bad path
+      FSUtils.validateRootPath(new Path("/hbase"));
+      fail();
+    } catch (IOException e) {
+      // Expected.
+      LOG.info("Got expected exception when checking invalid path:", e);
+    }
+  }
+}


Reply via email to