Author: stack
Date: Mon Sep 12 20:42:14 2011
New Revision: 1169915

URL: http://svn.apache.org/viewvc?rev=1169915&view=rev
Log:
HBASE-4325 Improve error message when using STARTROW for meta scans

Modified:
    hbase/branches/0.90/CHANGES.txt
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java
    hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java

Modified: hbase/branches/0.90/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hbase/branches/0.90/CHANGES.txt?rev=1169915&r1=1169914&r2=1169915&view=diff
==============================================================================
--- hbase/branches/0.90/CHANGES.txt (original)
+++ hbase/branches/0.90/CHANGES.txt Mon Sep 12 20:42:14 2011
@@ -48,6 +48,8 @@ Release 0.90.5 - Unreleased
                for a region (todd)
    HBASE-4313  Refactor TestHBaseFsck to make adding individual hbck tests
                easier (Jonathan Hsieh)
+   HBASE-4325  Improve error message when using STARTROW for meta scans
+               (Jonathan Hsieh)
  
 Release 0.90.4 - August 10, 2011
   BUG FIXES

Modified: 
hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java
URL: 
http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1169915&r1=1169914&r2=1169915&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java 
(original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java Mon 
Sep 12 20:42:14 2011
@@ -1293,12 +1293,16 @@ public class KeyValue implements Writabl
     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;
   }

Modified: 
hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
URL: 
http://svn.apache.org/viewvc/hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java?rev=1169915&r1=1169914&r2=1169915&view=diff
==============================================================================
--- hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java 
(original)
+++ hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java 
Mon Sep 12 20:42:14 2011
@@ -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 TestCa
     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


Reply via email to