hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r767953 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/master/HMaster.java src/java/org/apache/hadoop/hbase/util/FSUtils.java
Date Thu, 23 Apr 2009 16:09:00 GMT
Author: stack
Date: Thu Apr 23 16:08:59 2009
New Revision: 767953

URL: http://svn.apache.org/viewvc?rev=767953&view=rev
Log:
HBASE-1195  If HBase directory exists but version file is inexistent, still proceed with bootstrapping

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=767953&r1=767952&r2=767953&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Apr 23 16:08:59 2009
@@ -152,6 +152,8 @@
    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

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=767953&r1=767952&r2=767953&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 Thu Apr 23 16:08:59
2009
@@ -201,12 +201,9 @@
     }
     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 @@
         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) {

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=767953&r1=767952&r2=767953&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 Thu Apr 23 16:08:59
2009
@@ -33,7 +33,9 @@
 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 @@
     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 @@
    * 
    * @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 @@
    * @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 @@
     }
     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);
+  }
 }
\ No newline at end of file



Mime
View raw message