You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ji...@apache.org on 2008/06/04 00:16:43 UTC

svn commit: r662905 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/client/HTable.java src/java/org/apache/hadoop/hbase/master/HMaster.java src/java/org/apache/hadoop/hbase/regionserver/HStore.java

Author: jimk
Date: Tue Jun  3 15:16:43 2008
New Revision: 662905

URL: http://svn.apache.org/viewvc?rev=662905&view=rev
Log:
HBASE-655   Need programmatic way to add column family: need programmatic way to enable/disable table

Added HTable.isTableOnline and HTable.isTableOffline

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=662905&r1=662904&r2=662905&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Jun  3 15:16:43 2008
@@ -36,6 +36,8 @@
    HBASE-656   Do not retry exceptions such as unknown scanner or illegal argument
    HBASE-659   HLog#cacheFlushLock not cleared; hangs a region
    HBASE-663   Incorrect sequence number for cache flush
+   HBASE-655   Need programmatic way to add column family: need programmatic way
+               to enable/disable table
    
   IMPROVEMENTS
    HBASE-559   MR example job to count table rows

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java?rev=662905&r1=662904&r2=662905&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java Tue Jun  3 15:16:43 2008
@@ -42,13 +42,13 @@
 import org.apache.hadoop.hbase.io.Cell;
 import org.apache.hadoop.hbase.io.RowResult;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.io.Text;
 
 /**
  * Used to communicate with a single HBase table
  */
 public class HTable {
-  private final Log LOG = LogFactory.getLog(this.getClass());
   private final HConnection connection;
   private final byte [] tableName;
   private HBaseConfiguration configuration;
@@ -126,6 +126,174 @@
   }
 
   /**
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOnline(Text tableName) throws IOException {
+    return isTableOnline(tableName.getBytes());
+  }
+  /**
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOnline(String tableName) throws IOException {
+    return isTableOnline(Bytes.toBytes(tableName));
+  }
+  /**
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOnline(byte[] tableName) throws IOException {
+    return isTableOnline(new HBaseConfiguration(), tableName);
+  }
+  
+  /**
+   * @param conf HBaseConfiguration object
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOnline(HBaseConfiguration conf, Text tableName)
+  throws IOException {
+    return isTableOnline(conf, tableName.getBytes());
+  }
+  
+  /**
+   * @param conf HBaseConfiguration object
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOnline(HBaseConfiguration conf, String tableName)
+  throws IOException {
+    return isTableOnline(conf, Bytes.toBytes(tableName));
+  }
+
+  /**
+   * @param conf HBaseConfiguration object
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOnline(HBaseConfiguration conf, byte[] tableName)
+  throws IOException {
+    boolean online = true;
+    if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
+      // The root region is always on-line
+      return true;
+    }
+    HTable meta = new HTable(conf,
+        Bytes.equals(tableName, HConstants.META_TABLE_NAME) ?
+            HConstants.ROOT_TABLE_NAME : HConstants.META_TABLE_NAME);
+    Scanner s = meta.getScanner(HConstants.COL_REGIONINFO_ARRAY,
+        HRegionInfo.createRegionName(tableName, null, HConstants.NINES));
+    try {
+      RowResult r = null;
+      while ((r = s.next()) != null) {
+        Cell c = r.get(HConstants.COL_REGIONINFO);
+        if (c != null) {
+          HRegionInfo info = Writables.getHRegionInfoOrNull(c.getValue());
+          if (info != null) {
+            if (info.isOffline()) {
+              online = false;
+              break;
+            }
+          }
+        }
+      }
+    } finally {
+      s.close();
+    }
+    return online;
+  }
+  
+  /**
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOffline(Text tableName) throws IOException {
+    return isTableOffline(tableName.getBytes());
+  }
+  /**
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOffline(String tableName) throws IOException {
+    return isTableOffline(Bytes.toBytes(tableName));
+  }
+  /**
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOffline(byte[] tableName) throws IOException {
+    return isTableOffline(new HBaseConfiguration(), tableName);
+  }
+  
+  /**
+   * @param conf HBaseConfiguration object
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOffline(HBaseConfiguration conf, Text tableName)
+  throws IOException {
+    return isTableOffline(conf, tableName.getBytes());
+  }
+  
+  /**
+   * @param conf HBaseConfiguration object
+   * @param tableName name of table to check
+   * @return true if table is on-line
+   * @throws IOException
+   */
+  public static boolean isTableOffline(HBaseConfiguration conf, String tableName)
+  throws IOException {
+    return isTableOffline(conf, Bytes.toBytes(tableName));
+  }
+
+  /**
+   * @param conf HBaseConfiguration object
+   * @param tableName name of table to check
+   * @return true if table is off-line
+   * @throws IOException
+   */
+  public static boolean isTableOffline(HBaseConfiguration conf, byte[] tableName)
+  throws IOException {
+    boolean offline = true;
+    if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
+      // The root region is always online
+      return false;
+    }
+    HTable meta = new HTable(conf, HConstants.META_TABLE_NAME);
+    Scanner s = meta.getScanner(HConstants.COL_REGIONINFO_ARRAY,
+        HRegionInfo.createRegionName(tableName, null, HConstants.NINES));
+    try {
+      RowResult r = null;
+      while ((r = s.next()) != null) {
+        Cell c = r.get(HConstants.COL_REGIONINFO);
+        if (c != null) {
+          HRegionInfo info = Writables.getHRegionInfoOrNull(c.getValue());
+          if (info != null) {
+            if (!info.isOffline()) {
+              offline = false;
+              break;
+            }
+          }
+        }
+      }
+    } finally {
+      s.close();
+    }
+    return offline;
+  }
+  
+  /**
    * Find region location hosting passed row using cached info
    * @param row Row to find.
    * @return Location of row.
@@ -912,6 +1080,7 @@
    * Completely delete the row's cells.
    *
    * @param row Key of the row you want to completely delete.
+   * @param column column to be deleted
    * @throws IOException
    */
   public void deleteAll(final byte [] row, final byte [] column)

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=662905&r1=662904&r2=662905&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 Tue Jun  3 15:16:43 2008
@@ -629,6 +629,9 @@
 
   /** {@inheritDoc} */
   public void deleteTable(final byte [] tableName) throws IOException {
+    if (Bytes.equals(tableName, ROOT_TABLE_NAME)) {
+      throw new IOException("Can't delete root table");
+    }
     new TableDelete(this, tableName).process();
     LOG.info("deleted table: " + Bytes.toString(tableName));
   }
