HBASE-575 master dies with stack overflow error if rootdir isn't qualified

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@648427 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jim Kellerman 2008-04-15 21:45:28 +00:00
parent 863ac0c605
commit baa84cb4a1
4 changed files with 93 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Hbase Change Log
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

View File

@ -172,6 +172,14 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
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

View File

@ -21,6 +21,8 @@ package org.apache.hadoop.hbase.util;
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 @@ public class FSUtils {
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;
}
}
}

View File

@ -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);
}
}
}