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:
Viraj Jasani 2020-04-16 19:34:42 +05:30
parent 589d075de8
commit d4b64c2545
No known key found for this signature in database
GPG Key ID: E906DFF511D3E5DB
4 changed files with 329 additions and 293 deletions

View File

@ -84,7 +84,29 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(KVComparator comparator,
final HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<SeekerState>(comparator, decodingCtx) {
return new SeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
}
@Override
protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength,
int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException {
int decompressedSize = source.readInt();
ByteBuffer buffer = ByteBuffer.allocate(decompressedSize +
allocateHeaderLength);
buffer.position(allocateHeaderLength);
ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize);
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();
@ -112,18 +134,5 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
current.lastCommonPrefix = 0;
decodeNext();
}
};
}
@Override
protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength,
int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException {
int decompressedSize = source.readInt();
ByteBuffer buffer = ByteBuffer.allocate(decompressedSize +
allocateHeaderLength);
buffer.position(allocateHeaderLength);
ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize);
return buffer;
}
}

View File

@ -378,11 +378,41 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(KVComparator comparator,
HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<DiffSeekerState>(comparator, decodingCtx) {
return new DiffSeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
}
@Override
protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength,
int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException {
int decompressedSize = source.readInt();
ByteBuffer buffer = ByteBuffer.allocate(decompressedSize +
allocateHeaderLength);
buffer.position(allocateHeaderLength);
DiffCompressionState state = new DiffCompressionState();
while (source.available() > skipLastBytes) {
uncompressSingleKeyValue(source, buffer, state);
afterDecodingKeyValue(source, buffer, decodingCtx);
}
if (source.available() != skipLastBytes) {
throw new IllegalStateException("Read too much bytes.");
}
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;
@ -503,26 +533,5 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
protected DiffSeekerState createSeekerState() {
return new DiffSeekerState();
}
};
}
@Override
protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength,
int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException {
int decompressedSize = source.readInt();
ByteBuffer buffer = ByteBuffer.allocate(decompressedSize +
allocateHeaderLength);
buffer.position(allocateHeaderLength);
DiffCompressionState state = new DiffCompressionState();
while (source.available() > skipLastBytes) {
uncompressSingleKeyValue(source, buffer, state);
afterDecodingKeyValue(source, buffer, decodingCtx);
}
if (source.available() != skipLastBytes) {
throw new IllegalStateException("Read too much bytes.");
}
return buffer;
}
}

View File

@ -398,7 +398,17 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(KVComparator comparator,
final HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<FastDiffSeekerState>(comparator, decodingCtx) {
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) {
@ -524,6 +534,5 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
protected FastDiffSeekerState createSeekerState() {
return new FastDiffSeekerState();
}
};
}
}

View File

@ -198,7 +198,17 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(KVComparator comparator,
final HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<SeekerState>(comparator, decodingCtx) {
return new SeekerStateBufferedEncodedSeeker(comparator, decodingCtx);
}
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);
@ -227,6 +237,5 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
ByteBufferUtils.skip(currentBuffer, Bytes.SIZEOF_INT);
decodeNext();
}
};
}
}