HBASE-20564 Tighter ByteBufferKeyValue Cell Comparator; ADDENDUM

Add method the CellComparator Interface. Add implementation to
meta comparator so we don't fall back to the default comparator.

Includes a nothing change to hbase-server/pom.xml just to provoke
build.
This commit is contained in:
Michael Stack 2018-05-16 06:25:42 -07:00
parent 5c4685e56e
commit 77eaff0e10
No known key found for this signature in database
GPG Key ID: 9816C7FC8ACC93D2
3 changed files with 42 additions and 43 deletions

View File

@ -50,6 +50,14 @@ public interface CellComparator extends Comparator<Cell> {
@Override @Override
int compare(Cell leftCell, Cell rightCell); int compare(Cell leftCell, Cell rightCell);
/**
* Compare cells.
* @param ignoreSequenceid True if we are to compare the key portion only and ignore
* the sequenceid. Set to false to compare key and consider sequenceid.
* @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b.
*/
int compare(Cell leftCell, Cell rightCell, boolean ignoreSequenceid);
/** /**
* Lexographically compares the rows of two cells. * Lexographically compares the rows of two cells.
* @param leftCell the left hand side cell * @param leftCell the left hand side cell

View File

@ -63,13 +63,12 @@ public class CellComparatorImpl implements CellComparator {
/** /**
* Compare cells. * Compare cells.
* @param a
* @param b
* @param ignoreSequenceid True if we are to compare the key portion only and ignore * @param ignoreSequenceid True if we are to compare the key portion only and ignore
* the sequenceid. Set to false to compare key and consider sequenceid. * the sequenceid. Set to false to compare key and consider sequenceid.
* @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b. * @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b.
*/ */
public final int compare(final Cell a, final Cell b, boolean ignoreSequenceid) { @Override
public int compare(final Cell a, final Cell b, boolean ignoreSequenceid) {
int diff = 0; int diff = 0;
if (a instanceof ByteBufferKeyValue && b instanceof ByteBufferKeyValue) { if (a instanceof ByteBufferKeyValue && b instanceof ByteBufferKeyValue) {
diff = compareByteBufferKeyValue((ByteBufferKeyValue)a, (ByteBufferKeyValue)b); diff = compareByteBufferKeyValue((ByteBufferKeyValue)a, (ByteBufferKeyValue)b);
@ -97,7 +96,8 @@ public class CellComparatorImpl implements CellComparator {
* Caches deserialized lengths of rows and families, etc., and reuses them where it can * Caches deserialized lengths of rows and families, etc., and reuses them where it can
* (ByteBufferKeyValue has been changed to be amenable to our providing pre-made lengths, etc.) * (ByteBufferKeyValue has been changed to be amenable to our providing pre-made lengths, etc.)
*/ */
private final int compareByteBufferKeyValue(ByteBufferKeyValue left, ByteBufferKeyValue right) { private static final int compareByteBufferKeyValue(ByteBufferKeyValue left,
ByteBufferKeyValue right) {
// Compare Rows. Cache row length. // Compare Rows. Cache row length.
int leftRowLength = left.getRowLength(); int leftRowLength = left.getRowLength();
int rightRowLength = right.getRowLength(); int rightRowLength = right.getRowLength();
@ -134,6 +134,7 @@ public class CellComparatorImpl implements CellComparator {
if (rightFamilyLength + rightQualifierLength == 0 && rightType == Type.Minimum.getCode()) { if (rightFamilyLength + rightQualifierLength == 0 && rightType == Type.Minimum.getCode()) {
return -1; return -1;
} }
// Compare families. // Compare families.
int leftFamilyPosition = left.getFamilyPosition(leftFamilyLengthPosition); int leftFamilyPosition = left.getFamilyPosition(leftFamilyLengthPosition);
int rightFamilyPosition = right.getFamilyPosition(rightFamilyLengthPosition); int rightFamilyPosition = right.getFamilyPosition(rightFamilyLengthPosition);
@ -153,7 +154,8 @@ public class CellComparatorImpl implements CellComparator {
return diff; return diff;
} }
// Timestamps. // Timestamps.
diff = compareTimestamps(left.getTimestamp(leftKeyLength), right.getTimestamp(rightKeyLength)); diff = compareTimestampsInternal(left.getTimestamp(leftKeyLength),
right.getTimestamp(rightKeyLength));
if (diff != 0) { if (diff != 0) {
return diff; return diff;
} }
@ -166,8 +168,6 @@ public class CellComparatorImpl implements CellComparator {
/** /**
* Compares the family and qualifier part of the cell * Compares the family and qualifier part of the cell
* @param left the left cell
* @param right the right cell
* @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
*/ */
public final int compareColumns(final Cell left, final Cell right) { public final int compareColumns(final Cell left, final Cell right) {
@ -180,8 +180,6 @@ public class CellComparatorImpl implements CellComparator {
/** /**
* Compare the families of left and right cell * Compare the families of left and right cell
* @param left
* @param right
* @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
*/ */
@Override @Override
@ -213,8 +211,6 @@ public class CellComparatorImpl implements CellComparator {
/** /**
* Compare the qualifiers part of the left and right cells. * Compare the qualifiers part of the left and right cells.
* @param left
* @param right
* @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
*/ */
@Override @Override
@ -357,40 +353,19 @@ public class CellComparatorImpl implements CellComparator {
return (0xff & right.getTypeByte()) - (0xff & left.getTypeByte()); return (0xff & right.getTypeByte()) - (0xff & left.getTypeByte());
} }
/**
* Compares cell's timestamps in DESCENDING order.
* The below older timestamps sorting ahead of newer timestamps looks
* wrong but it is intentional. This way, newer timestamps are first
* found when we iterate over a memstore and newer versions are the
* first we trip over when reading from a store file.
* @return 1 if left's timestamp &lt; right's timestamp
* -1 if left's timestamp &gt; right's timestamp
* 0 if both timestamps are equal
*/
@Override @Override
public int compareTimestamps(final Cell left, final Cell right) { public int compareTimestamps(final Cell left, final Cell right) {
return compareTimestamps(left.getTimestamp(), right.getTimestamp()); return compareTimestampsInternal(left.getTimestamp(), right.getTimestamp());
} }
/**
* Compares timestamps in DESCENDING order.
* The below older timestamps sorting ahead of newer timestamps looks
* wrong but it is intentional. This way, newer timestamps are first
* found when we iterate over a memstore and newer versions are the
* first we trip over when reading from a store file.
* @return 1 if left timestamp &lt; right timestamp
* -1 if left timestamp &gt; right timestamp
* 0 if both timestamps are equal
*/
@Override @Override
public int compareTimestamps(final long ltimestamp, final long rtimestamp) { public int compareTimestamps(final long ltimestamp, final long rtimestamp) {
if (ltimestamp < rtimestamp) { return compareTimestampsInternal(ltimestamp, rtimestamp);
return 1; }
} else if (ltimestamp > rtimestamp) {
return -1; private static final int compareTimestampsInternal(final long ltimestamp, final long rtimestamp) {
} // Swap the times so sort is newest to oldest, descending.
return 0; return Long.compare(rtimestamp, ltimestamp);
} }
/** /**
@ -398,7 +373,6 @@ public class CellComparatorImpl implements CellComparator {
* {@link KeyValue}s. * {@link KeyValue}s.
*/ */
public static class MetaCellComparator extends CellComparatorImpl { public static class MetaCellComparator extends CellComparatorImpl {
@Override @Override
public int compareRows(final Cell left, final Cell right) { public int compareRows(final Cell left, final Cell right) {
return compareRows(left.getRowArray(), left.getRowOffset(), left.getRowLength(), return compareRows(left.getRowArray(), left.getRowOffset(), left.getRowLength(),
@ -411,7 +385,23 @@ public class CellComparatorImpl implements CellComparator {
roffset, rlength); roffset, rlength);
} }
private int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset, @Override
public int compare(final Cell a, final Cell b, boolean ignoreSequenceid) {
int diff = compareRows(a, b);
if (diff != 0) {
return diff;
}
diff = compareWithoutRow(a, b);
if (diff != 0) {
return diff;
}
// Negate following comparisons so later edits show up first mvccVersion: later sorts first
return ignoreSequenceid? diff: Longs.compare(b.getSequenceId(), a.getSequenceId());
}
private static int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset,
int rlength) { int rlength) {
int leftDelimiter = Bytes.searchDelimiterIndex(left, loffset, llength, HConstants.DELIMITER); int leftDelimiter = Bytes.searchDelimiterIndex(left, loffset, llength, HConstants.DELIMITER);
int rightDelimiter = Bytes int rightDelimiter = Bytes

View File

@ -37,7 +37,8 @@
</properties> </properties>
<build> <build>
<!-- Make sure resources get added before they are processed <!-- Make sure resources get added before they are processed
by placing this first --> by placing this first
-->
<resources> <resources>
<!-- Add the build webabpps to the classpth --> <!-- Add the build webabpps to the classpth -->
<resource> <resource>