You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jm...@apache.org on 2012/09/04 19:52:53 UTC

svn commit: r1380759 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/util/ test/java/org/apache/hadoop/hbase/util/

Author: jmhsieh
Date: Tue Sep  4 17:52:52 2012
New Revision: 1380759

URL: http://svn.apache.org/viewvc?rev=1380759&view=rev
Log:
HBASE-6516 hbck cannot detect any IOException while ".tableinfo" file is missing (Jie Huang)

Added:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableInfoMissingException.java
Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java

Added: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableInfoMissingException.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableInfoMissingException.java?rev=1380759&view=auto
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableInfoMissingException.java (added)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableInfoMissingException.java Tue Sep  4 17:52:52 2012
@@ -0,0 +1,47 @@
+/**
+ * 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;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+
+/**
+ * 
+ * Failed to find .tableinfo file under table dir
+ *
+ */
+@InterfaceAudience.Private
+@SuppressWarnings("serial")
+public class TableInfoMissingException extends HBaseIOException {
+
+  public TableInfoMissingException() {
+    super();
+  }
+
+  public TableInfoMissingException( String message ) {
+    super(message);
+  }
+
+  public TableInfoMissingException( String message, Throwable t ) {
+    super(message, t);
+  }
+
+  public TableInfoMissingException( Throwable t ) {
+    super(t);
+  }
+
+}

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java?rev=1380759&r1=1380758&r2=1380759&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java Tue Sep  4 17:52:52 2012
@@ -41,7 +41,7 @@ import org.apache.hadoop.fs.PathFilter;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.TableDescriptors;
-import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.TableInfoMissingException;
 
 
 /**
@@ -158,7 +158,18 @@ public class FSTableDescriptors implemen
         return tdm.getTableDescriptor();
       }
     }
-    HTableDescriptor htd = getTableDescriptor(this.fs, this.rootdir, tablename);
+    
+    HTableDescriptor htd = null;
+    try {
+       htd = getTableDescriptor(this.fs, this.rootdir, tablename);
+    } catch (NullPointerException e) {
+      LOG.debug("Exception during readTableDecriptor. Current table name = "
+          + tablename, e);
+    } catch (IOException ioe) {
+      LOG.debug("Exception during readTableDecriptor. Current table name = "
+          + tablename, ioe);
+    }
+    
     if (htd == null) {
       LOG.warn("The following folder is in HBase's root directory and " +
         "doesn't contain a table descriptor, " +
@@ -253,7 +264,7 @@ public class FSTableDescriptors implemen
    * @return The 'current' tableinfo file.
    * @throws IOException
    */
-  private static FileStatus getTableInfoPath(final FileSystem fs,
+  public static FileStatus getTableInfoPath(final FileSystem fs,
       final Path tabledir)
   throws IOException {
     FileStatus [] status = FSUtils.listStatus(fs, tabledir, new PathFilter() {
@@ -370,21 +381,25 @@ public class FSTableDescriptors implemen
   public static HTableDescriptor getTableDescriptor(FileSystem fs,
       Path hbaseRootDir, byte[] tableName)
   throws IOException {
-     return getTableDescriptor(fs, hbaseRootDir, Bytes.toString(tableName));
+     HTableDescriptor htd = null;
+     try {
+       htd = getTableDescriptor(fs, hbaseRootDir, Bytes.toString(tableName));
+     } catch (NullPointerException e) {
+       LOG.debug("Exception during readTableDecriptor. Current table name = "
+           + Bytes.toString(tableName), e);
+     }
+     return htd;
   }
 
   static HTableDescriptor getTableDescriptor(FileSystem fs,
-      Path hbaseRootDir, String tableName) {
+      Path hbaseRootDir, String tableName) throws NullPointerException, IOException{
     HTableDescriptor htd = null;
-    try {
-      htd = getTableDescriptor(fs, FSUtils.getTablePath(hbaseRootDir, tableName));
-    } catch (NullPointerException e) {
-      LOG.debug("Exception during readTableDecriptor. Current table name = " +
-        tableName , e);
-    } catch (IOException ioe) {
-      LOG.debug("Exception during readTableDecriptor. Current table name = " +
-        tableName , ioe);
+    // ignore both -ROOT- and .META. tables
+    if (Bytes.compareTo(Bytes.toBytes(tableName), HConstants.ROOT_TABLE_NAME) == 0
+        || Bytes.compareTo(Bytes.toBytes(tableName), HConstants.META_TABLE_NAME) == 0) {
+      return null;
     }
+    htd = getTableDescriptor(fs, FSUtils.getTablePath(hbaseRootDir, tableName));
     return htd;
   }
 
@@ -392,7 +407,10 @@ public class FSTableDescriptors implemen
   throws IOException, NullPointerException {
     if (tableDir == null) throw new NullPointerException();
     FileStatus status = getTableInfoPath(fs, tableDir);
-    if (status == null) return null;
+    if (status == null) {
+      throw new TableInfoMissingException("No .tableinfo file under "
+          + tableDir.toUri());
+    }
     FSDataInputStream fsDataInputStream = fs.open(status.getPath());
     HTableDescriptor hTableDescriptor = null;
     try {

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java?rev=1380759&r1=1380758&r2=1380759&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java Tue Sep  4 17:52:52 2012
@@ -714,8 +714,9 @@ public class HBaseFsck {
               hbaseRoot, tableName);
           modTInfo.htds.add(htd);
         } catch (IOException ioe) {
-          LOG.error("Unable to read .tableinfo from " + hbaseRoot, ioe);
-          throw ioe;
+          LOG.warn("Unable to read .tableinfo from " + hbaseRoot, ioe);
+          errors.reportError(ERROR_CODE.NO_TABLEINFO_FILE, 
+              "Unable to read .tableinfo from " + hbaseRoot);
         }
       }
       modTInfo.addRegionInfo(hbi);
@@ -2648,7 +2649,7 @@ public class HBaseFsck {
       MULTI_DEPLOYED, SHOULD_NOT_BE_DEPLOYED, MULTI_META_REGION, RS_CONNECT_FAILURE,
       FIRST_REGION_STARTKEY_NOT_EMPTY, LAST_REGION_ENDKEY_NOT_EMPTY, DUPE_STARTKEYS,
       HOLE_IN_REGION_CHAIN, OVERLAP_IN_REGION_CHAIN, REGION_CYCLE, DEGENERATE_REGION,
-      ORPHAN_HDFS_REGION, LINGERING_SPLIT_PARENT
+      ORPHAN_HDFS_REGION, LINGERING_SPLIT_PARENT, NO_TABLEINFO_FILE
     }
     public void clear();
     public void report(String message);

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java?rev=1380759&r1=1380758&r2=1380759&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java Tue Sep  4 17:52:52 2012
@@ -407,6 +407,27 @@ public class TestHBaseFsck {
     }    
   }
 
+  @Test
+  public void testHbckMissingTableinfo() throws Exception {
+    String table = "tableInfo";
+    FileSystem fs = null;
+    Path tableinfo = null;
+    try {
+      setupTable(table);
+      Path hbaseTableDir = new Path(conf.get(HConstants.HBASE_DIR) + "/" + table );
+      fs = hbaseTableDir.getFileSystem(conf);
+      FileStatus status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
+      tableinfo = status.getPath();
+      fs.rename(tableinfo, new Path("/.tableinfo"));
+      
+      HBaseFsck hbck = doFsck(conf, false); 
+      assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.NO_TABLEINFO_FILE });
+    } finally {
+      fs.rename(new Path("/.tableinfo"), tableinfo);
+      deleteTable(table);
+    }
+  }
+   
   /**
    * This create and fixes a bad table with regions that have a duplicate
    * start key