-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use lz4 instead of gzip for StringEncoding compress/decompress #1196
Conversation
Change-Id: Ie4458ba481ac3625139458cc92e9dbc0631898da
f4de848
to
f00f547
Compare
Codecov Report
@@ Coverage Diff @@
## master #1196 +/- ##
============================================
+ Coverage 65.75% 65.76% +0.01%
+ Complexity 5754 5753 -1
============================================
Files 361 360 -1
Lines 29548 29593 +45
Branches 4172 4180 +8
============================================
+ Hits 19428 19463 +35
- Misses 8147 8152 +5
- Partials 1973 1978 +5 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain the effect in commit message
buf.write(bytes, 0, len); | ||
} | ||
return decode(buf.bytes()); | ||
return decode(LZ4Util.decompress(buf.bytes(), BLOCK_SIZE).array()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid copy bytes, add method decode(bytes, offset, length), and let BytesBuffer implements OutputStream that BytesBuffer instance could be pass into LZ4BlockOutputStream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it:
use BytesBuffer instead of ByteArrayOutputStream in compress and decompress method, and init BytesBuffer estimate size
byte[] bytes = new byte[value.length]; | ||
int len; | ||
while ((len = in.read(bytes)) > 0) { | ||
while ((len = bis.read(bytes)) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to write a buf, just LZ4Util.decompress(value)
out.write(bytes); | ||
out.finish(); | ||
bytes = LZ4Util.compress(bytes, BLOCK_SIZE).array(); | ||
bos.write(bytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return LZ4Util.compress(bytes, BLOCK_SIZE).bytes()
backend=${backend} | ||
serializer=${serializer} | ||
backend=rocksdb | ||
serializer=binary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep origin
buf.write(bytes, 0, len); | ||
} | ||
return decode(buf.bytes()); | ||
return decode(LZ4Util.decompress(buf.bytes(), BLOCK_SIZE).array()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it:
use BytesBuffer instead of ByteArrayOutputStream in compress and decompress method, and init BytesBuffer estimate size
Change-Id: I812c0ba5a2abda0d11cb2e7af5ebc00da0c26ef6
@@ -135,11 +144,13 @@ public static String encodeBase64(byte[] bytes) { | |||
} | |||
|
|||
public static byte[] compress(String value) { | |||
return LZ4Util.compress(encode(value), BLOCK_SIZE).array(); | |||
BytesBuffer bf = LZ4Util.compress(encode(value), BLOCK_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to buf
} | ||
|
||
public static String decompress(byte[] value) { | ||
return decode(LZ4Util.decompress(value, BLOCK_SIZE).array()); | ||
BytesBuffer bf = LZ4Util.decompress(value, BLOCK_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(blockSize); | ||
BytesBuffer bf = new BytesBuffer(bytes.length * 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to buf
@@ -37,35 +36,35 @@ | |||
public static BytesBuffer compress(byte[] bytes, int blockSize) { | |||
LZ4Factory factory = LZ4Factory.fastestInstance(); | |||
LZ4Compressor compressor = factory.fastCompressor(); | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
BytesBuffer bf = new BytesBuffer(bytes.length / 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to buf
require(BYTE_LEN * val.length); | ||
this.buffer.put(val); | ||
return this; | ||
} | ||
|
||
public BytesBuffer write(byte[] val, int offset, int length) { | ||
public BytesBuffer writeByteArray(byte[] val, int offset, int length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer keep these methods returning void
} | ||
|
||
public BytesBuffer write(byte[] val, int offset, int length) { | ||
public void write(byte[] val, int offset, int length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add "@OverRide" for 3 write() methods
@@ -36,7 +36,7 @@ | |||
public static BytesBuffer compress(byte[] bytes, int blockSize) { | |||
LZ4Factory factory = LZ4Factory.fastestInstance(); | |||
LZ4Compressor compressor = factory.fastCompressor(); | |||
BytesBuffer buf = new BytesBuffer(bytes.length / 8); | |||
BytesBuffer buf = new BytesBuffer(bytes.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a const var buf_ratio, let init_size=bytes.length/buf_ratio, also update decompress to bytes.length*buf_ratio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ci failed
return compress(value, 0.0F); | ||
} | ||
|
||
public static byte[] compress(String value, float ratio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to not add this method
return decompress(value, 0.0F); | ||
} | ||
|
||
public static String decompress(byte[] value, float ratio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to bufferRatio
cassandra
hbase
|
} catch (IOException e) { | ||
throw new BackendException("Failed to compress: %s", e, value); | ||
} | ||
return compress(value, 0.0F); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define const
return decompress(value, 0.0F); | ||
} | ||
|
||
public static String decompress(byte[] value, float ratio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to bufferRatio
No description provided.