@@ -654,11 +657,17 @@
 
   /** {@inheritDoc} */
   public void enableTable(final byte [] tableName) throws IOException {
+    if (Bytes.equals(tableName, ROOT_TABLE_NAME)) {
+      throw new IOException("Can't enable root table");
+    }
     new ChangeTableState(this, tableName, true).process();
   }
 
   /** {@inheritDoc} */
   public void disableTable(final byte [] tableName) throws IOException {
+    if (Bytes.equals(tableName, ROOT_TABLE_NAME)) {
+      throw new IOException("Can't disable root table");
+    }
     new ChangeTableState(this, tableName, false).process();
   }
 

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java?rev=662905&r1=662904&r2=662905&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java Tue Jun  3 15:16:43 2008
@@ -438,7 +438,7 @@
         try {
           // Try fixing this file.. if we can.  Use the hbase version of fix.
           // Need to remove the old index file first else fix won't go ahead.
-          this.fs.delete(new Path(mapfile, MapFile.INDEX_FILE_NAME));
+          this.fs.delete(new Path(mapfile, MapFile.INDEX_FILE_NAME), false);
           long count = MapFile.fix(this.fs, mapfile, HStoreFile.HbaseMapFile.KEY_CLASS,
             HStoreFile.HbaseMapFile.VALUE_CLASS, false, this.conf);
           if (LOG.isDebugEnabled()) {