hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject [4/5] hbase git commit: HBASE-10800 - Use CellComparator instead of KVComparator (Ram)
Date Tue, 05 May 2015 06:09:03 GMT
http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java
index 664fcac..63cea49 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java
@@ -23,7 +23,6 @@ import java.io.OutputStream;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
-import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 
@@ -71,7 +70,7 @@ public class KeyValueCodecWithTags implements Codec {
     }
 
     protected Cell parseCell() throws IOException {
-      return KeyValue.iscreate(in);
+      return KeyValueUtil.iscreate(in);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
index 5b049fd..490d160 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
@@ -26,8 +26,6 @@ import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
-import org.apache.hadoop.hbase.KeyValue.SamePrefixComparator;
 import org.apache.hadoop.hbase.KeyValue.Type;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.SettableSequenceId;
@@ -79,6 +77,28 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
     return internalDecodeKeyValues(source, 0, 0, decodingCtx);
   }
 
+  /********************* common prefixes *************************/
+  // Having this as static is fine but if META is having DBE then we should
+  // change this.
+  public static int compareCommonRowPrefix(Cell left, Cell right, int rowCommonPrefix) {
+    return Bytes.compareTo(left.getRowArray(), left.getRowOffset() + rowCommonPrefix,
+        left.getRowLength() - rowCommonPrefix, right.getRowArray(), right.getRowOffset()
+            + rowCommonPrefix, right.getRowLength() - rowCommonPrefix);
+  }
+
+  public static int compareCommonFamilyPrefix(Cell left, Cell right, int familyCommonPrefix) {
+    return Bytes.compareTo(left.getFamilyArray(), left.getFamilyOffset() + familyCommonPrefix,
+        left.getFamilyLength() - familyCommonPrefix, right.getFamilyArray(),
+        right.getFamilyOffset() + familyCommonPrefix, right.getFamilyLength() - familyCommonPrefix);
+  }
+
+  public static int compareCommonQualifierPrefix(Cell left, Cell right, int qualCommonPrefix) {
+    return Bytes.compareTo(left.getQualifierArray(), left.getQualifierOffset() + qualCommonPrefix,
+        left.getQualifierLength() - qualCommonPrefix, right.getQualifierArray(),
+        right.getQualifierOffset() + qualCommonPrefix, right.getQualifierLength()
+            - qualCommonPrefix);
+  }
+
   protected static class SeekerState implements Cell {
     protected ByteBuffer currentBuffer;
     protected TagCompressionContext tagCompressionContext;
@@ -520,17 +540,15 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
       BufferedEncodedSeeker<STATE extends SeekerState>
       implements EncodedSeeker {
     protected HFileBlockDecodingContext decodingCtx;
-    protected final KVComparator comparator;
-    protected final SamePrefixComparator<byte[]> samePrefixComparator;
+    protected final CellComparator comparator;
     protected ByteBuffer currentBuffer;
     protected STATE current = createSeekerState(); // always valid
     protected STATE previous = createSeekerState(); // may not be valid
     protected TagCompressionContext tagCompressionContext = null;
 
-    public BufferedEncodedSeeker(KVComparator comparator,
+    public BufferedEncodedSeeker(CellComparator comparator,
         HFileBlockDecodingContext decodingCtx) {
       this.comparator = comparator;
-      this.samePrefixComparator = comparator;
       this.decodingCtx = decodingCtx;
       if (decodingCtx.getHFileContext().isCompressTags()) {
         try {
@@ -540,7 +558,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         }
       }
     }
-    
+
     protected boolean includesMvcc() {
       return this.decodingCtx.getHFileContext().isIncludesMvcc();
     }
@@ -550,14 +568,11 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
     }
 
     @Override
-    public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
-      return comparator.compareFlatKey(key, offset, length,
-          current.keyBuffer, 0, current.keyLength);
-    }
-
-    @Override
-    public int compareKey(KVComparator comparator, Cell key) {
-      return comparator.compareOnlyKeyPortion(key,
+    public int compareKey(CellComparator comparator, Cell key) {
+      // TODO BufferedEncodedSeeker, instance will be used by single thread alone. So we can
+      // have one KeyValue.KeyOnlyKeyValue instance as instance variable and reuse here and in
+      // seekToKeyInBlock 
+      return comparator.compareKeyIgnoresMvcc(key,
           new KeyValue.KeyOnlyKeyValue(current.keyBuffer, 0, current.keyLength));
     }
 
@@ -685,7 +700,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
       KeyValue.KeyOnlyKeyValue currentCell = new KeyValue.KeyOnlyKeyValue();
       do {
         int comp;
-        if (samePrefixComparator != null) {
+        if (comparator != null) {
           currentCell.setKey(current.keyBuffer, 0, current.keyLength);
           if (current.lastCommonPrefix != 0) {
             // The KV format has row key length also in the byte array. The
@@ -698,9 +713,10 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
           if (current.lastCommonPrefix <= 2) {
             rowCommonPrefix = 0;
           }
-          rowCommonPrefix += CellComparator.findCommonPrefixInRowPart(seekCell, currentCell,
+          rowCommonPrefix += findCommonPrefixInRowPart(seekCell, currentCell,
+              rowCommonPrefix);
+          comp = compareCommonRowPrefix(seekCell, currentCell,
               rowCommonPrefix);
-          comp = CellComparator.compareCommonRowPrefix(seekCell, currentCell, rowCommonPrefix);
           if (comp == 0) {
             comp = compareTypeBytes(seekCell, currentCell);
             if (comp == 0) {
@@ -709,9 +725,9 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
                   0,
                   Math.min(familyCommonPrefix,
                       current.lastCommonPrefix - (3 + currentCell.getRowLength())));
-              familyCommonPrefix += CellComparator.findCommonPrefixInFamilyPart(seekCell,
+              familyCommonPrefix += findCommonPrefixInFamilyPart(seekCell,
                   currentCell, familyCommonPrefix);
-              comp = CellComparator.compareCommonFamilyPrefix(seekCell, currentCell,
+              comp = compareCommonFamilyPrefix(seekCell, currentCell,
                   familyCommonPrefix);
               if (comp == 0) {
                 // subtract the rowkey fixed length and the family key fixed
@@ -722,9 +738,9 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
                         qualCommonPrefix,
                         current.lastCommonPrefix
                             - (3 + currentCell.getRowLength() + currentCell.getFamilyLength())));
-                qualCommonPrefix += CellComparator.findCommonPrefixInQualifierPart(seekCell,
+                qualCommonPrefix += findCommonPrefixInQualifierPart(seekCell,
                     currentCell, qualCommonPrefix);
-                comp = CellComparator.compareCommonQualifierPrefix(seekCell, currentCell,
+                comp = compareCommonQualifierPrefix(seekCell, currentCell,
                     qualCommonPrefix);
                 if (comp == 0) {
                   comp = CellComparator.compareTimestamps(seekCell, currentCell);
@@ -745,7 +761,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
           }
         } else {
           Cell r = new KeyValue.KeyOnlyKeyValue(current.keyBuffer, 0, current.keyLength);
-          comp = comparator.compareOnlyKeyPortion(seekCell, r);
+          comp = comparator.compareKeyIgnoresMvcc(seekCell, r);
         }
         if (comp == 0) { // exact match
           if (seekBefore) {
@@ -798,6 +814,27 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
       return 0;
     }
 
+    private static int findCommonPrefixInRowPart(Cell left, Cell right, int rowCommonPrefix) {
+      return Bytes.findCommonPrefix(left.getRowArray(), right.getRowArray(), left.getRowLength()
+          - rowCommonPrefix, right.getRowLength() - rowCommonPrefix, left.getRowOffset()
+          + rowCommonPrefix, right.getRowOffset() + rowCommonPrefix);
+    }
+
+    private static int findCommonPrefixInFamilyPart(Cell left, Cell right, int familyCommonPrefix) {
+      return Bytes
+          .findCommonPrefix(left.getFamilyArray(), right.getFamilyArray(), left.getFamilyLength()
+              - familyCommonPrefix, right.getFamilyLength() - familyCommonPrefix,
+              left.getFamilyOffset() + familyCommonPrefix, right.getFamilyOffset()
+                  + familyCommonPrefix);
+    }
+
+    private static int findCommonPrefixInQualifierPart(Cell left, Cell right,
+        int qualifierCommonPrefix) {
+      return Bytes.findCommonPrefix(left.getQualifierArray(), right.getQualifierArray(),
+          left.getQualifierLength() - qualifierCommonPrefix, right.getQualifierLength()
+              - qualifierCommonPrefix, left.getQualifierOffset() + qualifierCommonPrefix,
+          right.getQualifierOffset() + qualifierCommonPrefix);
+    }
 
     private void moveToPrevious() {
       if (!previous.isValid()) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
index 6b87c77..6fa01c0 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
@@ -22,9 +22,9 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.util.ByteBufferUtils;
@@ -81,7 +81,7 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
   }
 
   @Override
-  public EncodedSeeker createSeeker(KVComparator comparator,
+  public EncodedSeeker createSeeker(CellComparator comparator,
       final HFileBlockDecodingContext decodingCtx) {
     return new BufferedEncodedSeeker<SeekerState>(comparator, decodingCtx) {
       @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
index 8073e54..f084689 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
@@ -22,7 +22,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.io.hfile.HFileContext;
 
@@ -98,7 +98,7 @@ public interface DataBlockEncoder {
    * @param decodingCtx
    * @return A newly created seeker.
    */
-  EncodedSeeker createSeeker(KVComparator comparator, 
+  EncodedSeeker createSeeker(CellComparator comparator, 
       HFileBlockDecodingContext decodingCtx);
 
   /**
@@ -193,12 +193,8 @@ public interface DataBlockEncoder {
      * Compare the given key against the current key
      * @param comparator
      * @param key
-     * @param offset
-     * @param length
      * @return -1 is the passed key is smaller than the current key, 0 if equal and 1 if greater
      */
-    public int compareKey(KVComparator comparator, byte[] key, int offset, int length);
-
-    public int compareKey(KVComparator comparator, Cell key);
+    public int compareKey(CellComparator comparator, Cell key);
   }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
index 4182dc4..c55400b 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
@@ -22,9 +22,9 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.util.ByteBufferUtils;
@@ -372,7 +372,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
   }
 
   @Override
-  public EncodedSeeker createSeeker(KVComparator comparator,
+  public EncodedSeeker createSeeker(CellComparator comparator,
       HFileBlockDecodingContext decodingCtx) {
     return new BufferedEncodedSeeker<DiffSeekerState>(comparator, decodingCtx) {
       private byte[] familyNameWithSize;

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
index a6f43d0..3000993 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
@@ -22,9 +22,9 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.util.ByteBufferUtils;
@@ -392,7 +392,7 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
   }
 
   @Override
-  public EncodedSeeker createSeeker(KVComparator comparator,
+  public EncodedSeeker createSeeker(CellComparator comparator,
       final HFileBlockDecodingContext decodingCtx) {
     return new BufferedEncodedSeeker<FastDiffSeekerState>(comparator, decodingCtx) {
       private void decode(boolean isFirst) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
index 0286eca..1350366 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
@@ -22,9 +22,9 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.util.ByteBufferUtils;
@@ -196,7 +196,7 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
   }
 
   @Override
-  public EncodedSeeker createSeeker(KVComparator comparator,
+  public EncodedSeeker createSeeker(CellComparator comparator,
       final HFileBlockDecodingContext decodingCtx) {
     return new BufferedEncodedSeeker<SeekerState>(comparator, decodingCtx) {
       @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
index 80bfe5f..0366644 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
@@ -46,6 +46,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.classification.InterfaceStability;
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.io.RawComparator;
 import org.apache.hadoop.io.WritableComparator;
@@ -2088,8 +2089,9 @@ public class Bytes implements Comparable<Bytes> {
    *         ranging from -(N + 1) to N - 1.
    */
   public static int binarySearch(byte[][] arr, byte[] key, int offset, int length) {
-    return binarySearch(arr, key, offset, length, Bytes.BYTES_RAWCOMPARATOR);
+    return binarySearch(arr, key, offset, length, (CellComparator) null);
   }
+
   /**
    * Binary search for keys in indexes.
    *
@@ -2109,18 +2111,41 @@ public class Bytes implements Comparable<Bytes> {
   @Deprecated
   public static int binarySearch(byte [][]arr, byte []key, int offset,
       int length, RawComparator<?> comparator) {
-    if(comparator == null) {
-      comparator = Bytes.BYTES_RAWCOMPARATOR;
-    }
+    return binarySearch(arr, key, offset, length, (CellComparator)null);
+  }
+
+  /**
+   * Binary search for keys in indexes.
+   *
+   * @param arr array of byte arrays to search for
+   * @param key the key you want to find
+   * @param offset the offset in the key you want to find
+   * @param length the length of the key
+   * @param comparator a comparator to compare.
+   * @return zero-based index of the key, if the key is present in the array.
+   *         Otherwise, a value -(i + 1) such that the key is between arr[i -
+   *         1] and arr[i] non-inclusively, where i is in [0, i], if we define
+   *         arr[-1] = -Inf and arr[N] = Inf for an N-element array. The above
+   *         means that this function can return 2N + 1 different values
+   *         ranging from -(N + 1) to N - 1.
+   */
+  public static int binarySearch(byte [][]arr, byte []key, int offset,
+      int length, CellComparator comparator) {
     int low = 0;
     int high = arr.length - 1;
 
+    KeyValue.KeyOnlyKeyValue r = new KeyValue.KeyOnlyKeyValue();
+    r.setKey(key, offset, length);
     while (low <= high) {
       int mid = (low+high) >>> 1;
       // we have to compare in this order, because the comparator order
       // has special logic when the 'left side' is a special key.
-      int cmp = comparator.compare(key, offset, length,
-          arr[mid], 0, arr[mid].length);
+      int cmp = 0;
+      if (comparator != null) {
+        cmp = comparator.compare(r, arr[mid], 0, arr[mid].length);
+      } else {
+        cmp = Bytes.BYTES_RAWCOMPARATOR.compare(key, offset, length, arr[mid], 0, arr[mid].length);
+      }
       // key lives above the midpoint
       if (cmp > 0)
         low = mid + 1;
@@ -2618,4 +2643,56 @@ public class Bytes implements Comparable<Bytes> {
     return b;
   }
 
-}
+  /**
+   * @param b
+   * @param delimiter
+   * @return Index of delimiter having started from start of <code>b</code> moving rightward.
+   */
+  public static int searchDelimiterIndex(final byte[] b, int offset, final int length,
+      final int delimiter) {
+    if (b == null) {
+      throw new IllegalArgumentException("Passed buffer is null");
+    }
+    int result = -1;
+    for (int i = offset; i < length + offset; i++) {
+      if (b[i] == delimiter) {
+        result = i;
+        break;
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Find index of passed delimiter walking from end of buffer backwards.
+   * 
+   * @param b
+   * @param delimiter
+   * @return Index of delimiter
+   */
+  public static int searchDelimiterIndexInReverse(final byte[] b, final int offset,
+      final int length, final int delimiter) {
+    if (b == null) {
+      throw new IllegalArgumentException("Passed buffer is null");
+    }
+    int result = -1;
+    for (int i = (offset + length) - 1; i >= offset; i--) {
+      if (b[i] == delimiter) {
+        result = i;
+        break;
+      }
+    }
+    return result;
+    }
+  
+    public static int findCommonPrefix(byte[] left, byte[] right, int leftLength, int rightLength,
+        int leftOffset, int rightOffset) {
+      int length = Math.min(leftLength, rightLength);
+      int result = 0;
+  
+      while (result < length && left[leftOffset + result] == right[rightOffset + result]) {
+        result++;
+      }
+      return result;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/main/java/org/apache/hadoop/hbase/util/test/RedundantKVGenerator.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/test/RedundantKVGenerator.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/test/RedundantKVGenerator.java
index 52bc4e0..26b513c 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/test/RedundantKVGenerator.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/test/RedundantKVGenerator.java
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Random;
 
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.Tag;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
@@ -284,7 +285,7 @@ public class RedundantKVGenerator {
       }
     }
 
-    Collections.sort(result, KeyValue.COMPARATOR);
+    Collections.sort(result, CellComparator.COMPARATOR);
 
     return result;
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
index 007f826..1f5e206 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
@@ -17,10 +17,8 @@
  */
 package org.apache.hadoop.hbase;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.KeyValue.Type;
 import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -30,6 +28,7 @@ import org.junit.experimental.categories.Category;
 @Category({MiscTests.class, SmallTests.class})
 public class TestCellComparator {
 
+  private CellComparator comparator = CellComparator.COMPARATOR;
   byte[] row1 = Bytes.toBytes("row1");
   byte[] row2 = Bytes.toBytes("row2");
   byte[] row_1_0 = Bytes.toBytes("row10");
@@ -47,7 +46,7 @@ public class TestCellComparator {
   public void testCompareCells() {
     KeyValue kv1 = new KeyValue(row1, fam1, qual1, val);
     KeyValue kv2 = new KeyValue(row2, fam1, qual1, val);
-    assertTrue((CellComparator.compare(kv1, kv2, false)) < 0);
+    assertTrue((comparator.compare(kv1, kv2)) < 0);
 
     kv1 = new KeyValue(row1, fam2, qual1, val);
     kv2 = new KeyValue(row1, fam1, qual1, val);
@@ -55,90 +54,37 @@ public class TestCellComparator {
 
     kv1 = new KeyValue(row1, fam1, qual1, 1l, val);
     kv2 = new KeyValue(row1, fam1, qual1, 2l, val);
-    assertTrue((CellComparator.compare(kv1, kv2, false) > 0));
+    assertTrue((comparator.compare(kv1, kv2) > 0));
 
     kv1 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
     kv2 = new KeyValue(row1, fam1, qual1, 1l, Type.Maximum);
-    assertTrue((CellComparator.compare(kv1, kv2, false) > 0));
+    assertTrue((comparator.compare(kv1, kv2) > 0));
 
     kv1 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
-    kv2 = new KeyValue(row1, fam_1_2, qual1, 1l, Type.Maximum);
-    assertTrue((CellComparator.compareCommonFamilyPrefix(kv1, kv2, 4) < 0));
+    kv2 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
+    assertTrue((CellUtil.equals(kv1, kv2)));
+  }
 
-    kv1 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
-    kv2 = new KeyValue(row_1_0, fam_1_2, qual1, 1l, Type.Maximum);
-    assertTrue((CellComparator.compareCommonRowPrefix(kv1, kv2, 4) < 0));
+  @Test
+  public void testCompareCellWithKey() throws Exception {
+    KeyValue kv1 = new KeyValue(row1, fam1, qual1, val);
+    KeyValue kv2 = new KeyValue(row2, fam1, qual1, val);
+    assertTrue((comparator.compare(kv1, kv2.getKey(), 0, kv2.getKey().length)) < 0);
+
+    kv1 = new KeyValue(row1, fam2, qual1, val);
+    kv2 = new KeyValue(row1, fam1, qual1, val);
+    assertTrue((comparator.compare(kv1, kv2.getKey(), 0, kv2.getKey().length)) > 0);
+
+    kv1 = new KeyValue(row1, fam1, qual1, 1l, val);
+    kv2 = new KeyValue(row1, fam1, qual1, 2l, val);
+    assertTrue((comparator.compare(kv1, kv2.getKey(), 0, kv2.getKey().length)) > 0);
 
-    kv1 = new KeyValue(row1, fam1, qual2, 1l, Type.Put);
+    kv1 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
     kv2 = new KeyValue(row1, fam1, qual1, 1l, Type.Maximum);
-    assertTrue((CellComparator.compareCommonQualifierPrefix(kv1, kv2, 4) > 0));
+    assertTrue((comparator.compare(kv1, kv2.getKey(), 0, kv2.getKey().length)) > 0);
 
     kv1 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
     kv2 = new KeyValue(row1, fam1, qual1, 1l, Type.Put);
-    assertTrue((CellComparator.equals(kv1, kv2)));
-  }
-
-  @Test
-  public void testGetShortMidpoint() {
-    KeyValue.KVComparator comparator = new KeyValue.KVComparator();
-
-    Cell left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    Cell right = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    Cell mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) <= 0);
-    assertTrue(CellComparator.compare(mid, right, true) <= 0);
-
-    left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) <= 0);
-
-    left = CellUtil.createCell(Bytes.toBytes("g"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("i"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) <= 0);
-
-    left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("bbbbbbb"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) < 0);
-    assertEquals(1, (int)mid.getRowLength());
-
-    left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("a"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) <= 0);
-
-    left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("aaaaaaaa"), Bytes.toBytes("b"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) < 0);
-    assertEquals(2, (int)mid.getFamilyLength());
-
-    left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("aaaaaaaaa"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) < 0);
-    assertEquals(2, (int)mid.getQualifierLength());
-
-    left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("b"));
-    mid = CellComparator.getMidpoint(comparator, left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) <= 0);
-    assertEquals(1, (int)mid.getQualifierLength());
-
-    // Assert that if meta comparator, it returns the right cell -- i.e.  no optimization done.
-    left = CellUtil.createCell(Bytes.toBytes("g"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    right = CellUtil.createCell(Bytes.toBytes("i"), Bytes.toBytes("a"), Bytes.toBytes("a"));
-    mid = CellComparator.getMidpoint(new KeyValue.MetaComparator(), left, right);
-    assertTrue(CellComparator.compare(left, mid, true) < 0);
-    assertTrue(CellComparator.compare(mid, right, true) == 0);
+    assertTrue((comparator.compare(kv1, kv2.getKey(), 0, kv2.getKey().length)) == 0);
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
index f1b46c9..ab3f89b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
@@ -23,7 +23,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -34,8 +33,6 @@ 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;
 
@@ -109,24 +106,24 @@ public class TestKeyValue extends TestCase {
     final byte [] qf = Bytes.toBytes("umn");
     KeyValue aaa = new KeyValue(a, fam, qf, a);
     KeyValue bbb = new KeyValue(b, fam, qf, b);
-    assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
-    assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
+    assertTrue(CellComparator.COMPARATOR.compare(aaa, bbb) < 0);
+    assertTrue(CellComparator.COMPARATOR.compare(bbb, aaa) > 0);
     // Compare breaks if passed same ByteBuffer as both left and right arguments.
-    assertTrue(KeyValue.COMPARATOR.compare(bbb, bbb) == 0);
-    assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
+    assertTrue(CellComparator.COMPARATOR.compare(bbb, bbb) == 0);
+    assertTrue(CellComparator.COMPARATOR.compare(aaa, aaa) == 0);
     // Do compare with different timestamps.
     aaa = new KeyValue(a, fam, qf, 1, a);
     bbb = new KeyValue(a, fam, qf, 2, a);
-    assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) > 0);
-    assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) < 0);
-    assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
+    assertTrue(CellComparator.COMPARATOR.compare(aaa, bbb) > 0);
+    assertTrue(CellComparator.COMPARATOR.compare(bbb, aaa) < 0);
+    assertTrue(CellComparator.COMPARATOR.compare(aaa, aaa) == 0);
     // Do compare with different types.  Higher numbered types -- Delete
     // should sort ahead of lower numbers; i.e. Put
     aaa = new KeyValue(a, fam, qf, 1, KeyValue.Type.Delete, a);
     bbb = new KeyValue(a, fam, qf, 1, a);
-    assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
-    assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
-    assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
+    assertTrue(CellComparator.COMPARATOR.compare(aaa, bbb) < 0);
+    assertTrue(CellComparator.COMPARATOR.compare(bbb, aaa) > 0);
+    assertTrue(CellComparator.COMPARATOR.compare(aaa, aaa) == 0);
   }
 
   public void testMoreComparisons() throws Exception {
@@ -137,7 +134,7 @@ public class TestKeyValue extends TestCase {
         Bytes.toBytes("TestScanMultipleVersions,row_0500,1236020145502"), now);
     KeyValue bbb = new KeyValue(
         Bytes.toBytes("TestScanMultipleVersions,,99999999999999"), now);
-    KVComparator c = new KeyValue.MetaComparator();
+    CellComparator c = CellComparator.META_COMPARATOR;
     assertTrue(c.compare(bbb, aaa) < 0);
 
     KeyValue aaaa = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,,1236023996656"),
@@ -152,13 +149,13 @@ public class TestKeyValue extends TestCase {
         Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236034574912L,
         (byte[])null);
     assertTrue(c.compare(x, y) < 0);
-    comparisons(new KeyValue.MetaComparator());
-    comparisons(new KeyValue.KVComparator());
-    metacomparisons(new KeyValue.MetaComparator());
+    comparisons(CellComparator.META_COMPARATOR);
+    comparisons(CellComparator.COMPARATOR);
+    metacomparisons(CellComparator.META_COMPARATOR);
   }
 
   public void testMetaComparatorTableKeysWithCommaOk() {
-    MetaComparator c = new KeyValue.MetaComparator();
+    CellComparator c = CellComparator.META_COMPARATOR;
     long now = System.currentTimeMillis();
     // meta keys values are not quite right.  A users can enter illegal values
     // from shell when scanning meta.
@@ -179,17 +176,17 @@ public class TestKeyValue extends TestCase {
       Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null);
     KeyValue rowB = new KeyValue(Bytes.toBytes("testtable,www.hbase.org/%20,99999"),
         Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null);
-    assertTrue(KeyValue.META_COMPARATOR.compare(rowA, rowB) < 0);
+    assertTrue(CellComparator.META_COMPARATOR.compare(rowA, rowB) < 0);
 
     rowA = new KeyValue(Bytes.toBytes("testtable,,1234"), Bytes.toBytes("fam"),
         Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null);
     rowB = new KeyValue(Bytes.toBytes("testtable,$www.hbase.org/,99999"),
         Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null);
-    assertTrue(KeyValue.META_COMPARATOR.compare(rowA, rowB) < 0);
+    assertTrue(CellComparator.META_COMPARATOR.compare(rowA, rowB) < 0);
 
   }
 
-  private void metacomparisons(final KeyValue.MetaComparator c) {
+  private void metacomparisons(final CellComparator c) {
     long now = System.currentTimeMillis();
     assertTrue(c.compare(new KeyValue(
         Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now),
@@ -206,7 +203,7 @@ public class TestKeyValue extends TestCase {
           Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now)) > 0);
   }
 
-  private void comparisons(final KeyValue.KVComparator c) {
+  private void comparisons(final CellComparator c) {
     long now = System.currentTimeMillis();
     assertTrue(c.compare(new KeyValue(
         Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now),
@@ -223,7 +220,7 @@ public class TestKeyValue extends TestCase {
   }
 
   public void testBinaryKeys() throws Exception {
-    Set<KeyValue> set = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
+    Set<KeyValue> set = new TreeSet<KeyValue>(CellComparator.COMPARATOR);
     final byte [] fam = Bytes.toBytes("col");
     final byte [] qf = Bytes.toBytes("umn");
     final byte [] nb = new byte[0];
@@ -249,7 +246,7 @@ public class TestKeyValue extends TestCase {
     }
     assertTrue(assertion);
     // Make set with good comparator
-    set = new TreeSet<KeyValue>(new KeyValue.MetaComparator());
+    set = new TreeSet<KeyValue>(CellComparator.META_COMPARATOR);
     Collections.addAll(set, keys);
     count = 0;
     for (KeyValue k: set) {
@@ -271,7 +268,7 @@ public class TestKeyValue extends TestCase {
   private final byte[] qualA = Bytes.toBytes("qfA");
   private final byte[] qualB = Bytes.toBytes("qfB");
 
-  private void assertKVLess(KeyValue.KVComparator c,
+  private void assertKVLess(CellComparator c,
                             KeyValue less,
                             KeyValue greater) {
     int cmp = c.compare(less,greater);
@@ -280,20 +277,16 @@ public class TestKeyValue extends TestCase {
     assertTrue(cmp > 0);
   }
 
-  private void assertKVLessWithoutRow(KeyValue.KVComparator c, int common, KeyValue less,
+  private void assertKVLessWithoutRow(CellComparator c, int common, KeyValue less,
       KeyValue greater) {
-    int cmp = c.compareIgnoringPrefix(common, less.getBuffer(), less.getOffset()
-        + KeyValue.ROW_OFFSET, less.getKeyLength(), greater.getBuffer(),
-        greater.getOffset() + KeyValue.ROW_OFFSET, greater.getKeyLength());
+    int cmp = c.compare(less, greater);
     assertTrue(cmp < 0);
-    cmp = c.compareIgnoringPrefix(common, greater.getBuffer(), greater.getOffset()
-        + KeyValue.ROW_OFFSET, greater.getKeyLength(), less.getBuffer(),
-        less.getOffset() + KeyValue.ROW_OFFSET, less.getKeyLength());
+    cmp = c.compare(greater, less);
     assertTrue(cmp > 0);
   }
 
   public void testCompareWithoutRow() {
-    final KeyValue.KVComparator c = KeyValue.COMPARATOR;
+    final CellComparator c = CellComparator.COMPARATOR;
     byte[] row = Bytes.toBytes("row");
 
     byte[] fa = Bytes.toBytes("fa");
@@ -340,7 +333,7 @@ public class TestKeyValue extends TestCase {
   }
 
   public void testFirstLastOnRow() {
-    final KVComparator c = KeyValue.COMPARATOR;
+    final CellComparator c = CellComparator.COMPARATOR;
     long ts = 1;
     byte[] bufferA = new byte[128];
     int offsetA = 0;
@@ -414,7 +407,7 @@ public class TestKeyValue extends TestCase {
     byte[] tmpArr = new byte[initialPadding + endingPadding + keyLen];
     System.arraycopy(kv.getBuffer(), kv.getKeyOffset(), tmpArr,
         initialPadding, keyLen);
-    KeyValue kvFromKey = KeyValue.createKeyValueFromKey(tmpArr, initialPadding,
+    KeyValue kvFromKey = KeyValueUtil.createKeyValueFromKey(tmpArr, initialPadding,
         keyLen);
     assertEquals(keyLen, kvFromKey.getKeyLength());
     assertEquals(KeyValue.ROW_OFFSET + keyLen, kvFromKey.getBuffer().length);
@@ -439,82 +432,6 @@ public class TestKeyValue extends TestCase {
     assertEquals(12345L, time2);
   }
 
-  /**
-   * See HBASE-7845
-   */
-  public void testGetShortMidpointKey() {
-    final KVComparator keyComparator = KeyValue.COMPARATOR;
-    //verify that faked shorter rowkey could be generated
-    long ts = 5;
-    KeyValue kv1 = new KeyValue(Bytes.toBytes("the quick brown fox"), family, qualA, ts, Type.Put);
-    KeyValue kv2 = new KeyValue(Bytes.toBytes("the who test text"), family, qualA, ts, Type.Put);
-    byte[] newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(keyComparator.compareFlatKey(newKey, kv2.getKey()) < 0);
-    short newRowLength = Bytes.toShort(newKey, 0);
-    byte[] expectedArray = Bytes.toBytes("the r");
-    Bytes.equals(newKey, KeyValue.ROW_LENGTH_SIZE, newRowLength, expectedArray, 0,
-      expectedArray.length);
-
-    //verify: same with "row + family + qualifier", return rightKey directly
-    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 5, Type.Put);
-    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 0, Type.Put);
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
-    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(keyComparator.compareFlatKey(newKey, kv2.getKey()) == 0);
-    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, -5, Type.Put);
-    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, -10, Type.Put);
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
-    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(keyComparator.compareFlatKey(newKey, kv2.getKey()) == 0);
-
-    // verify: same with row, different with qualifier
-    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 5, Type.Put);
-    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualB, 5, Type.Put);
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
-    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(keyComparator.compareFlatKey(newKey, kv2.getKey()) < 0);
-    KeyValue newKeyValue = KeyValue.createKeyValueFromKey(newKey);
-    assertTrue(Arrays.equals(newKeyValue.getFamily(),family));
-    assertTrue(Arrays.equals(newKeyValue.getQualifier(),qualB));
-    assertTrue(newKeyValue.getTimestamp() == HConstants.LATEST_TIMESTAMP);
-    assertTrue(newKeyValue.getTypeByte() == Type.Maximum.getCode());
-
-    //verify metaKeyComparator's getShortMidpointKey output
-    final KVComparator metaKeyComparator = KeyValue.META_COMPARATOR;
-    kv1 = new KeyValue(Bytes.toBytes("ilovehbase123"), family, qualA, 5, Type.Put);
-    kv2 = new KeyValue(Bytes.toBytes("ilovehbase234"), family, qualA, 0, Type.Put);
-    newKey = metaKeyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(metaKeyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(metaKeyComparator.compareFlatKey(newKey, kv2.getKey()) == 0);
-
-    //verify common fix scenario
-    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, ts, Type.Put);
-    kv2 = new KeyValue(Bytes.toBytes("ilovehbaseandhdfs"), family, qualA, ts, Type.Put);
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
-    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(keyComparator.compareFlatKey(newKey, kv2.getKey()) < 0);
-    newRowLength = Bytes.toShort(newKey, 0);
-    expectedArray = Bytes.toBytes("ilovehbasea");
-    Bytes.equals(newKey, KeyValue.ROW_LENGTH_SIZE, newRowLength, expectedArray, 0,
-      expectedArray.length);
-    //verify only 1 offset scenario
-    kv1 = new KeyValue(Bytes.toBytes("100abcdefg"), family, qualA, ts, Type.Put);
-    kv2 = new KeyValue(Bytes.toBytes("101abcdefg"), family, qualA, ts, Type.Put);
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
-    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
-    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
-    assertTrue(keyComparator.compareFlatKey(newKey, kv2.getKey()) < 0);
-    newRowLength = Bytes.toShort(newKey, 0);
-    expectedArray = Bytes.toBytes("101");
-    Bytes.equals(newKey, KeyValue.ROW_LENGTH_SIZE, newRowLength, expectedArray, 0,
-      expectedArray.length);
-  }
-
   public void testKVsWithTags() {
     byte[] row = Bytes.toBytes("myRow");
     byte[] cf = Bytes.toBytes("myCF");
@@ -577,7 +494,7 @@ public class TestKeyValue extends TestCase {
   }
   
   public void testMetaKeyComparator() {
-    MetaComparator c = new KeyValue.MetaComparator();
+    CellComparator c = CellComparator.META_COMPARATOR;
     long now = System.currentTimeMillis();
 
     KeyValue a = new KeyValue(Bytes.toBytes("table1"), now);
@@ -652,9 +569,9 @@ public class TestKeyValue extends TestCase {
     KeyValueUtil.oswrite(mkvA2, os, true);
     DataInputStream is = new DataInputStream(new ByteArrayInputStream(
         byteArrayOutputStream.toByteArray()));
-    KeyValue deSerKV1 = KeyValue.iscreate(is);
+    KeyValue deSerKV1 = KeyValueUtil.iscreate(is);
     assertTrue(kvA1.equals(deSerKV1));
-    KeyValue deSerKV2 = KeyValue.iscreate(is);
+    KeyValue deSerKV2 = KeyValueUtil.iscreate(is);
     assertTrue(kvA2.equals(deSerKV2));
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
index 922de6f..1ce4bf6 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
@@ -29,6 +29,7 @@ import java.io.IOException;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -112,13 +113,13 @@ public class TestCellCodec {
     Codec.Decoder decoder = codec.getDecoder(dis);
     assertTrue(decoder.advance());
     Cell c = decoder.current();
-    assertTrue(CellComparator.equals(c, kv1));
+    assertTrue(CellUtil.equals(c, kv1));
     assertTrue(decoder.advance());
     c = decoder.current();
-    assertTrue(CellComparator.equals(c, kv2));
+    assertTrue(CellUtil.equals(c, kv2));
     assertTrue(decoder.advance());
     c = decoder.current();
-    assertTrue(CellComparator.equals(c, kv3));
+    assertTrue(CellUtil.equals(c, kv3));
     assertFalse(decoder.advance());
     dis.close();
     assertEquals(offset, cis.getCount());

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
index 30f2f00..beff87a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
@@ -29,7 +29,7 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.Tag;
@@ -76,7 +76,7 @@ public class TestCellCodecWithTags {
     Codec.Decoder decoder = codec.getDecoder(dis);
     assertTrue(decoder.advance());
     Cell c = decoder.current();
-    assertTrue(CellComparator.equals(c, cell1));
+    assertTrue(CellUtil.equals(c, cell1));
     List<Tag> tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
     assertEquals(2, tags.size());
     Tag tag = tags.get(0);
@@ -87,7 +87,7 @@ public class TestCellCodecWithTags {
     assertTrue(Bytes.equals(Bytes.toBytes("teststring2"), tag.getValue()));
     assertTrue(decoder.advance());
     c = decoder.current();
-    assertTrue(CellComparator.equals(c, cell2));
+    assertTrue(CellUtil.equals(c, cell2));
     tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
     assertEquals(1, tags.size());
     tag = tags.get(0);
@@ -95,7 +95,7 @@ public class TestCellCodecWithTags {
     assertTrue(Bytes.equals(Bytes.toBytes("teststring3"), tag.getValue()));
     assertTrue(decoder.advance());
     c = decoder.current();
-    assertTrue(CellComparator.equals(c, cell3));
+    assertTrue(CellUtil.equals(c, cell3));
     tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
     assertEquals(3, tags.size());
     tag = tags.get(0);

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
index 007647a..04fb9a9 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
@@ -29,7 +29,7 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.Tag;
@@ -76,7 +76,7 @@ public class TestKeyValueCodecWithTags {
     Codec.Decoder decoder = codec.getDecoder(dis);
     assertTrue(decoder.advance());
     Cell c = decoder.current();
-    assertTrue(CellComparator.equals(c, kv1));
+    assertTrue(CellUtil.equals(c, kv1));
     List<Tag> tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
     assertEquals(2, tags.size());
     Tag tag = tags.get(0);
@@ -87,7 +87,7 @@ public class TestKeyValueCodecWithTags {
     assertTrue(Bytes.equals(Bytes.toBytes("teststring2"), tag.getValue()));
     assertTrue(decoder.advance());
     c = decoder.current();
-    assertTrue(CellComparator.equals(c, kv2));
+    assertTrue(CellUtil.equals(c, kv2));
     tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
     assertEquals(1, tags.size());
     tag = tags.get(0);
@@ -95,7 +95,7 @@ public class TestKeyValueCodecWithTags {
     assertTrue(Bytes.equals(Bytes.toBytes("teststring3"), tag.getValue()));
     assertTrue(decoder.advance());
     c = decoder.current();
-    assertTrue(CellComparator.equals(c, kv3));
+    assertTrue(CellUtil.equals(c, kv3));
     tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
     assertEquals(3, tags.size());
     tag = tags.get(0);

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
index aa13223..adb87fd 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
@@ -285,33 +285,25 @@ public class TestBytes extends TestCase {
     byte [] key4 = {0};
     byte [] key5 = {2};
 
-    assertEquals(1, Bytes.binarySearch(arr, key1, 0, 1,
-      Bytes.BYTES_RAWCOMPARATOR));
-    assertEquals(0, Bytes.binarySearch(arr, key1, 1, 1,
-      Bytes.BYTES_RAWCOMPARATOR));
+    assertEquals(1, Bytes.binarySearch(arr, key1, 0, 1));
+    assertEquals(0, Bytes.binarySearch(arr, key1, 1, 1));
     assertEquals(-(2+1), Arrays.binarySearch(arr, key2_2,
       Bytes.BYTES_COMPARATOR));
-    assertEquals(-(2+1), Bytes.binarySearch(arr, key2, 0, 1,
-      Bytes.BYTES_RAWCOMPARATOR));
-    assertEquals(4, Bytes.binarySearch(arr, key2, 1, 1,
-      Bytes.BYTES_RAWCOMPARATOR));
-    assertEquals(2, Bytes.binarySearch(arr, key3, 0, 1,
-      Bytes.BYTES_RAWCOMPARATOR));
-    assertEquals(5, Bytes.binarySearch(arr, key3, 1, 1,
-      Bytes.BYTES_RAWCOMPARATOR));
+    assertEquals(-(2+1), Bytes.binarySearch(arr, key2, 0, 1));
+    assertEquals(4, Bytes.binarySearch(arr, key2, 1, 1));
+    assertEquals(2, Bytes.binarySearch(arr, key3, 0, 1));
+    assertEquals(5, Bytes.binarySearch(arr, key3, 1, 1));
     assertEquals(-1,
-      Bytes.binarySearch(arr, key4, 0, 1, Bytes.BYTES_RAWCOMPARATOR));
+      Bytes.binarySearch(arr, key4, 0, 1));
     assertEquals(-2,
-      Bytes.binarySearch(arr, key5, 0, 1, Bytes.BYTES_RAWCOMPARATOR));
+      Bytes.binarySearch(arr, key5, 0, 1));
 
     // Search for values to the left and to the right of each item in the array.
     for (int i = 0; i < arr.length; ++i) {
       assertEquals(-(i + 1), Bytes.binarySearch(arr,
-          new byte[] { (byte) (arr[i][0] - 1) }, 0, 1,
-          Bytes.BYTES_RAWCOMPARATOR));
+          new byte[] { (byte) (arr[i][0] - 1) }, 0, 1));
       assertEquals(-(i + 2), Bytes.binarySearch(arr,
-          new byte[] { (byte) (arr[i][0] + 1) }, 0, 1,
-          Bytes.BYTES_RAWCOMPARATOR));
+          new byte[] { (byte) (arr[i][0] + 1) }, 0, 1));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
----------------------------------------------------------------------
diff --git a/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java b/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
index a548b8a..e6f1b3e 100644
--- a/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
+++ b/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -52,6 +53,6 @@ public class TestPBCell {
     pbr.setPosition(0);
     decoded = CODEC.decode(pbr);
     assertEquals(encodedLength, pbr.getPosition());
-    assertTrue(CellComparator.equals(cell, ProtobufUtil.toCell(decoded)));
+    assertTrue(CellUtil.equals(cell, ProtobufUtil.toCell(decoded)));
   }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestImportTsv.java
----------------------------------------------------------------------
diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestImportTsv.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestImportTsv.java
index 4c27ec8..657217f 100644
--- a/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestImportTsv.java
+++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestImportTsv.java
@@ -36,6 +36,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.IntegrationTestingUtility;
 import org.apache.hadoop.hbase.testclassification.IntegrationTests;
@@ -78,7 +79,7 @@ public class IntegrationTestImportTsv implements Configurable, Tool {
       "row10\t1\tc1\tc2\n";
 
   protected static final Set<KeyValue> simple_expected =
-      new TreeSet<KeyValue>(KeyValue.COMPARATOR) {
+      new TreeSet<KeyValue>(CellComparator.COMPARATOR) {
     private static final long serialVersionUID = 1L;
     {
       byte[] family = Bytes.toBytes("d");
@@ -157,7 +158,7 @@ public class IntegrationTestImportTsv implements Configurable, Tool {
           assertTrue(
             format("Scan produced surprising result. expected: <%s>, actual: %s",
               expected, actual),
-            KeyValue.COMPARATOR.compare(expected, actual) == 0);
+            CellComparator.COMPARATOR.compare(expected, actual) == 0);
         }
       }
       assertFalse("Did not consume all expected values.", expectedIt.hasNext());

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java
index afcb526..f44a445 100644
--- a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java
+++ b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java
@@ -25,10 +25,9 @@ import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
-import org.apache.hadoop.hbase.KeyValue.MetaComparator;
-import org.apache.hadoop.hbase.KeyValue.RawBytesComparator;
+import org.apache.hadoop.hbase.CellComparator.MetaCellComparator;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.codec.prefixtree.decode.DecoderFactory;
 import org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArraySearcher;
@@ -58,7 +57,7 @@ import org.apache.hadoop.io.WritableUtils;
  * created and recycled by static PtEncoderFactory and PtDecoderFactory.
  */
 @InterfaceAudience.Private
-public class PrefixTreeCodec implements DataBlockEncoder{
+public class PrefixTreeCodec implements DataBlockEncoder {
 
   /**
    * no-arg constructor for reflection
@@ -150,12 +149,11 @@ public class PrefixTreeCodec implements DataBlockEncoder{
    * the way to this point.
    */
   @Override
-  public EncodedSeeker createSeeker(KVComparator comparator, HFileBlockDecodingContext decodingCtx) {
-    if (comparator instanceof RawBytesComparator){
-      throw new IllegalArgumentException("comparator must be KeyValue.KeyComparator");
-    } else if (comparator instanceof MetaComparator){
-      throw new IllegalArgumentException("DataBlockEncoding.PREFIX_TREE not compatible with hbase:meta "
-          +"table");
+  public EncodedSeeker createSeeker(CellComparator comparator,
+      HFileBlockDecodingContext decodingCtx) {
+    if (comparator instanceof MetaCellComparator) {
+      throw new IllegalArgumentException(
+          "DataBlockEncoding.PREFIX_TREE not compatible with hbase:meta " + "table");
     }
 
     return new PrefixTreeSeeker(decodingCtx.getHFileContext().isIncludesMvcc());

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
index d9852be..73e8ab4 100644
--- a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
+++ b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
@@ -21,9 +21,9 @@ package org.apache.hadoop.hbase.codec.prefixtree;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.KeyValue.Type;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.SettableSequenceId;
@@ -213,13 +213,6 @@ public class PrefixTreeSeeker implements EncodedSeeker {
   }
 
   @Override
-  public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
-    // can't optimize this, make a copy of the key
-    ByteBuffer bb = getKeyDeepCopy();
-    return comparator.compareFlatKey(key, offset, length, bb.array(), bb.arrayOffset(), bb.limit());
-  }
-
-  @Override
   public int seekToKeyInBlock(Cell key, boolean forceBeforeOnExactMatch) {
     if (USE_POSITION_BEFORE) {
       return seekToOrBeforeUsingPositionAtOrBefore(key, forceBeforeOnExactMatch);
@@ -229,7 +222,8 @@ public class PrefixTreeSeeker implements EncodedSeeker {
   }
 
   @Override
-  public int compareKey(KVComparator comparator, Cell key) {
+  public int compareKey(CellComparator comparator, Cell key) {
+    // can't optimize this, make a copy of the key
     ByteBuffer bb = getKeyDeepCopy();
     return comparator.compare(key,
         new KeyValue.KeyOnlyKeyValue(bb.array(), bb.arrayOffset(), bb.limit()));

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeArrayScanner.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeArrayScanner.java b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeArrayScanner.java
index cb7eeea..1e91eb2 100644
--- a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeArrayScanner.java
+++ b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeArrayScanner.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.codec.prefixtree.decode;
 
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.CellScanner;
 import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
 import org.apache.hadoop.hbase.codec.prefixtree.decode.column.ColumnReader;
@@ -61,7 +60,6 @@ public class PrefixTreeArrayScanner extends PrefixTreeCell implements CellScanne
   protected boolean nubCellsRemain;
   protected int currentCellIndex;
 
-
   /*********************** construct ******************************/
 
   // pass in blockMeta so we can initialize buffers big enough for all cells in the block
@@ -420,7 +418,7 @@ public class PrefixTreeArrayScanner extends PrefixTreeCell implements CellScanne
 
   protected int populateNonRowFieldsAndCompareTo(int cellNum, Cell key) {
     populateNonRowFields(cellNum);
-    return CellComparator.compare(this, key, true);
+    return comparator.compareKeyIgnoresMvcc(this, key);
   }
 
   protected void populateFirstNonRowFields() {

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeCell.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeCell.java b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeCell.java
index 97eed62..f06634c 100644
--- a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeCell.java
+++ b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/decode/PrefixTreeCell.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.SettableSequenceId;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.util.Bytes;
 
 /**
  * As the PrefixTreeArrayScanner moves through the tree bytes, it changes the values in the fields
@@ -33,6 +34,8 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
  */
 @InterfaceAudience.Private
 public class PrefixTreeCell implements Cell, SettableSequenceId, Comparable<Cell> {
+  // Create a reference here?  Can be removed too
+  protected CellComparator comparator = CellComparator.COMPARATOR;
 
   /********************** static **********************/
 
@@ -91,19 +94,35 @@ public class PrefixTreeCell implements Cell, SettableSequenceId, Comparable<Cell
       return false;
     }
     //Temporary hack to maintain backwards compatibility with KeyValue.equals
-    return CellComparator.equalsIgnoreMvccVersion(this, (Cell)obj);
+    return CellUtil.equalsIgnoreMvccVersion(this, (Cell)obj);
 
     //TODO return CellComparator.equals(this, (Cell)obj);//see HBASE-6907
   }
 
   @Override
   public int hashCode() {
-    return CellComparator.hashCodeIgnoreMvcc(this);
+    return calculateHashForKey(this);
+  }
+
+  private int calculateHashForKey(Cell cell) {
+    // pre-calculate the 3 hashes made of byte ranges
+    int rowHash = Bytes.hashCode(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
+    int familyHash = Bytes.hashCode(cell.getFamilyArray(), cell.getFamilyOffset(),
+        cell.getFamilyLength());
+    int qualifierHash = Bytes.hashCode(cell.getQualifierArray(), cell.getQualifierOffset(),
+        cell.getQualifierLength());
+
+    // combine the 6 sub-hashes
+    int hash = 31 * rowHash + familyHash;
+    hash = 31 * hash + qualifierHash;
+    hash = 31 * hash + (int) cell.getTimestamp();
+    hash = 31 * hash + cell.getTypeByte();
+    return hash;
   }
 
   @Override
   public int compareTo(Cell other) {
-    return CellComparator.compare(this, other, false);
+    return comparator.compare(this, other);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/BaseTestRowData.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/BaseTestRowData.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/BaseTestRowData.java
index a895f9f..89ceacf 100644
--- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/BaseTestRowData.java
+++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/BaseTestRowData.java
@@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.codec.prefixtree.row;
 
 import java.util.List;
 
-import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher;
@@ -37,7 +37,7 @@ public abstract class BaseTestRowData implements TestRowData {
     for (int i = 1; i < inputs.size(); ++i) {
       KeyValue lastKv = inputs.get(i - 1);
       KeyValue kv = inputs.get(i);
-      if (!CellComparator.equalsRow(lastKv, kv)) {
+      if (!CellUtil.matchingRow(lastKv, kv)) {
         rowStartIndexes.add(i);
       }
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestPrefixTreeSearcher.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestPrefixTreeSearcher.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestPrefixTreeSearcher.java
index 98513da..c005c17 100644
--- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestPrefixTreeSearcher.java
+++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestPrefixTreeSearcher.java
@@ -26,7 +26,7 @@ import java.util.Collection;
 import java.util.List;
 
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.testclassification.MiscTests;
@@ -85,7 +85,7 @@ public class TestPrefixTreeSearcher {
         // check all 3 permutations of equals()
         Assert.assertEquals(inputCell, outputCell);
         Assert.assertEquals(outputCell, inputCell);
-        Assert.assertTrue(CellComparator.equals(inputCell, outputCell));
+        Assert.assertTrue(CellUtil.equals(inputCell, outputCell));
       }
       Assert.assertEquals(rows.getInputs().size(), i + 1);
     } finally {
@@ -124,7 +124,7 @@ public class TestPrefixTreeSearcher {
         boolean hit = searcher.positionAt(kv);
         Assert.assertTrue(hit);
         Cell foundKv = searcher.current();
-        Assert.assertTrue(CellComparator.equals(kv, foundKv));
+        Assert.assertTrue(CellUtil.equals(kv, foundKv));
       }
     } finally {
       DecoderFactory.checkIn(searcher);

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataNumberStrings.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataNumberStrings.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataNumberStrings.java
index e508c2c..5393136 100644
--- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataNumberStrings.java
+++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataNumberStrings.java
@@ -50,7 +50,7 @@ public class TestRowDataNumberStrings extends BaseTestRowData{
 
       d.add(new KeyValue(row, family, column, 0L, Type.Put, value));
     }
-    Collections.sort(d, new CellComparator());
+    Collections.sort(d, CellComparator.COMPARATOR);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSearcherRowMiss.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSearcherRowMiss.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSearcherRowMiss.java
index edea305..916d7f5 100644
--- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSearcherRowMiss.java
+++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSearcherRowMiss.java
@@ -22,7 +22,7 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.codec.prefixtree.row.BaseTestRowData;
 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition;
@@ -73,11 +73,11 @@ public class TestRowDataSearcherRowMiss extends BaseTestRowData{
       throw new RuntimeException(e);
     }
     Cell first = searcher.current();
-    Assert.assertTrue(CellComparator.equals(d.get(0), first));
+    Assert.assertTrue(CellUtil.equals(d.get(0), first));
 
     //test first cell in second row
     Assert.assertTrue(searcher.positionAt(d.get(1)));
-    Assert.assertTrue(CellComparator.equals(d.get(1), searcher.current()));
+    Assert.assertTrue(CellUtil.equals(d.get(1), searcher.current()));
 
     testBetween1and2(searcher);
     testBetween2and3(searcher);
@@ -99,12 +99,12 @@ public class TestRowDataSearcherRowMiss extends BaseTestRowData{
     //test atOrBefore
     p = searcher.positionAtOrBefore(betweenAAndAAA);
     Assert.assertEquals(CellScannerPosition.BEFORE, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(1)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(1)));
 
     //test atOrAfter
     p = searcher.positionAtOrAfter(betweenAAndAAA);
     Assert.assertEquals(CellScannerPosition.AFTER, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(2)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(2)));
   }
 
   private void testBetween2and3(CellSearcher searcher){
@@ -117,12 +117,12 @@ public class TestRowDataSearcherRowMiss extends BaseTestRowData{
     //test atOrBefore
     p = searcher.positionAtOrBefore(betweenAAAndB);
     Assert.assertEquals(CellScannerPosition.BEFORE, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(2)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(2)));
 
     //test atOrAfter
     p = searcher.positionAtOrAfter(betweenAAAndB);
     Assert.assertEquals(CellScannerPosition.AFTER, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(3)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(3)));
   }
 
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSimple.java
----------------------------------------------------------------------
diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSimple.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSimple.java
index 6c3750a..62234fc 100644
--- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSimple.java
+++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/data/TestRowDataSimple.java
@@ -22,7 +22,7 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellComparator;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.codec.prefixtree.row.BaseTestRowData;
 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition;
@@ -73,11 +73,11 @@ public class TestRowDataSimple extends BaseTestRowData {
       throw new RuntimeException(e);
     }
     Cell first = searcher.current();
-    Assert.assertTrue(CellComparator.equals(d.get(0), first));
+    Assert.assertTrue(CellUtil.equals(d.get(0), first));
 
     // test first cell in second row
     Assert.assertTrue(searcher.positionAt(d.get(3)));
-    Assert.assertTrue(CellComparator.equals(d.get(3), searcher.current()));
+    Assert.assertTrue(CellUtil.equals(d.get(3), searcher.current()));
 
     Cell between4And5 = new KeyValue(rowB, cf, cq1, ts - 2, v0);
 
@@ -87,12 +87,12 @@ public class TestRowDataSimple extends BaseTestRowData {
     // test atOrBefore
     p = searcher.positionAtOrBefore(between4And5);
     Assert.assertEquals(CellScannerPosition.BEFORE, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(4)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(4)));
 
     // test atOrAfter
     p = searcher.positionAtOrAfter(between4And5);
     Assert.assertEquals(CellScannerPosition.AFTER, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(5)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(5)));
 
     // test when key falls before first key in block
     Cell beforeFirst = new KeyValue(Bytes.toBytes("A"), cf, cq0, ts, v0);
@@ -101,7 +101,7 @@ public class TestRowDataSimple extends BaseTestRowData {
     Assert.assertEquals(CellScannerPosition.BEFORE_FIRST, p);
     p = searcher.positionAtOrAfter(beforeFirst);
     Assert.assertEquals(CellScannerPosition.AFTER, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(0)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), d.get(0)));
     Assert.assertEquals(d.get(0), searcher.current());
 
     // test when key falls after last key in block
@@ -111,7 +111,7 @@ public class TestRowDataSimple extends BaseTestRowData {
     Assert.assertEquals(CellScannerPosition.AFTER_LAST, p);
     p = searcher.positionAtOrBefore(afterLast);
     Assert.assertEquals(CellScannerPosition.BEFORE, p);
-    Assert.assertTrue(CellComparator.equals(searcher.current(), CollectionUtils.getLast(d)));
+    Assert.assertTrue(CellUtil.equals(searcher.current(), CollectionUtils.getLast(d)));
   }
 
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
index ce8ff38..a95da7b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
@@ -164,8 +164,8 @@ public class HalfStoreFileReader extends StoreFile.Reader {
         // constrain the bottom.
         if (!top) {
           ByteBuffer bb = getKey();
-          if (getComparator().compareFlatKey(bb.array(), bb.arrayOffset(), bb.limit(),
-              splitkey, 0, splitkey.length) >= 0) {
+          if (getComparator().compare(splitCell, bb.array(), bb.arrayOffset(),
+              bb.limit()) <= 0) {
             atEnd = true;
             return false;
           }
@@ -176,7 +176,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
       @Override
       public boolean seekTo() throws IOException {
         if (top) {
-          int r = this.delegate.seekTo(new KeyValue.KeyOnlyKeyValue(splitkey, 0, splitkey.length));
+          int r = this.delegate.seekTo(splitCell);
           if (r == HConstants.INDEX_KEY_MAGIC) {
             return true;
           }
@@ -196,9 +196,9 @@ public class HalfStoreFileReader extends StoreFile.Reader {
         }
         // Check key.
         ByteBuffer k = this.delegate.getKey();
-        return this.delegate.getReader().getComparator().
-          compareFlatKey(k.array(), k.arrayOffset(), k.limit(),
-            splitkey, 0, splitkey.length) < 0;
+        return (this.delegate.getReader().getComparator().
+          compare(splitCell, k.array(), k.arrayOffset(), k.limit()
+            )) > 0;
       }
 
       public org.apache.hadoop.hbase.io.hfile.HFile.Reader getReader() {
@@ -212,11 +212,11 @@ public class HalfStoreFileReader extends StoreFile.Reader {
       @Override
       public int seekTo(Cell key) throws IOException {
         if (top) {
-          if (getComparator().compareOnlyKeyPortion(key, splitCell) < 0) {
+          if (getComparator().compareKeyIgnoresMvcc(key, splitCell) < 0) {
             return -1;
           }
         } else {
-          if (getComparator().compareOnlyKeyPortion(key, splitCell) >= 0) {
+          if (getComparator().compareKeyIgnoresMvcc(key, splitCell) >= 0) {
             // we would place the scanner in the second half.
             // it might be an error to return false here ever...
             boolean res = delegate.seekBefore(splitCell);
@@ -237,11 +237,11 @@ public class HalfStoreFileReader extends StoreFile.Reader {
         // except
         // that we call reseekTo (and not seekTo) on the delegate.
         if (top) {
-          if (getComparator().compareOnlyKeyPortion(key, splitCell) < 0) {
+          if (getComparator().compareKeyIgnoresMvcc(key, splitCell) < 0) {
             return -1;
           }
         } else {
-          if (getComparator().compareOnlyKeyPortion(key, splitCell) >= 0) {
+          if (getComparator().compareKeyIgnoresMvcc(key, splitCell) >= 0) {
             // we would place the scanner in the second half.
             // it might be an error to return false here ever...
             boolean res = delegate.seekBefore(splitCell);
@@ -263,13 +263,13 @@ public class HalfStoreFileReader extends StoreFile.Reader {
       public boolean seekBefore(Cell key) throws IOException {
         if (top) {
           Cell fk = new KeyValue.KeyOnlyKeyValue(getFirstKey(), 0, getFirstKey().length);
-          if (getComparator().compareOnlyKeyPortion(key, fk) <= 0) {
+          if (getComparator().compareKeyIgnoresMvcc(key, fk) <= 0) {
             return false;
           }
         } else {
           // The equals sign isn't strictly necessary just here to be consistent
           // with seekTo
-          if (getComparator().compareOnlyKeyPortion(key, splitCell) >= 0) {
+          if (getComparator().compareKeyIgnoresMvcc(key, splitCell) >= 0) {
             boolean ret = this.delegate.seekBefore(splitCell);
             if (ret) {
               atEnd = false;

http://git-wip-us.apache.org/repos/asf/hbase/blob/977f8674/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java
index 9ce5056..72f550a 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java
@@ -27,10 +27,11 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.util.ByteStringer;
+import org.apache.hadoop.hbase.CellComparator.MetaCellComparator;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.hbase.CellComparator;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.io.compress.Compression;
 import org.apache.hadoop.hbase.protobuf.generated.HFileProtos;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -109,7 +110,7 @@ public class FixedFileTrailer {
 
   /** Raw key comparator class name in version 3 */
   // We could write the actual class name from 2.0 onwards and handle BC
-  private String comparatorClassName = KeyValue.COMPARATOR.getClass().getName();
+  private String comparatorClassName = CellComparator.COMPARATOR.getClass().getName();
 
   /** The encryption key */
   private byte[] encryptionKey;
@@ -538,12 +539,12 @@ public class FixedFileTrailer {
     return minorVersion;
   }
 
-  public void setComparatorClass(Class<? extends KVComparator> klass) {
+  public void setComparatorClass(Class<? extends CellComparator> klass) {
     // Is the comparator instantiable?
     try {
       // If null, it should be the Bytes.BYTES_RAWCOMPARATOR
       if (klass != null) {
-        KVComparator comp = klass.newInstance();
+        CellComparator comp = klass.newInstance();
         // if the name wasn't one of the legacy names, maybe its a legit new
         // kind of comparator.
         comparatorClassName = klass.getName();
@@ -555,34 +556,35 @@ public class FixedFileTrailer {
   }
 
   @SuppressWarnings("unchecked")
-  private static Class<? extends KVComparator> getComparatorClass(
-      String comparatorClassName) throws IOException {
-    try {
-      // HFile V2 legacy comparator class names.
-      if (comparatorClassName.equals(KeyValue.COMPARATOR.getLegacyKeyComparatorName())) {
-        comparatorClassName = KeyValue.COMPARATOR.getClass().getName();
-      } else if (comparatorClassName.equals(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName())) {
-        comparatorClassName = KeyValue.META_COMPARATOR.getClass().getName();
-      } else if (comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getLegacyKeyComparatorName())) {
-        return null;
-      }
-
+  private static Class<? extends CellComparator> getComparatorClass(String comparatorClassName)
+      throws IOException {
+    Class<? extends CellComparator> comparatorKlass;
+    if (comparatorClassName.equals(KeyValue.COMPARATOR.getLegacyKeyComparatorName())
+        || comparatorClassName.equals(KeyValue.COMPARATOR.getClass().getName())) {
+      comparatorKlass = CellComparator.class;
+    } else if (comparatorClassName.equals(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName())
+        || comparatorClassName.equals(KeyValue.META_COMPARATOR.getClass().getName())) {
+      comparatorKlass = MetaCellComparator.class;
+    } else if (comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getClass().getName())
+        || comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getLegacyKeyComparatorName())) {
+      // When the comparator to be used is Bytes.BYTES_RAWCOMPARATOR, we just return null from here
+      // Bytes.BYTES_RAWCOMPARATOR is not a CellComparator
+      comparatorKlass = null;
+    } else {
       // if the name wasn't one of the legacy names, maybe its a legit new kind of comparator.
-      if (comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getClass().getName())) {
-        // Return null for Bytes.BYTES_RAWCOMPARATOR
-        return null;
-      } else {
-        return (Class<? extends KVComparator>) Class.forName(comparatorClassName);
+      try {
+        comparatorKlass = (Class<? extends CellComparator>) Class.forName(comparatorClassName);
+      } catch (ClassNotFoundException e) {
+        throw new IOException(e);
       }
-    } catch (ClassNotFoundException ex) {
-      throw new IOException(ex);
     }
+    return comparatorKlass;
   }
 
-  public static KVComparator createComparator(
+  public static CellComparator createComparator(
       String comparatorClassName) throws IOException {
     try {
-      Class<? extends KVComparator> comparatorClass = getComparatorClass(comparatorClassName);
+      Class<? extends CellComparator> comparatorClass = getComparatorClass(comparatorClassName);
       return comparatorClass != null ? comparatorClass.newInstance() : null;
     } catch (InstantiationException e) {
       throw new IOException("Comparator class " + comparatorClassName +
@@ -593,7 +595,7 @@ public class FixedFileTrailer {
     }
   }
 
-  KVComparator createComparator() throws IOException {
+  CellComparator createComparator() throws IOException {
     expectAtLeastMajorVersion(2);
     return createComparator(comparatorClassName);
   }


Mime
View raw message