@InterfaceAudience.Private public class BBKVComparator extends Object implements Comparator
ByteBufferKeyValue
is prevalent type (BBKV
is base-type in hbase2). Takes a general comparator as fallback in case types are NOT the
expected ByteBufferKeyValue.
This is a tricked-out Comparator at heart of hbase read and write. It is in the HOT path so we try all sorts of ugly stuff so we can go faster. See below in this javadoc comment for the list.
Apply this comparator narrowly so it is fed exclusively ByteBufferKeyValues as much as is possible so JIT can settle (e.g. make one per ConcurrentSkipListMap in HStore).
Exploits specially added methods in BBKV to save on deserializations of shorts, longs, etc: i.e. calculating the family length requires row length; pass it in rather than recalculate it, and so on.
This comparator does static dispatch to private final methods so hotspot is comfortable deciding inline.
Measurement has it that we almost have it so all inlines from memstore ConcurrentSkipListMap on down to the (unsafe) intrinisics that do byte compare and deserialize shorts and ints; needs a bit more work.
Does not take a Type to compare: i.e. it is not a Comparator<Cell> or CellComparator<Cell> or Comparator<ByteBufferKeyValue> because that adds another method to the hierarchy -- from compare(Object, Object) to dynamic compare(Cell, Cell) to static private compare -- and inlining doesn't happen if hierarchy is too deep (it is the case here).
Be careful making changes. Compare perf before and after and look at what hotspot ends up generating before committing change (jitwatch is helpful here). Changing this one class doubled write throughput (HBASE-20483).
Modifier and Type | Field and Description |
---|---|
private Comparator |
fallback |
protected static org.slf4j.Logger |
LOG |
Constructor and Description |
---|
BBKVComparator(Comparator fallback) |
Modifier and Type | Method and Description |
---|---|
(package private) static int |
compare(ByteBufferKeyValue left,
ByteBufferKeyValue right,
boolean ignoreSequenceid) |
int |
compare(Object l,
Object r) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
protected static final org.slf4j.Logger LOG
private final Comparator fallback
public BBKVComparator(Comparator fallback)
public int compare(Object l, Object r)
compare
in interface Comparator
static final int compare(ByteBufferKeyValue left, ByteBufferKeyValue right, boolean ignoreSequenceid)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.