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:16:00 +05:30
parent 22912ff346
commit ca1f7a9499
No known key found for this signature in database
GPG Key ID: E906DFF511D3E5DB
4 changed files with 320 additions and 288 deletions

View File

@ -81,7 +81,28 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(final HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<SeekerState>(decodingCtx) {
return new SeekerStateBufferedEncodedSeeker(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> {
private SeekerStateBufferedEncodedSeeker(HFileBlockDecodingContext decodingCtx) {
super(decodingCtx);
}
@Override
protected void decodeNext() {
current.keyLength = currentBuffer.getInt();
@ -109,18 +130,6 @@ 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

@ -381,11 +381,39 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<DiffSeekerState>(decodingCtx) {
return new DiffSeekerStateBufferedEncodedSeeker(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(HFileBlockDecodingContext decodingCtx) {
super(decodingCtx);
}
private void decode(boolean isFirst) {
byte flag = currentBuffer.get();
byte type = 0;
@ -503,26 +531,5 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
protected DiffSeekerState createSeekerState() {
return new DiffSeekerState(this.tmpPair, this.includesTags());
}
};
}
@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

@ -396,7 +396,16 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(final HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<FastDiffSeekerState>(decodingCtx) {
return new FastDiffSeekerStateBufferedEncodedSeeker(decodingCtx);
}
private static class FastDiffSeekerStateBufferedEncodedSeeker
extends BufferedEncodedSeeker<FastDiffSeekerState> {
private FastDiffSeekerStateBufferedEncodedSeeker(HFileBlockDecodingContext decodingCtx) {
super(decodingCtx);
}
private void decode(boolean isFirst) {
byte flag = currentBuffer.get();
if ((flag & FLAG_SAME_KEY_LENGTH) == 0) {
@ -520,6 +529,5 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
protected FastDiffSeekerState createSeekerState() {
return new FastDiffSeekerState(this.tmpPair, this.includesTags());
}
};
}
}

View File

@ -194,7 +194,16 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
@Override
public EncodedSeeker createSeeker(final HFileBlockDecodingContext decodingCtx) {
return new BufferedEncodedSeeker<SeekerState>(decodingCtx) {
return new SeekerStateBufferedEncodedSeeker(decodingCtx);
}
private static class SeekerStateBufferedEncodedSeeker
extends BufferedEncodedSeeker<SeekerState> {
private SeekerStateBufferedEncodedSeeker(HFileBlockDecodingContext decodingCtx) {
super(decodingCtx);
}
@Override
protected void decodeNext() {
current.keyLength = ByteBuff.readCompressedInt(currentBuffer);
@ -222,6 +231,5 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
currentBuffer.skip(Bytes.SIZEOF_INT);
decodeNext();
}
};
}
}