hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r680453 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/HTableDescriptor.java src/test/org/apache/hadoop/hbase/TestTable.java
Date Mon, 28 Jul 2008 19:26:30 GMT
Author: jimk
Date: Mon Jul 28 12:26:30 2008
New Revision: 680453

URL: http://svn.apache.org/viewvc?rev=680453&view=rev
Log:
HBASE-771   Names legal in 0.1 are not in 0.2; breaks migration

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HTableDescriptor.java
    hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestTable.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=680453&r1=680452&r2=680453&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Mon Jul 28 12:26:30 2008
@@ -218,6 +218,7 @@
    HBASE-770   Update HBaseRPC to match hadoop 0.17 RPC
    HBASE-780   Can't scan '.META.' from new shell
    HBASE-424   Should be able to enable/disable .META. table
+   HBASE-771   Names legal in 0.1 are not in 0.2; breaks migration
    
   IMPROVEMENTS
    HBASE-559   MR example job to count table rows

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HTableDescriptor.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HTableDescriptor.java?rev=680453&r1=680452&r2=680453&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HTableDescriptor.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HTableDescriptor.java Mon Jul 28 12:26:30
2008
@@ -122,7 +122,7 @@
    * @param name Table name.
    * @throws IllegalArgumentException if passed a table name
    * that is made of other than 'word' characters, underscore or period: i.e.
-   * <code>[a-zA-Z_0-9.].
+   * <code>[a-zA-Z_0-9-.].
    * @see <a href="HADOOP-1581">HADOOP-1581 HBASE: Un-openable tablename bug</a>
    */
   public HTableDescriptor(final byte [] name) {
@@ -213,13 +213,19 @@
     if (b == null || b.length <= 0) {
       throw new IllegalArgumentException("Name is null or empty");
     }
+    if (b[0] == '.' || b[0] == '-') {
+      throw new IllegalArgumentException("Illegal first character <" + b[0] +
+          ">. " + "User-space table names can only start with 'word " +
+          "characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(b));
+    }
     for (int i = 0; i < b.length; i++) {
-      if (Character.isLetterOrDigit(b[i]) || b[i] == '_') {
+      if (Character.isLetterOrDigit(b[i]) || b[i] == '_' || b[i] == '-' ||
+          b[i] == '.') {
         continue;
       }
       throw new IllegalArgumentException("Illegal character <" + b[i] + ">. " +
         "User-space table names can only contain 'word characters':" +
-        "i.e. [a-zA-Z_0-9]: " + Bytes.toString(b));
+        "i.e. [a-zA-Z_0-9-.]: " + Bytes.toString(b));
     }
     return b;
   }

Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestTable.java?rev=680453&r1=680452&r2=680453&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestTable.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestTable.java Mon Jul 28 12:26:30
2008
@@ -24,6 +24,7 @@
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.io.BatchUpdate;
+import org.apache.hadoop.hbase.util.Bytes;
 
 /** Tests table creation restrictions*/
 public class TestTable extends HBaseClusterTestCase {
@@ -127,17 +128,18 @@
 
   /**
    * Test read only tables
+   * @throws Exception
    */
   public void testReadOnlyTable() throws Exception {
     HBaseAdmin admin = new HBaseAdmin(conf);
     HTableDescriptor desc = new HTableDescriptor(getName());
-    byte[] colName = "test:".getBytes();
+    byte[] colName = Bytes.toBytes("test:");
     desc.addFamily(new HColumnDescriptor(colName));
     desc.setReadOnly(true);
     admin.createTable(desc);
     HTable table = new HTable(conf, getName());
     try {
-      byte[] value = "somedata".getBytes();
+      byte[] value = Bytes.toBytes("somedata");
       BatchUpdate update = new BatchUpdate();
       update.put(colName, value);
       table.commit(update);
@@ -146,4 +148,33 @@
       // expected
     }
   }
+  
+  /**
+   * Test that user table names can contain '-' and '.' so long as they do not
+   * start with same. HBASE-771
+   */
+  public void testTableNames() {
+    byte[][] illegalNames = new byte[][] {
+        Bytes.toBytes("-bad"),
+        Bytes.toBytes(".bad"),
+        HConstants.ROOT_TABLE_NAME,
+        HConstants.META_TABLE_NAME
+    };
+    for (int i = 0; i < illegalNames.length; i++) {
+      try {
+        new HTableDescriptor(illegalNames[i]);
+        fail("Did not detect '" + Bytes.toString(illegalNames[i]) +
+            "' as an illegal user table name");
+      } catch (IllegalArgumentException e) {
+        // expected
+      }
+    }
+    byte[] legalName = Bytes.toBytes("g-oo.d");
+    try {
+      new HTableDescriptor(legalName);
+    } catch (IllegalArgumentException e) {
+      fail("Legal user table name: '" + Bytes.toString(legalName) +
+          "' caused IllegalArgumentException: " + e.getMessage());
+    }
+  }
 }
\ No newline at end of file



Mime
View raw message