HBASE-4325 Improve error message when using STARTROW for meta scans

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1169914 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-09-12 20:41:22 +00:00
parent c9efe7d495
commit bcd4846420
3 changed files with 36 additions and 2 deletions

View File

@ -568,6 +568,8 @@ Release 0.90.5 - Unreleased
HBASE-4294 HLogSplitter sleeps with 1-second granularity (todd)
HBASE-4270 IOE ignored during flush-on-close causes dataloss
HBASE-4180 HBase should check the isSecurityEnabled flag before login
HBASE-4325 Improve error message when using STARTROW for meta scans
(Jonathan Hsieh)
IMPROVEMENT
HBASE-4205 Enhance HTable javadoc (Eric Charles)

View File

@ -1311,12 +1311,16 @@ public class KeyValue implements Writable, HeapSize {
return index;
}
/**
* This function is only used in Meta key comparisons so its error message
* is specific for meta key errors.
*/
static int getRequiredDelimiterInReverse(final byte [] b,
final int offset, final int length, final int delimiter) {
int index = getDelimiterInReverse(b, offset, length, delimiter);
if (index < 0) {
throw new IllegalArgumentException("No " + delimiter + " in <" +
Bytes.toString(b) + ">" + ", length=" + length + ", offset=" + offset);
throw new IllegalArgumentException(".META. key must have two '" + (char)delimiter + "' "
+ "delimiters and have the following format: '<table>,<key>,<etc>'");
}
return index;
}

View File

@ -28,6 +28,7 @@ import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.KeyValue.KVComparator;
import org.apache.hadoop.hbase.KeyValue.MetaComparator;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.util.Bytes;
@ -149,6 +150,33 @@ public class TestKeyValue extends TestCase {
metacomparisons(new KeyValue.MetaComparator());
}
public void testBadMetaCompareSingleDelim() {
MetaComparator c = new KeyValue.MetaComparator();
long now = System.currentTimeMillis();
// meta keys values are not quite right. A users can enter illegal values
// from shell when scanning meta.
KeyValue a = new KeyValue(Bytes.toBytes("table,a1"), now);
KeyValue b = new KeyValue(Bytes.toBytes("table,a2"), now);
try {
c.compare(a, b);
} catch (IllegalArgumentException iae) {
assertEquals(".META. key must have two ',' delimiters and have the following" +
" format: '<table>,<key>,<etc>'", iae.getMessage());
return;
}
fail("Expected IllegalArgumentException");
}
public void testMetaComparatorTableKeysWithCommaOk() {
MetaComparator c = new KeyValue.MetaComparator();
long now = System.currentTimeMillis();
// meta keys values are not quite right. A users can enter illegal values
// from shell when scanning meta.
KeyValue a = new KeyValue(Bytes.toBytes("table,key,with,commas1,1234"), now);
KeyValue b = new KeyValue(Bytes.toBytes("table,key,with,commas2,0123"), now);
assertTrue(c.compare(a, b) < 0);
}
/**
* Tests cases where rows keys have characters below the ','.
* See HBASE-832