HBASE-1816 Master Rewrite; redo how we check rootdir in HMaster constructor -- was broke when deploying on cluster

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@830768 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-10-28 21:34:23 +00:00
parent fd02c343fa
commit d6adcd04f5
3 changed files with 33 additions and 77 deletions

View File

@ -404,9 +404,8 @@
<name>zookeeper.retries</name> <name>zookeeper.retries</name>
<value>5</value> <value>5</value>
<description>How many times to retry connections to ZooKeeper. Used for <description>How many times to retry connections to ZooKeeper. Used for
reading/writing root region location, checking/writing out of safe mode. reading/writing root region location. Used together with ${zookeeper.pause}
Used together with ${zookeeper.pause} in an exponential backoff fashion in an exponential backoff fashion when making queries to ZooKeeper.
when making queries to ZooKeeper.
</description> </description>
</property> </property>
<property> <property>
@ -435,16 +434,6 @@
this means the root location is stored at /hbase/root-region-server. this means the root location is stored at /hbase/root-region-server.
</description> </description>
</property> </property>
<property>
<name>zookeeper.znode.safemode</name>
<value>safe-mode</value>
<description>Path to ephemeral ZNode signifying cluster is out of safe mode.
This is created by the master when scanning is done. Clients wait for this
node before querying the cluster. If a relative path is given, the parent
folder will be ${zookeeper.znode.parent}. By default, this means the safe
mode flag is stored at /hbase/safe-mode.
</description>
</property>
<!-- <!--
The following three properties are used together to create the list of The following three properties are used together to create the list of

View File

