HBASE-24194 : Refactor anonymous inner classes of BufferedEncodedSeeker to named inner classes (#1522)
Signed-off-by: Peter Somogyi <psomogyi@apache.org> Signed-off-by: binlijin <binlijin@gmail.com>
This commit is contained in:
parent
589d075de8
commit
d4b64c2545
|
@ -84,35 +84,7 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
|
|||
@Override
|
||||
public EncodedSeeker createSeeker(KVComparator comparator,
|
||||
final HFileBlockDecodingContext decodingCtx) {
|
||||
return new BufferedEncodedSeeker<SeekerState>(comparator, decodingCtx) {
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
current.keyLength = currentBuffer.getInt();
|
||||
current.valueLength = currentBuffer.getInt();
|
||||
current.ensureSpaceForKey();
|
||||
currentBuffer.get(current.keyBuffer, 0, current.keyLength);
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
if (includesTags()) {
|
||||
// Read short as unsigned, high byte first
|
||||
current.tagsLength = ((currentBuffer.get() & 0xff) << 8) ^ (currentBuffer.get() & 0xff);
|
||||
ByteBufferUtils.skip(currentBuffer, current.tagsLength);
|
||||
}
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
current.lastCommonPrefix = 0;
|
||||
decodeNext();
|
||||
}
|
||||
};
|
||||
return new SeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,4 +98,41 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
|
|||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static class SeekerStateBufferedEncodedSeeker
|
||||
extends BufferedEncodedSeeker<SeekerState> {
|
||||
|
||||
public SeekerStateBufferedEncodedSeeker(KVComparator comparator,
|
||||
HFileBlockDecodingContext decodingCtx) {
|
||||
super(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
current.keyLength = currentBuffer.getInt();
|
||||
current.valueLength = currentBuffer.getInt();
|
||||
current.ensureSpaceForKey();
|
||||
currentBuffer.get(current.keyBuffer, 0, current.keyLength);
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
if (includesTags()) {
|
||||
// Read short as unsigned, high byte first
|
||||
current.tagsLength = ((currentBuffer.get() & 0xff) << 8) ^ (currentBuffer.get() & 0xff);
|
||||
ByteBufferUtils.skip(currentBuffer, current.tagsLength);
|
||||
}
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
current.lastCommonPrefix = 0;
|
||||
decodeNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -378,132 +378,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
|
|||
@Override
|
||||
public EncodedSeeker createSeeker(KVComparator comparator,
|
||||
HFileBlockDecodingContext decodingCtx) {
|
||||
return new BufferedEncodedSeeker<DiffSeekerState>(comparator, decodingCtx) {
|
||||
private byte[] familyNameWithSize;
|
||||
private static final int TIMESTAMP_WITH_TYPE_LENGTH =
|
||||
Bytes.SIZEOF_LONG + Bytes.SIZEOF_BYTE;
|
||||
|
||||
private void decode(boolean isFirst) {
|
||||
byte flag = currentBuffer.get();
|
||||
byte type = 0;
|
||||
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
if (!isFirst) {
|
||||
type = current.keyBuffer[current.keyLength - Bytes.SIZEOF_BYTE];
|
||||
}
|
||||
current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
if ((flag & FLAG_SAME_VALUE_LENGTH) == 0) {
|
||||
current.valueLength =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
current.lastCommonPrefix =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
|
||||
current.ensureSpaceForKey();
|
||||
|
||||
if (current.lastCommonPrefix < Bytes.SIZEOF_SHORT) {
|
||||
// length of row is different, copy everything except family
|
||||
|
||||
// copy the row size
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
Bytes.SIZEOF_SHORT - current.lastCommonPrefix);
|
||||
current.rowLengthWithSize = Bytes.toShort(current.keyBuffer, 0) +
|
||||
Bytes.SIZEOF_SHORT;
|
||||
|
||||
// copy the rest of row
|
||||
currentBuffer.get(current.keyBuffer, Bytes.SIZEOF_SHORT,
|
||||
current.rowLengthWithSize - Bytes.SIZEOF_SHORT);
|
||||
|
||||
// copy the column family
|
||||
System.arraycopy(familyNameWithSize, 0, current.keyBuffer,
|
||||
current.rowLengthWithSize, familyNameWithSize.length);
|
||||
|
||||
// copy the qualifier
|
||||
currentBuffer.get(current.keyBuffer,
|
||||
current.rowLengthWithSize + familyNameWithSize.length,
|
||||
current.keyLength - current.rowLengthWithSize -
|
||||
familyNameWithSize.length - TIMESTAMP_WITH_TYPE_LENGTH);
|
||||
} else if (current.lastCommonPrefix < current.rowLengthWithSize) {
|
||||
// we have to copy part of row and qualifier,
|
||||
// but column family is in right place
|
||||
|
||||
// before column family (rest of row)
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.rowLengthWithSize - current.lastCommonPrefix);
|
||||
|
||||
// after column family (qualifier)
|
||||
currentBuffer.get(current.keyBuffer,
|
||||
current.rowLengthWithSize + familyNameWithSize.length,
|
||||
current.keyLength - current.rowLengthWithSize -
|
||||
familyNameWithSize.length - TIMESTAMP_WITH_TYPE_LENGTH);
|
||||
} else {
|
||||
// copy just the ending
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - TIMESTAMP_WITH_TYPE_LENGTH -
|
||||
current.lastCommonPrefix);
|
||||
}
|
||||
|
||||
// timestamp
|
||||
int pos = current.keyLength - TIMESTAMP_WITH_TYPE_LENGTH;
|
||||
int timestampFitInBytes = 1 +
|
||||
((flag & MASK_TIMESTAMP_LENGTH) >>> SHIFT_TIMESTAMP_LENGTH);
|
||||
long timestampOrDiff =
|
||||
ByteBufferUtils.readLong(currentBuffer, timestampFitInBytes);
|
||||
if ((flag & FLAG_TIMESTAMP_SIGN) != 0) {
|
||||
timestampOrDiff = -timestampOrDiff;
|
||||
}
|
||||
if ((flag & FLAG_TIMESTAMP_IS_DIFF) == 0) { // it is timestamp
|
||||
current.timestamp = timestampOrDiff;
|
||||
} else { // it is diff
|
||||
current.timestamp = current.timestamp - timestampOrDiff;
|
||||
}
|
||||
Bytes.putLong(current.keyBuffer, pos, current.timestamp);
|
||||
pos += Bytes.SIZEOF_LONG;
|
||||
|
||||
// type
|
||||
if ((flag & FLAG_SAME_TYPE) == 0) {
|
||||
currentBuffer.get(current.keyBuffer, pos, Bytes.SIZEOF_BYTE);
|
||||
} else if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
current.keyBuffer[pos] = type;
|
||||
}
|
||||
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
|
||||
if (includesTags()) {
|
||||
decodeTags();
|
||||
}
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
|
||||
// read column family
|
||||
byte familyNameLength = currentBuffer.get();
|
||||
familyNameWithSize = new byte[familyNameLength + Bytes.SIZEOF_BYTE];
|
||||
familyNameWithSize[0] = familyNameLength;
|
||||
currentBuffer.get(familyNameWithSize, Bytes.SIZEOF_BYTE,
|
||||
familyNameLength);
|
||||
decode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
decode(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DiffSeekerState createSeekerState() {
|
||||
return new DiffSeekerState();
|
||||
}
|
||||
};
|
||||
return new DiffSeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -525,4 +400,138 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
|
|||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static class DiffSeekerStateBufferedEncodedSeeker
|
||||
extends BufferedEncodedSeeker<DiffSeekerState> {
|
||||
|
||||
private byte[] familyNameWithSize;
|
||||
private static final int TIMESTAMP_WITH_TYPE_LENGTH =
|
||||
Bytes.SIZEOF_LONG + Bytes.SIZEOF_BYTE;
|
||||
|
||||
private DiffSeekerStateBufferedEncodedSeeker(KVComparator comparator,
|
||||
HFileBlockDecodingContext decodingCtx) {
|
||||
super(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
private void decode(boolean isFirst) {
|
||||
byte flag = currentBuffer.get();
|
||||
byte type = 0;
|
||||
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
if (!isFirst) {
|
||||
type = current.keyBuffer[current.keyLength - Bytes.SIZEOF_BYTE];
|
||||
}
|
||||
current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
if ((flag & FLAG_SAME_VALUE_LENGTH) == 0) {
|
||||
current.valueLength =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
current.lastCommonPrefix =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
|
||||
current.ensureSpaceForKey();
|
||||
|
||||
if (current.lastCommonPrefix < Bytes.SIZEOF_SHORT) {
|
||||
// length of row is different, copy everything except family
|
||||
|
||||
// copy the row size
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
Bytes.SIZEOF_SHORT - current.lastCommonPrefix);
|
||||
current.rowLengthWithSize = Bytes.toShort(current.keyBuffer, 0) +
|
||||
Bytes.SIZEOF_SHORT;
|
||||
|
||||
// copy the rest of row
|
||||
currentBuffer.get(current.keyBuffer, Bytes.SIZEOF_SHORT,
|
||||
current.rowLengthWithSize - Bytes.SIZEOF_SHORT);
|
||||
|
||||
// copy the column family
|
||||
System.arraycopy(familyNameWithSize, 0, current.keyBuffer,
|
||||
current.rowLengthWithSize, familyNameWithSize.length);
|
||||
|
||||
// copy the qualifier
|
||||
currentBuffer.get(current.keyBuffer,
|
||||
current.rowLengthWithSize + familyNameWithSize.length,
|
||||
current.keyLength - current.rowLengthWithSize -
|
||||
familyNameWithSize.length - TIMESTAMP_WITH_TYPE_LENGTH);
|
||||
} else if (current.lastCommonPrefix < current.rowLengthWithSize) {
|
||||
// we have to copy part of row and qualifier,
|
||||
// but column family is in right place
|
||||
|
||||
// before column family (rest of row)
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.rowLengthWithSize - current.lastCommonPrefix);
|
||||
|
||||
// after column family (qualifier)
|
||||
currentBuffer.get(current.keyBuffer,
|
||||
current.rowLengthWithSize + familyNameWithSize.length,
|
||||
current.keyLength - current.rowLengthWithSize -
|
||||
familyNameWithSize.length - TIMESTAMP_WITH_TYPE_LENGTH);
|
||||
} else {
|
||||
// copy just the ending
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - TIMESTAMP_WITH_TYPE_LENGTH -
|
||||
current.lastCommonPrefix);
|
||||
}
|
||||
|
||||
// timestamp
|
||||
int pos = current.keyLength - TIMESTAMP_WITH_TYPE_LENGTH;
|
||||
int timestampFitInBytes = 1 +
|
||||
((flag & MASK_TIMESTAMP_LENGTH) >>> SHIFT_TIMESTAMP_LENGTH);
|
||||
long timestampOrDiff =
|
||||
ByteBufferUtils.readLong(currentBuffer, timestampFitInBytes);
|
||||
if ((flag & FLAG_TIMESTAMP_SIGN) != 0) {
|
||||
timestampOrDiff = -timestampOrDiff;
|
||||
}
|
||||
if ((flag & FLAG_TIMESTAMP_IS_DIFF) == 0) { // it is timestamp
|
||||
current.timestamp = timestampOrDiff;
|
||||
} else { // it is diff
|
||||
current.timestamp = current.timestamp - timestampOrDiff;
|
||||
}
|
||||
Bytes.putLong(current.keyBuffer, pos, current.timestamp);
|
||||
pos += Bytes.SIZEOF_LONG;
|
||||
|
||||
// type
|
||||
if ((flag & FLAG_SAME_TYPE) == 0) {
|
||||
currentBuffer.get(current.keyBuffer, pos, Bytes.SIZEOF_BYTE);
|
||||
} else if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
current.keyBuffer[pos] = type;
|
||||
}
|
||||
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
|
||||
if (includesTags()) {
|
||||
decodeTags();
|
||||
}
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
|
||||
// read column family
|
||||
byte familyNameLength = currentBuffer.get();
|
||||
familyNameWithSize = new byte[familyNameLength + Bytes.SIZEOF_BYTE];
|
||||
familyNameWithSize[0] = familyNameLength;
|
||||
currentBuffer.get(familyNameWithSize, Bytes.SIZEOF_BYTE,
|
||||
familyNameLength);
|
||||
decode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
decode(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DiffSeekerState createSeekerState() {
|
||||
return new DiffSeekerState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -398,132 +398,141 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
|
|||
@Override
|
||||
public EncodedSeeker createSeeker(KVComparator comparator,
|
||||
final HFileBlockDecodingContext decodingCtx) {
|
||||
return new BufferedEncodedSeeker<FastDiffSeekerState>(comparator, decodingCtx) {
|
||||
private void decode(boolean isFirst) {
|
||||
byte flag = currentBuffer.get();
|
||||
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
if (!isFirst) {
|
||||
System.arraycopy(current.keyBuffer,
|
||||
current.keyLength - current.prevTimestampAndType.length,
|
||||
current.prevTimestampAndType, 0,
|
||||
current.prevTimestampAndType.length);
|
||||
}
|
||||
current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
return new FastDiffSeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
private class FastDiffSeekerStateBufferedEncodedSeeker
|
||||
extends BufferedEncodedSeeker<FastDiffSeekerState> {
|
||||
|
||||
private FastDiffSeekerStateBufferedEncodedSeeker(KVComparator comparator,
|
||||
HFileBlockDecodingContext decodingCtx) {
|
||||
super(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
private void decode(boolean isFirst) {
|
||||
byte flag = currentBuffer.get();
|
||||
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
if (!isFirst) {
|
||||
System.arraycopy(current.keyBuffer,
|
||||
current.keyLength - current.prevTimestampAndType.length,
|
||||
current.prevTimestampAndType, 0,
|
||||
current.prevTimestampAndType.length);
|
||||
}
|
||||
if ((flag & FLAG_SAME_VALUE_LENGTH) == 0) {
|
||||
current.valueLength =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
current.lastCommonPrefix =
|
||||
current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
if ((flag & FLAG_SAME_VALUE_LENGTH) == 0) {
|
||||
current.valueLength =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
}
|
||||
current.lastCommonPrefix =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
|
||||
current.ensureSpaceForKey();
|
||||
current.ensureSpaceForKey();
|
||||
|
||||
if (isFirst) {
|
||||
// copy everything
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - current.prevTimestampAndType.length);
|
||||
current.rowLengthWithSize = Bytes.toShort(current.keyBuffer, 0) +
|
||||
Bytes.SIZEOF_SHORT;
|
||||
current.familyLengthWithSize =
|
||||
current.keyBuffer[current.rowLengthWithSize] + Bytes.SIZEOF_BYTE;
|
||||
} else if (current.lastCommonPrefix < Bytes.SIZEOF_SHORT) {
|
||||
// length of row is different, copy everything except family
|
||||
if (isFirst) {
|
||||
// copy everything
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - current.prevTimestampAndType.length);
|
||||
current.rowLengthWithSize = Bytes.toShort(current.keyBuffer, 0) +
|
||||
Bytes.SIZEOF_SHORT;
|
||||
current.familyLengthWithSize =
|
||||
current.keyBuffer[current.rowLengthWithSize] + Bytes.SIZEOF_BYTE;
|
||||
} else if (current.lastCommonPrefix < Bytes.SIZEOF_SHORT) {
|
||||
// length of row is different, copy everything except family
|
||||
|
||||
// copy the row size
|
||||
int oldRowLengthWithSize = current.rowLengthWithSize;
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
Bytes.SIZEOF_SHORT - current.lastCommonPrefix);
|
||||
current.rowLengthWithSize = Bytes.toShort(current.keyBuffer, 0) +
|
||||
Bytes.SIZEOF_SHORT;
|
||||
// copy the row size
|
||||
int oldRowLengthWithSize = current.rowLengthWithSize;
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
Bytes.SIZEOF_SHORT - current.lastCommonPrefix);
|
||||
current.rowLengthWithSize = Bytes.toShort(current.keyBuffer, 0) +
|
||||
Bytes.SIZEOF_SHORT;
|
||||
|
||||
// move the column family
|
||||
System.arraycopy(current.keyBuffer, oldRowLengthWithSize,
|
||||
current.keyBuffer, current.rowLengthWithSize,
|
||||
current.familyLengthWithSize);
|
||||
// move the column family
|
||||
System.arraycopy(current.keyBuffer, oldRowLengthWithSize,
|
||||
current.keyBuffer, current.rowLengthWithSize,
|
||||
current.familyLengthWithSize);
|
||||
|
||||
// copy the rest of row
|
||||
currentBuffer.get(current.keyBuffer, Bytes.SIZEOF_SHORT,
|
||||
current.rowLengthWithSize - Bytes.SIZEOF_SHORT);
|
||||
// copy the rest of row
|
||||
currentBuffer.get(current.keyBuffer, Bytes.SIZEOF_SHORT,
|
||||
current.rowLengthWithSize - Bytes.SIZEOF_SHORT);
|
||||
|
||||
// copy the qualifier
|
||||
currentBuffer.get(current.keyBuffer, current.rowLengthWithSize
|
||||
+ current.familyLengthWithSize, current.keyLength
|
||||
- current.rowLengthWithSize - current.familyLengthWithSize
|
||||
- current.prevTimestampAndType.length);
|
||||
} else if (current.lastCommonPrefix < current.rowLengthWithSize) {
|
||||
// We have to copy part of row and qualifier, but the column family
|
||||
// is in the right place.
|
||||
// copy the qualifier
|
||||
currentBuffer.get(current.keyBuffer, current.rowLengthWithSize
|
||||
+ current.familyLengthWithSize, current.keyLength
|
||||
- current.rowLengthWithSize - current.familyLengthWithSize
|
||||
- current.prevTimestampAndType.length);
|
||||
} else if (current.lastCommonPrefix < current.rowLengthWithSize) {
|
||||
// We have to copy part of row and qualifier, but the column family
|
||||
// is in the right place.
|
||||
|
||||
// before column family (rest of row)
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.rowLengthWithSize - current.lastCommonPrefix);
|
||||
// before column family (rest of row)
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.rowLengthWithSize - current.lastCommonPrefix);
|
||||
|
||||
// after column family (qualifier)
|
||||
currentBuffer.get(current.keyBuffer, current.rowLengthWithSize
|
||||
+ current.familyLengthWithSize, current.keyLength
|
||||
- current.rowLengthWithSize - current.familyLengthWithSize
|
||||
- current.prevTimestampAndType.length);
|
||||
} else {
|
||||
// copy just the ending
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - current.prevTimestampAndType.length
|
||||
- current.lastCommonPrefix);
|
||||
}
|
||||
|
||||
// timestamp
|
||||
int pos = current.keyLength - current.prevTimestampAndType.length;
|
||||
int commonTimestampPrefix = (flag & MASK_TIMESTAMP_LENGTH) >>>
|
||||
SHIFT_TIMESTAMP_LENGTH;
|
||||
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
System.arraycopy(current.prevTimestampAndType, 0, current.keyBuffer,
|
||||
pos, commonTimestampPrefix);
|
||||
}
|
||||
pos += commonTimestampPrefix;
|
||||
currentBuffer.get(current.keyBuffer, pos,
|
||||
Bytes.SIZEOF_LONG - commonTimestampPrefix);
|
||||
pos += Bytes.SIZEOF_LONG - commonTimestampPrefix;
|
||||
|
||||
// type
|
||||
if ((flag & FLAG_SAME_TYPE) == 0) {
|
||||
currentBuffer.get(current.keyBuffer, pos, Bytes.SIZEOF_BYTE);
|
||||
} else if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
current.keyBuffer[pos] =
|
||||
current.prevTimestampAndType[Bytes.SIZEOF_LONG];
|
||||
}
|
||||
|
||||
// handle value
|
||||
if ((flag & FLAG_SAME_VALUE) == 0) {
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
}
|
||||
|
||||
if (includesTags()) {
|
||||
decodeTags();
|
||||
}
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
// after column family (qualifier)
|
||||
currentBuffer.get(current.keyBuffer, current.rowLengthWithSize
|
||||
+ current.familyLengthWithSize, current.keyLength
|
||||
- current.rowLengthWithSize - current.familyLengthWithSize
|
||||
- current.prevTimestampAndType.length);
|
||||
} else {
|
||||
// copy just the ending
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - current.prevTimestampAndType.length
|
||||
- current.lastCommonPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
decode(true);
|
||||
// timestamp
|
||||
int pos = current.keyLength - current.prevTimestampAndType.length;
|
||||
int commonTimestampPrefix = (flag & MASK_TIMESTAMP_LENGTH) >>>
|
||||
SHIFT_TIMESTAMP_LENGTH;
|
||||
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
System.arraycopy(current.prevTimestampAndType, 0, current.keyBuffer,
|
||||
pos, commonTimestampPrefix);
|
||||
}
|
||||
pos += commonTimestampPrefix;
|
||||
currentBuffer.get(current.keyBuffer, pos,
|
||||
Bytes.SIZEOF_LONG - commonTimestampPrefix);
|
||||
pos += Bytes.SIZEOF_LONG - commonTimestampPrefix;
|
||||
|
||||
// type
|
||||
if ((flag & FLAG_SAME_TYPE) == 0) {
|
||||
currentBuffer.get(current.keyBuffer, pos, Bytes.SIZEOF_BYTE);
|
||||
} else if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
|
||||
current.keyBuffer[pos] =
|
||||
current.prevTimestampAndType[Bytes.SIZEOF_LONG];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
decode(false);
|
||||
// handle value
|
||||
if ((flag & FLAG_SAME_VALUE) == 0) {
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FastDiffSeekerState createSeekerState() {
|
||||
return new FastDiffSeekerState();
|
||||
if (includesTags()) {
|
||||
decodeTags();
|
||||
}
|
||||
};
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
decode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
decode(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FastDiffSeekerState createSeekerState() {
|
||||
return new FastDiffSeekerState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,35 +198,44 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
|
|||
@Override
|
||||
public EncodedSeeker createSeeker(KVComparator comparator,
|
||||
final HFileBlockDecodingContext decodingCtx) {
|
||||
return new BufferedEncodedSeeker<SeekerState>(comparator, decodingCtx) {
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
current.valueLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
current.lastCommonPrefix =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
current.keyLength += current.lastCommonPrefix;
|
||||
current.ensureSpaceForKey();
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - current.lastCommonPrefix);
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
if (includesTags()) {
|
||||
decodeTags();
|
||||
}
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
return new SeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
decodeNext();
|
||||
private static class SeekerStateBufferedEncodedSeeker
|
||||
extends BufferedEncodedSeeker<SeekerState> {
|
||||
|
||||
private SeekerStateBufferedEncodedSeeker(KVComparator comparator,
|
||||
HFileBlockDecodingContext decodingCtx) {
|
||||
super(comparator, decodingCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeNext() {
|
||||
current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
current.valueLength = ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
current.lastCommonPrefix =
|
||||
ByteBufferUtils.readCompressedInt(currentBuffer);
|
||||
current.keyLength += current.lastCommonPrefix;
|
||||
current.ensureSpaceForKey();
|
||||
currentBuffer.get(current.keyBuffer, current.lastCommonPrefix,
|
||||
current.keyLength - current.lastCommonPrefix);
|
||||
current.valueOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.valueLength);
|
||||
if (includesTags()) {
|
||||
decodeTags();
|
||||
}
|
||||
};
|
||||
if (includesMvcc()) {
|
||||
current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer);
|
||||
} else {
|
||||
current.memstoreTS = 0;
|
||||
}
|
||||
current.nextKvOffset = currentBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeFirst() {
|
||||
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
|
||||
decodeNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue