You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by gc...@apache.org on 2012/10/24 03:10:48 UTC

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

Author: gchanan
Date: Wed Oct 24 01:10:48 2012
New Revision: 1401526

URL: http://svn.apache.org/viewvc?rev=1401526&view=rev
Log:
HBASE-7018 Fix and Improve TableDescriptor caching for bulk assignment

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java?rev=1401526&r1=1401525&r2=1401526&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java Wed Oct 24 01:10:48 2012
@@ -17,7 +17,6 @@
  */
 package org.apache.hadoop.hbase;
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Map;
 
@@ -29,22 +28,18 @@ public interface TableDescriptors {
   /**
    * @param tablename
    * @return HTableDescriptor for tablename
-   * @throws TableExistsException
-   * @throws FileNotFoundException
    * @throws IOException
    */
   public HTableDescriptor get(final String tablename)
-  throws FileNotFoundException, IOException;
+  throws IOException;
 
   /**
    * @param tablename
    * @return HTableDescriptor for tablename
-   * @throws TableExistsException
-   * @throws FileNotFoundException
    * @throws IOException
    */
   public HTableDescriptor get(final byte[] tablename)
-  throws FileNotFoundException, IOException;
+  throws IOException;
 
   /**
    * Get Map of all HTableDescriptors. Populates the descriptor cache as a

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1401526&r1=1401525&r2=1401526&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Wed Oct 24 01:10:48 2012
@@ -2773,7 +2773,7 @@ public class HRegionServer implements HR
       htd = htds.get(region.getTableNameAsString());
       if (htd == null) {
         htd = this.tableDescriptors.get(region.getTableName());
-        htds.put(region.getRegionNameAsString(), htd);
+        htds.put(region.getTableNameAsString(), htd);
       }
     }
     this.regionsInTransitionInRS.putIfAbsent(region.getEncodedNameAsBytes(),

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=1401526&r1=1401525&r2=1401526&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 Wed Oct 24 01:10:48 2012
@@ -122,7 +122,7 @@ public class FSTableDescriptors implemen
    */
   @Override
   public HTableDescriptor get(final byte [] tablename)
-  throws FileNotFoundException, IOException {
+  throws IOException {
     return get(Bytes.toString(tablename));
   }
 
@@ -131,7 +131,7 @@ public class FSTableDescriptors implemen
    */
   @Override
   public HTableDescriptor get(final String tablename)
-  throws FileNotFoundException, IOException {
+  throws IOException {
     invocations++;
     if (HTableDescriptor.ROOT_TABLEDESC.getNameAsString().equals(tablename)) {
       cachehits++;
@@ -148,20 +148,19 @@ public class FSTableDescriptors implemen
     }
 
     // Look in cache of descriptors.
-    TableDescriptorModtime tdm = this.cache.get(tablename);
+    TableDescriptorModtime cachedtdm = this.cache.get(tablename);
 
-    // Check mod time has not changed (this is trip to NN).
-    long modtime = getTableInfoModtime(this.fs, this.rootdir, tablename);
-    if (tdm != null) {
-      if (modtime <= tdm.getModtime()) {
+    if (cachedtdm != null) {
+      // Check mod time has not changed (this is trip to NN).
+      if (getTableInfoModtime(this.fs, this.rootdir, tablename) <= cachedtdm.getModtime()) {
         cachehits++;
-        return tdm.getTableDescriptor();
+        return cachedtdm.getTableDescriptor();
       }
     }
     
-    HTableDescriptor htd = null;
+    TableDescriptorModtime tdmt = null;
     try {
-       htd = getTableDescriptor(this.fs, this.rootdir, tablename);
+      tdmt = getTableDescriptorModtime(this.fs, this.rootdir, tablename);
     } catch (NullPointerException e) {
       LOG.debug("Exception during readTableDecriptor. Current table name = "
           + tablename, e);
@@ -170,14 +169,14 @@ public class FSTableDescriptors implemen
           + tablename, ioe);
     }
     
-    if (htd == null) {
+    if (tdmt == null) {
       LOG.warn("The following folder is in HBase's root directory and " +
         "doesn't contain a table descriptor, " +
         "do consider deleting it: " + tablename);
     } else {
-      this.cache.put(tablename, new TableDescriptorModtime(modtime, htd));
+      this.cache.put(tablename, tdmt);
     }
-    return htd;
+    return tdmt == null ? null : tdmt.getTableDescriptor();
   }
 
   /* (non-Javadoc)
@@ -231,7 +230,7 @@ public class FSTableDescriptors implemen
       }
     }
     TableDescriptorModtime tdm = this.cache.remove(tablename);
-    return tdm == null? null: tdm.getTableDescriptor();
+    return tdm == null ? null : tdm.getTableDescriptor();
   }
 
   /**
@@ -383,7 +382,9 @@ public class FSTableDescriptors implemen
   throws IOException {
      HTableDescriptor htd = null;
      try {
-       htd = getTableDescriptor(fs, hbaseRootDir, Bytes.toString(tableName));
+       TableDescriptorModtime tdmt =
+         getTableDescriptorModtime(fs, hbaseRootDir, Bytes.toString(tableName));
+       htd = tdmt == null ? null : tdmt.getTableDescriptor();
      } catch (NullPointerException e) {
        LOG.debug("Exception during readTableDecriptor. Current table name = "
            + Bytes.toString(tableName), e);
@@ -392,19 +393,23 @@ public class FSTableDescriptors implemen
   }
 
   static HTableDescriptor getTableDescriptor(FileSystem fs,
+      Path hbaseRootDir, String tableName) throws NullPointerException, IOException {
+    TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, hbaseRootDir, tableName);
+    return tdmt == null ? null : tdmt.getTableDescriptor();
+  }
+
+  static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs,
       Path hbaseRootDir, String tableName) throws NullPointerException, IOException{
-    HTableDescriptor htd = null;
     // 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;
+    return getTableDescriptorModtime(fs, FSUtils.getTablePath(hbaseRootDir, tableName));
   }
 
-  public static HTableDescriptor getTableDescriptor(FileSystem fs, Path tableDir)
-  throws IOException, NullPointerException {
+  static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir)
+  throws NullPointerException, IOException {
     if (tableDir == null) throw new NullPointerException();
     FileStatus status = getTableInfoPath(fs, tableDir);
     if (status == null) {
@@ -419,8 +424,15 @@ public class FSTableDescriptors implemen
     } finally {
       fsDataInputStream.close();
     }
-    return hTableDescriptor;
+    return new TableDescriptorModtime(status.getModificationTime(), hTableDescriptor);
+  }
+
+  public static HTableDescriptor getTableDescriptor(FileSystem fs, Path tableDir)
+  throws IOException, NullPointerException {
+    TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, tableDir);
+    return tdmt == null? null: tdmt.getTableDescriptor();
   }
+ 
 
   /**
    * Update table descriptor

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java?rev=1401526&r1=1401525&r2=1401526&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java Wed Oct 24 01:10:48 2012
@@ -27,7 +27,6 @@ import static org.junit.Assert.assertEqu
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -247,13 +246,13 @@ public class TestCatalogJanitor {
         
         @Override
         public HTableDescriptor get(byte[] tablename)
-        throws FileNotFoundException, IOException {
+        throws IOException {
           return get(Bytes.toString(tablename));
         }
         
         @Override
         public HTableDescriptor get(String tablename)
-        throws FileNotFoundException, IOException {
+        throws IOException {
           return createHTableDescriptor();
         }