You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by op...@apache.org on 2019/09/05 09:48:48 UTC
[hbase] branch branch-1 updated: HBASE-22937 The RawBytesComparator
in branch-1 have wrong comparison order (#582)
This is an automated email from the ASF dual-hosted git repository.
openinx pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1 by this push:
new 4c2bf71 HBASE-22937 The RawBytesComparator in branch-1 have wrong comparison order (#582)
4c2bf71 is described below
commit 4c2bf71a3ab284d43d69d8880e074a6d797ee42c
Author: openinx <op...@gmail.com>
AuthorDate: Thu Sep 5 17:48:41 2019 +0800
HBASE-22937 The RawBytesComparator in branch-1 have wrong comparison order (#582)
---
.../java/org/apache/hadoop/hbase/KeyValue.java | 24 ++++++++++------------
.../java/org/apache/hadoop/hbase/TestKeyValue.java | 13 ++++++++++++
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
index 1f84d62..e820d11 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
@@ -2630,9 +2630,8 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId,
*/
public static class RawBytesComparator extends KVComparator {
/**
- * The HFileV2 file format's trailer contains this class name. We reinterpret this and
- * instantiate the appropriate comparator.
- * TODO: With V3 consider removing this.
+ * The HFileV2 file format's trailer contains this class name. We reinterpret this and
+ * instantiate the appropriate comparator. TODO: With V3 consider removing this.
* @return legacy class name for FileFileTrailer#comparatorClassName
*/
@Override
@@ -2645,9 +2644,9 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId,
*/
@Override
@Deprecated
- public int compareFlatKey(byte[] left, int loffset, int llength, byte[] right,
- int roffset, int rlength) {
- return Bytes.BYTES_RAWCOMPARATOR.compare(left, loffset, llength, right, roffset, rlength);
+ public int compareFlatKey(byte[] left, int loffset, int llength, byte[] right, int roffset,
+ int rlength) {
+ return Bytes.BYTES_RAWCOMPARATOR.compare(left, loffset, llength, right, roffset, rlength);
}
@Override
@@ -2659,19 +2658,19 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId,
@VisibleForTesting
public int compareOnlyKeyPortion(Cell left, Cell right) {
int c = Bytes.BYTES_RAWCOMPARATOR.compare(left.getRowArray(), left.getRowOffset(),
- left.getRowLength(), right.getRowArray(), right.getRowOffset(), right.getRowLength());
+ left.getRowLength(), right.getRowArray(), right.getRowOffset(), right.getRowLength());
if (c != 0) {
return c;
}
c = Bytes.BYTES_RAWCOMPARATOR.compare(left.getFamilyArray(), left.getFamilyOffset(),
- left.getFamilyLength(), right.getFamilyArray(), right.getFamilyOffset(),
- right.getFamilyLength());
+ left.getFamilyLength(), right.getFamilyArray(), right.getFamilyOffset(),
+ right.getFamilyLength());
if (c != 0) {
return c;
}
c = Bytes.BYTES_RAWCOMPARATOR.compare(left.getQualifierArray(), left.getQualifierOffset(),
- left.getQualifierLength(), right.getQualifierArray(), right.getQualifierOffset(),
- right.getQualifierLength());
+ left.getQualifierLength(), right.getQualifierArray(), right.getQualifierOffset(),
+ right.getQualifierLength());
if (c != 0) {
return c;
}
@@ -2679,14 +2678,13 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId,
if (c != 0) {
return c;
}
- return (0xff & left.getTypeByte()) - (0xff & right.getTypeByte());
+ return (0xff & right.getTypeByte()) - (0xff & left.getTypeByte());
}
@Override
public byte[] calcIndexKey(byte[] lastKeyOfPreviousBlock, byte[] firstKeyInBlock) {
return firstKeyInBlock;
}
-
}
/**
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 0860636..729de12 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
@@ -38,6 +38,7 @@ 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.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
@@ -722,4 +723,16 @@ public class TestKeyValue extends TestCase {
}
}
}
+
+ @Test
+ public void testRawBytesComparator() {
+ long ts = System.currentTimeMillis();
+ byte[] key = Bytes.toBytes("key");
+ byte[] cf = Bytes.toBytes("cf");
+ byte[] qualifier = Bytes.toBytes("qualifier");
+ byte[] value = Bytes.toBytes("value");
+ KeyValue kvA1 = new KeyValue(key, cf, qualifier, ts, Type.Put, value);
+ KeyValue kvA2 = new KeyValue(key, cf, qualifier, ts, Type.DeleteFamily, value);
+ assertTrue(KeyValue.RAW_COMPARATOR.compare(kvA1, kvA2) > 0);
+ }
}