You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:06:46 UTC

svn commit: r1181417 - /hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java

Author: nspiegelberg
Date: Tue Oct 11 02:06:45 2011
New Revision: 1181417

URL: http://svn.apache.org/viewvc?rev=1181417&view=rev
Log:
HBASE-3155: HFile.appendMetaBlock() uses wrong comparator

Summary:
appendMetaBlock() was using the wrong comparator. although the variable is
called 'rawComparator', it's actually a normal comparator (KeyComparator) that
defaults to RawComparator if not specified. All meta sorting needs to be done
using the actual Bytes.RAW_COMPARATOR. This happened because >=2 things were
inserted into meta.

Test Plan:
mvn clean test

DiffCamp Revision: 174368
Reviewed By: jgray
CC: jgray
Revert Plan:
OK

Modified:
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java?rev=1181417&r1=1181416&r2=1181417&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java Tue Oct 11 02:06:45 2011
@@ -240,7 +240,7 @@ public class HFile {
     private long valuelength = 0;
 
     // Used to ensure we write in order.
-    private final RawComparator<byte []> rawComparator;
+    private final RawComparator<byte []> comparator;
 
     // A stream made per block written.
     private DataOutputStream out;
@@ -371,7 +371,7 @@ public class HFile {
       this.outputStream = ostream;
       this.closeOutputStream = false;
       this.blocksize = blocksize;
-      this.rawComparator = c == null? Bytes.BYTES_RAWCOMPARATOR: c;
+      this.comparator = c == null? Bytes.BYTES_RAWCOMPARATOR: c;
       this.name = this.outputStream.toString();
       this.compressAlgo = compress == null?
         DEFAULT_COMPRESSION_ALGORITHM: compress;
@@ -473,8 +473,8 @@ public class HFile {
       for (i = 0; i < metaNames.size(); ++i) {
         // stop when the current key is greater than our own
         byte[] cur = metaNames.get(i);
-        if (this.rawComparator.compare(cur, 0, cur.length, key, 0, key.length)
-            > 0) {
+        if (Bytes.BYTES_RAWCOMPARATOR.compare(cur, 0, cur.length,
+            key, 0, key.length) > 0) {
           break;
         }
       }
@@ -604,7 +604,7 @@ public class HFile {
           MAXIMUM_KEY_LENGTH);
       }
       if (this.lastKeyBuffer != null) {
-        int keyComp = this.rawComparator.compare(this.lastKeyBuffer, this.lastKeyOffset,
+        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" +
@@ -715,7 +715,7 @@ public class HFile {
       appendFileInfo(this.fileinfo, FileInfo.AVG_VALUE_LEN,
         Bytes.toBytes(avgValueLen), false);
       appendFileInfo(this.fileinfo, FileInfo.COMPARATOR,
-        Bytes.toBytes(this.rawComparator.getClass().getName()), false);
+        Bytes.toBytes(this.comparator.getClass().getName()), false);
       long pos = o.getPos();
       this.fileinfo.write(o);
       return pos;