HBASE-1195 If HBase directory exists but version file is inexistent, still proceed with bootstrapping

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@767953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-04-23 16:08:59 +00:00
parent 6f966f2caa
commit bade3e74bd
3 changed files with 45 additions and 17 deletions

View File

@ -152,6 +152,8 @@ Release 0.20.0 - Unreleased
HBASE-1235 Add table enabled status to shell and UI
(Lars George via Stack)
HBASE-1333 RowCounter updates
HBASE-1195 If HBase directory exists but version file is inexistent, still
proceed with bootstrapping (Evgeny Ryabitskiy via Stack)
Release 0.19.0 - 01/21/2009
INCOMPATIBLE CHANGES

View File

@ -201,12 +201,9 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
}
this.conf.set(HConstants.HBASE_DIR, this.rootdir.toString());
this.rand = new Random();
Path rootRegionDir =
HRegion.getRegionDir(rootdir, HRegionInfo.ROOT_REGIONINFO);
LOG.info("Root region dir: " + rootRegionDir.toString());
try {
// Make sure the root directory exists!
// Make sure the hbase root directory exists!
if (!fs.exists(rootdir)) {
fs.mkdirs(rootdir);
FSUtils.setVersion(fs, rootdir);
@ -214,7 +211,8 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
FSUtils.checkVersion(fs, rootdir, true);
}
if (!fs.exists(rootRegionDir)) {
// Make sure the root region directory exists!
if (!FSUtils.rootRegionExists(fs, rootdir)) {
bootstrap();
}
} catch (IOException e) {

View File

@ -33,7 +33,9 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.RemoteExceptionHandler;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hdfs.DistributedFileSystem;
/**
@ -137,7 +139,7 @@ public class FSUtils {
String version = null;
if (fs.exists(versionFile)) {
FSDataInputStream s =
fs.open(new Path(rootdir, HConstants.VERSION_FILE_NAME));
fs.open(versionFile);
try {
version = DataInputStream.readUTF(s);
} finally {
@ -156,19 +158,28 @@ public class FSUtils {
*
* @throws IOException
*/
public static void checkVersion(FileSystem fs, Path rootdir, boolean message)
throws IOException {
public static void checkVersion(FileSystem fs, Path rootdir,
boolean message) throws IOException {
String version = getVersion(fs, rootdir);
if (version == null ||
version.compareTo(HConstants.FILE_SYSTEM_VERSION) != 0) {
// Output on stdout so user sees it in terminal.
String msg = "File system needs to be upgraded. Run " +
"the '${HBASE_HOME}/bin/hbase migrate' script.";
if (message) {
System.out.println("WARNING! " + msg);
if (version == null) {
if (!rootRegionExists(fs, rootdir)) {
// rootDir is empty (no version file and no root region)
// just create new version file (HBASE-1195)
FSUtils.setVersion(fs, rootdir);
return;
}
throw new FileSystemVersionException(msg);
} else if (version.compareTo(HConstants.FILE_SYSTEM_VERSION) == 0)
return;
// version is deprecated require migration
// Output on stdout so user sees it in terminal.
String msg = "File system needs to be upgraded. Run " +
"the '${HBASE_HOME}/bin/hbase migrate' script.";
if (message) {
System.out.println("WARNING! " + msg);
}
throw new FileSystemVersionException(msg);
}
/**
@ -178,11 +189,13 @@ public class FSUtils {
* @param rootdir
* @throws IOException
*/
public static void setVersion(FileSystem fs, Path rootdir) throws IOException {
public static void setVersion(FileSystem fs, Path rootdir)
throws IOException {
FSDataOutputStream s =
fs.create(new Path(rootdir, HConstants.VERSION_FILE_NAME));
s.writeUTF(HConstants.FILE_SYSTEM_VERSION);
s.close();
LOG.debug("Created version file to: " + rootdir.toString());
}
/**
@ -237,4 +250,19 @@ public class FSUtils {
}
return rootdir;
}
/**
* Checks if root region exists
*
* @param fs file system
* @param rootdir root directory of HBase installation
* @return true if exists
* @throws IOException
*/
public static boolean rootRegionExists(FileSystem fs, Path rootdir)
throws IOException {
Path rootRegionDir =
HRegion.getRegionDir(rootdir, HRegionInfo.ROOT_REGIONINFO);
return fs.exists(rootRegionDir);
}
}