@ -157,16 +157,18 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
*/ */
public HMaster(HBaseConfiguration conf) throws IOException { public HMaster(HBaseConfiguration conf) throws IOException {
this.conf = conf; this.conf = conf;
this.fs = FileSystem.get(this.conf); // Set filesystem to be that of this.rootdir else we get complaints about
this.rootdir = getAndCheckRootDir(this.conf, this.fs); // mismatched filesystems if hbase.rootdir is hdfs and fs.defaultFS is
// Set back into the configuration the qualified rootdir path. // default localfs. Presumption is that rootdir is fully-qualified before
this.conf.set(HConstants.HBASE_DIR, rootdir.toString()); // we get to here with appropriate fs scheme.
// Set filesystem to be that of this.rootdir. this.rootdir = FSUtils.getRootDir(this.conf);
this.conf.set("fs.defaultFS", this.rootdir.toString()); this.conf.set("fs.defaultFS", this.rootdir.toString());
this.fs = FileSystem.get(this.conf);
checkRootDir(this.rootdir, this.conf, this.fs);
// Get my address and create an rpc server instance. The rpc-server port // Get my address and create an rpc server instance. The rpc-server port
// can be ephemeral...ensure we have the correct info // can be ephemeral...ensure we have the correct info
HServerAddress a = new HServerAddress(getMyAddress()); HServerAddress a = new HServerAddress(getMyAddress(this.conf));
this.rpcServer = HBaseRPC.getServer(this, a.getBindAddress(), this.rpcServer = HBaseRPC.getServer(this, a.getBindAddress(),
a.getPort(), conf.getInt("hbase.regionserver.handler.count", 10), a.getPort(), conf.getInt("hbase.regionserver.handler.count", 10),
false, conf); false, conf);
@ -198,19 +200,19 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
} }
/* /*
* Get the rootdir. Make sure its wholesome before returning. * Get the rootdir. Make sure its wholesome and exists before returning.
* @param rd
* @param conf * @param conf
* @param fs * @param fs
* @return Fully qualified path to wholesome hbase root dir. * @return hbase.rootdir (after checks for existence and bootstrapping if
* needed populating the directory with necessary bootup files).
* @throws IOException * @throws IOException
*/ */
private Path getAndCheckRootDir(final HBaseConfiguration c, private static Path checkRootDir(final Path rd, final HBaseConfiguration c,
final FileSystem fs) final FileSystem fs)
throws IOException { throws IOException {
Path rd = FSUtils.verifyAndQualifyRootDir(c);
// If FS is in safe mode wait till out of it. // If FS is in safe mode wait till out of it.
FSUtils.waitOnSafeMode(c, c.getInt(THREAD_WAKE_FREQUENCY, 10 * 1000)); FSUtils.waitOnSafeMode(c, c.getInt(THREAD_WAKE_FREQUENCY, 10 * 1000));
// Filesystem is good. Go ahead and check for hbase.rootdir. // Filesystem is good. Go ahead and check for hbase.rootdir.
if (!fs.exists(rd)) { if (!fs.exists(rd)) {
fs.mkdirs(rd); fs.mkdirs(rd);
@ -225,21 +227,7 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
return rd; return rd;
} }
/* private static void bootstrap(final Path rd, final HBaseConfiguration c)
* @return This masters' address.
* @throws UnknownHostException
*/
private String getMyAddress() throws UnknownHostException {
// Find out our address up in DNS.
String addressStr = DNS.getDefaultHost(
conf.get("hbase.master.dns.interface","default"),
conf.get("hbase.master.dns.nameserver","default"));
addressStr += ":" +
this.conf.get(MASTER_PORT, Integer.toString(DEFAULT_MASTER_PORT));
return addressStr;
}
private void bootstrap(final Path rd, final HBaseConfiguration c)
throws IOException { throws IOException {
LOG.info("BOOTSTRAP: creating ROOT and first META regions"); LOG.info("BOOTSTRAP: creating ROOT and first META regions");
try { try {
@ -271,12 +259,25 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
* @param hri Set all family block caching to <code>b</code> * @param hri Set all family block caching to <code>b</code>
* @param b * @param b
*/ */
private void setBlockCaching(final HRegionInfo hri, final boolean b) { private static void setBlockCaching(final HRegionInfo hri, final boolean b) {
for (HColumnDescriptor hcd: hri.getTableDesc().families.values()) { for (HColumnDescriptor hcd: hri.getTableDesc().families.values()) {
hcd.setBlockCacheEnabled(b); hcd.setBlockCacheEnabled(b);
} }
} }
/*
* @return This masters' address.
* @throws UnknownHostException
*/
private static String getMyAddress(final HBaseConfiguration c)
throws UnknownHostException {
// Find out our address up in DNS.
String s = DNS.getDefaultHost(c.get("hbase.master.dns.interface","default"),
c.get("hbase.master.dns.nameserver","default"));
s += ":" + c.get(MASTER_PORT, Integer.toString(DEFAULT_MASTER_PORT));
return s;
}
/** /**
* Checks to see if the file system is still accessible. * Checks to see if the file system is still accessible.
* If not, sets closed * If not, sets closed

View File

@ -237,19 +237,6 @@ public class FSUtils {
} }
} }
/**
* Verify and qualify rootdir in <code>conf</code>. Does not test for
* existence of the rootdir.
* @param conf.
* @return Verified and qualified rootdir.
* @throws IOException
*/
public static Path verifyAndQualifyRootDir(final HBaseConfiguration conf)
throws IOException {
Path dir = FSUtils.getRootDir(conf, false);
return FileSystem.get(conf).makeQualified(FSUtils.validateRootPath(dir));
}
/** /**
* If DFS, check safe mode and if so, wait until we clear it. * If DFS, check safe mode and if so, wait until we clear it.
* @param conf * @param conf
@ -290,33 +277,12 @@ public class FSUtils {
/** /**
* @param c * @param c
* @return Path to hbase root directory: i.e. <code>hbase.rootdir</code> as a * @return Path to hbase root directory: i.e. <code>hbase.rootdir</code> from
* Path. * configuration as a Path.
* @throws IOException * @throws IOException
*/ */
public static Path getRootDir(final HBaseConfiguration c) throws IOException { public static Path getRootDir(final HBaseConfiguration c) throws IOException {
return getRootDir(c, true); return new Path(c.get(HConstants.HBASE_DIR));
}
/**
* @param c
* @param test If true, test for presence and throw exception if not present.
* @return Path to hbase root directory: i.e. <code>hbase.rootdir</code> as a
* Path.
* @throws IOException
*/
public static Path getRootDir(final HBaseConfiguration c, final boolean test)
throws IOException {
FileSystem fs = FileSystem.get(c);
// Get root directory of HBase installation
Path rootdir = fs.makeQualified(new Path(c.get(HConstants.HBASE_DIR)));
if (test && !fs.exists(rootdir)) {
String message = "HBase root directory " + rootdir.toString() +
" does not exist.";
LOG.error(message);
throw new FileNotFoundException(message);
}
return rootdir;
} }
/** /**