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:59:31 UTC
[hbase] branch branch-1.4 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.4
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1.4 by this push:
new c756e88 HBASE-22937 The RawBytesComparator in branch-1 have wrong comparison order (#582)
c756e88 is described below
commit c756e8801445cf387bfef65d13bae9f819b21220
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 | 12 +++++++++++
2 files changed, 23 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 2b09faf..f1cde13 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
@@ -2620,9 +2620,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
@@ -2635,9 +2634,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
@@ -2649,19 +2648,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;
}
@@ -2669,14 +2668,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 7d3aa0e..dbaf806 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.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;
+import org.junit.Test;
import static org.junit.Assert.assertNotEquals;
@@ -849,4 +850,15 @@ public class TestKeyValue extends TestCase {
assertNotEquals(kvA1.hashCode(), kvB.hashCode());
}
+ @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);
+ }
}