diff --git a/CHANGES.txt b/CHANGES.txt
index 43c4f060a80..7fa35219b79 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)
diff --git a/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/src/main/java/org/apache/hadoop/hbase/KeyValue.java
index 7c7bf214168..585c4a895b0 100644
--- a/src/main/java/org/apache/hadoop/hbase/KeyValue.java
+++ b/src/main/java/org/apache/hadoop/hbase/KeyValue.java
@@ -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: '
,,'");
}
return index;
}
diff --git a/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
index 68fff55e438..110b847d0a4 100644
--- a/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
+++ b/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
@@ -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: ',,'", 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