Author: stack
Date: Fri Nov 13 06:39:58 2009
New Revision: 835757

URL: http://svn.apache.org/viewvc?rev=835757&view=rev
Log:
HBASE-1841 If multiple of same key in an hfile and they span blocks, may miss 
the earlier keys on a lookup

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/hfile/HFile.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=835757&r1=835756&r2=835757&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Fri Nov 13 06:39:58 2009
@@ -107,6 +107,9 @@
                Java 5
    HBASE-1967  [Transactional] client.TestTransactions.testPutPutScan fails
                sometimes -- Temporary fix
+   HBASE-1841  If multiple of same key in an hfile and they span blocks, may
+               miss the earlier keys on a lookup
+               (Schubert Zhang via Stack)
 
   IMPROVEMENTS
    HBASE-1760  Cleanup TODOs in HTable

Modified: 
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/hfile/HFile.java
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/hfile/HFile.java?rev=835757&r1=835756&r2=835757&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/hfile/HFile.java 
(original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/hfile/HFile.java Fri 
Nov 13 06:39:58 2009
@@ -475,9 +475,11 @@
     public void append(final byte [] key, final int koffset, final int klength,
         final byte [] value, final int voffset, final int vlength)
     throws IOException {
-      checkKey(key, koffset, klength);
+      boolean dupKey = checkKey(key, koffset, klength);
       checkValue(value, voffset, vlength);
-      checkBlockBoundary();
+      if (!dupKey) {
+        checkBlockBoundary();
+      }
       // Write length of key and value and then actual key and value bytes.
       this.out.writeInt(klength);
       this.keylength += klength;
@@ -499,10 +501,13 @@
 
     /*
      * @param key Key to check.
+     * @return the flag of duplicate Key or not
      * @throws IOException
      */
-    private void checkKey(final byte [] key, final int offset, final int 
length)
+    private boolean checkKey(final byte [] key, final int offset, final int 
length)
     throws IOException {
+      boolean dupKey = false;
+      
       if (key == null || length <= 0) {
         throw new IOException("Key cannot be null or empty");
       }
@@ -511,14 +516,18 @@
           MAXIMUM_KEY_LENGTH);
       }
       if (this.lastKeyBuffer != null) {
-        if (this.comparator.compare(this.lastKeyBuffer, this.lastKeyOffset,
-            this.lastKeyLength, key, offset, length) > 0) {
+        int keyComp = this.comparator.compare(this.lastKeyBuffer, 
this.lastKeyOffset,
+            this.lastKeyLength, key, offset, length);        
+        if (keyComp > 0) {
           throw new IOException("Added a key not lexically larger than" +
             " previous key=" + Bytes.toString(key, offset, length) +
             ", lastkey=" + Bytes.toString(this.lastKeyBuffer, 
this.lastKeyOffset,
                 this.lastKeyLength));
+        } else if (keyComp == 0) {
+          dupKey = true;
         }
       }
+      return dupKey;
     }
 
     private void checkValue(final byte [] value, final int offset,


Reply via email to