From 5ece5d82712f03de81b11bd6a0de5e231c0af2cc Mon Sep 17 00:00:00 2001 From: mbertozzi Date: Tue, 4 Mar 2014 09:06:02 +0000 Subject: [PATCH] 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 --- .../ClientSnapshotDescriptionUtils.java | 2 +- .../org/apache/hadoop/hbase/TableName.java | 36 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java index 51f48abf327..299c30941c6 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java @@ -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()); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java index 4faccef5277..c83034e3326 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java @@ -145,11 +145,17 @@ public final class TableName implements Comparable { 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 * [a-zA-Z_0-9] or '_', '.' or '-'. @@ -161,15 +167,23 @@ public final class TableName implements Comparable { */ 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)); + "> at 0. Namespaces can only start with alphanumeric " + + "characters': i.e. [a-zA-Z_0-9]: " + + Bytes.toString(qualifierName)); } for (int i = start; i < end; i++) { if (Character.isLetterOrDigit(qualifierName[i]) || @@ -179,13 +193,13 @@ public final class TableName implements Comparable { continue; } throw new IllegalArgumentException("Illegal character code:" + qualifierName[i] + - ", <" + (char) qualifierName[i] + "> at " + i + - ". User-space table qualifiers can only contain " + - "'alphanumeric characters': i.e. [a-zA-Z_0-9-.]: " + - Bytes.toString(qualifierName, start, end)); + ", <" + (char) qualifierName[i] + "> at " + i + + ". " + (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); }