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)
|
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());
|
||||||
|
|
|
@ -145,11 +145,17 @@ public final class TableName implements Comparable<TableName> {
|
||||||
return tableName;
|
return 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 '-'.
|
||||||
|
@ -161,15 +167,23 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue