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
This commit is contained in:
Jim Kellerman 2008-07-28 19:26:30 +00:00
parent 37b6f7e42e
commit 0a9f7e62f6
3 changed files with 43 additions and 5 deletions

View File

@ -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

View File

@ -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.
* <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 @@ 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;
}

View File

@ -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());
}
}
}