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:
parent
f9dab7dddd
commit
5ece5d8271
|
@ -39,7 +39,7 @@ public class ClientSnapshotDescriptionUtils {
|
|||
public static void assertSnapshotRequestIsValid(HBaseProtos.SnapshotDescription snapshot)
|
||||
throws IllegalArgumentException {
|
||||
// make sure the snapshot name is valid
|
||||
TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName()));
|
||||
TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName()), true);
|
||||
if(snapshot.hasTable()) {
|
||||
// make sure the table name is valid, this will implicitly check validity
|
||||
TableName tableName = TableName.valueOf(snapshot.getTable());
|
||||
|
|
|
@ -145,11 +145,17 @@ public final class TableName implements Comparable<TableName> {
|
|||
return tableName;
|
||||
}
|
||||
|
||||
public static byte [] isLegalTableQualifierName(final byte[] qualifierName){
|
||||
isLegalTableQualifierName(qualifierName, 0, qualifierName.length);
|
||||
public static byte [] isLegalTableQualifierName(final byte[] qualifierName) {
|
||||
isLegalTableQualifierName(qualifierName, 0, qualifierName.length, false);
|
||||
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
|
||||
* <code>[a-zA-Z_0-9]</code> or '_', '.' or '-'.
|
||||
|
@ -161,15 +167,23 @@ public final class TableName implements Comparable<TableName> {
|
|||
*/
|
||||
public static void isLegalTableQualifierName(final byte[] qualifierName,
|
||||
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) {
|
||||
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] == '-') {
|
||||
throw new IllegalArgumentException("Illegal first character <" + qualifierName[0] +
|
||||
"> 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++) {
|
||||
if (Character.isLetterOrDigit(qualifierName[i]) ||
|
||||
|
@ -180,12 +194,12 @@ public final class TableName implements Comparable<TableName> {
|
|||
}
|
||||
throw new IllegalArgumentException("Illegal character code:" + qualifierName[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-.]: " +
|
||||
Bytes.toString(qualifierName, start, end));
|
||||
}
|
||||
}
|
||||
|
||||
public static void isLegalNamespaceName(byte[] namespaceName) {
|
||||
isLegalNamespaceName(namespaceName, 0, namespaceName.length);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue