From 0a9f7e62f6927faef7f9ef813885c93327df7e67 Mon Sep 17 00:00:00 2001 From: Jim Kellerman Date: Mon, 28 Jul 2008 19:26:30 +0000 Subject: [PATCH] HBASE-771 Names legal in 0.1 are not in 0.2; breaks migration git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@680453 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../apache/hadoop/hbase/HTableDescriptor.java | 12 +++++-- .../org/apache/hadoop/hbase/TestTable.java | 35 +++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f23107a2de7..3d564a2e92a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -218,6 +218,7 @@ Release 0.2.0 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 diff --git a/src/java/org/apache/hadoop/hbase/HTableDescriptor.java b/src/java/org/apache/hadoop/hbase/HTableDescriptor.java index eeb26b5fcc5..d8efaf20817 100644 --- a/src/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ b/src/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -122,7 +122,7 @@ public class HTableDescriptor implements WritableComparable { * @param name Table name. * @throws IllegalArgumentException if passed a table name * that is made of other than 'word' characters, underscore or period: i.e. - * [a-zA-Z_0-9.]. + * [a-zA-Z_0-9-.]. * @see HADOOP-1581 HBASE: Un-openable tablename bug */ public HTableDescriptor(final byte [] name) { @@ -213,13 +213,19 @@ public class HTableDescriptor implements WritableComparable { 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; } diff --git a/src/test/org/apache/hadoop/hbase/TestTable.java b/src/test/org/apache/hadoop/hbase/TestTable.java index 312d763544e..196c0691b7c 100644 --- a/src/test/org/apache/hadoop/hbase/TestTable.java +++ b/src/test/org/apache/hadoop/hbase/TestTable.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger; 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 @@ public class TestTable extends HBaseClusterTestCase { /** * 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 @@ public class TestTable extends HBaseClusterTestCase { // 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