HBASE-9708 Improve Snapshot Name Error Message (Esteban Gutierrez)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1573947 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
mbertozzi 2014-03-04 09:06:02 +00:00
parent f9dab7dddd
commit 5ece5d8271
2 changed files with 26 additions and 12 deletions

View File

@ -39,7 +39,7 @@ public class ClientSnapshotDescriptionUtils {
public static void assertSnapshotRequestIsValid(HBaseProtos.SnapshotDescription snapshot) public static void assertSnapshotRequestIsValid(HBaseProtos.SnapshotDescription snapshot)
throws IllegalArgumentException { throws IllegalArgumentException {
// make sure the snapshot name is valid // make sure the snapshot name is valid
TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName())); TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName()), true);
if(snapshot.hasTable()) { if(snapshot.hasTable()) {
// make sure the table name is valid, this will implicitly check validity // make sure the table name is valid, this will implicitly check validity
TableName tableName = TableName.valueOf(snapshot.getTable()); TableName tableName = TableName.valueOf(snapshot.getTable());

View File

@ -146,10 +146,16 @@ public final class TableName implements Comparable<TableName> {
} }
public static byte [] isLegalTableQualifierName(final byte[] qualifierName) { public static byte [] isLegalTableQualifierName(final byte[] qualifierName) {
isLegalTableQualifierName(qualifierName, 0, qualifierName.length); isLegalTableQualifierName(qualifierName, 0, qualifierName.length, false);
return qualifierName; return qualifierName;
} }
public static byte [] isLegalTableQualifierName(final byte[] qualifierName, boolean isSnapshot) {
isLegalTableQualifierName(qualifierName, 0, qualifierName.length, isSnapshot);
return qualifierName;
}
/** /**
* Qualifier names can only contain 'word' characters * Qualifier names can only contain 'word' characters
* <code>[a-zA-Z_0-9]</code> or '_', '.' or '-'. * <code>[a-zA-Z_0-9]</code> or '_', '.' or '-'.
@ -162,14 +168,22 @@ public final class TableName implements Comparable<TableName> {
public static void isLegalTableQualifierName(final byte[] qualifierName, public static void isLegalTableQualifierName(final byte[] qualifierName,
int start, int start,
int end) { int end) {
isLegalTableQualifierName(qualifierName, start, end, false);
}
public static void isLegalTableQualifierName(final byte[] qualifierName,
int start,
int end,
boolean isSnapshot) {
if(end - start < 1) { if(end - start < 1) {
throw new IllegalArgumentException("Table qualifier must not be empty"); throw new IllegalArgumentException(isSnapshot ? "Snapshot" : "Table" + " qualifier must not be empty");
} }
if (qualifierName[start] == '.' || qualifierName[start] == '-') { if (qualifierName[start] == '.' || qualifierName[start] == '-') {
throw new IllegalArgumentException("Illegal first character <" + qualifierName[0] + throw new IllegalArgumentException("Illegal first character <" + qualifierName[0] +
"> at 0. Namespaces can only start with alphanumeric " + "> at 0. Namespaces can only start with alphanumeric " +
"characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(qualifierName)); "characters': i.e. [a-zA-Z_0-9]: " +
Bytes.toString(qualifierName));
} }
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
if (Character.isLetterOrDigit(qualifierName[i]) || if (Character.isLetterOrDigit(qualifierName[i]) ||
@ -180,12 +194,12 @@ public final class TableName implements Comparable<TableName> {
} }
throw new IllegalArgumentException("Illegal character code:" + qualifierName[i] + throw new IllegalArgumentException("Illegal character code:" + qualifierName[i] +
", <" + (char) qualifierName[i] + "> at " + i + ", <" + (char) qualifierName[i] + "> at " + i +
". User-space table qualifiers can only contain " + ". " + (isSnapshot ? "snapshot" : "User-space table") +
" qualifiers can only contain " +
"'alphanumeric characters': i.e. [a-zA-Z_0-9-.]: " + "'alphanumeric characters': i.e. [a-zA-Z_0-9-.]: " +
Bytes.toString(qualifierName, start, end)); Bytes.toString(qualifierName, start, end));
} }
} }
public static void isLegalNamespaceName(byte[] namespaceName) { public static void isLegalNamespaceName(byte[] namespaceName) {
isLegalNamespaceName(namespaceName, 0, namespaceName.length); isLegalNamespaceName(namespaceName, 0, namespaceName.length);
} }