Uh oh!
There was an error while loading. Please reload this page.
ARROW-10880: [Java] Support compressing RecordBatch IPC buffers by LZ4 - #8949
ARROW-10880: [Java] Support compressing RecordBatch IPC buffers by LZ4#8949liyafan82 wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Do we need to ensure this in little-endian? (c.f. https://github.com/apache/arrow/blob/master/cpp/src/arrow/ipc/reader.cc#L385).
There was a problem hiding this comment.
Revised accordingly. Thanks for your kind reminder.
kiszk
commented
Jan 4, 2021
Looks good to me |
There was a problem hiding this comment.
How was this library chosen? It looks like it might not have been released in a while?
There was a problem hiding this comment.
@kiszk You are right. I chose this library because our C++ implementation also depends on this repo (https://github.com/lz4/lz4).
There was a problem hiding this comment.
| publicArrowBufcompress(BufferAllocatorallocator, ArrowBufunCompressedBuffer) { | |
| publicArrowBufcompress(BufferAllocatorallocator, ArrowBufuncompressedBuffer) { |
There was a problem hiding this comment.
? or is this consistent with the existing API?
There was a problem hiding this comment.
For some scenarios (e.g. flight sender), we only need the compressor, while for others (e.g. flight receiver), we only need the decompressor. So there is no need to create both eagerly.
emkornfield
commented
Jan 4, 2021
Is it possible to add a test to confirm that this can be read/written from the C++ implementation? |
When I use the changes and try to compress and decompress an empty buffer (by using a variable sized vector with only missing values) I get a SIGSEGV (hs_err_pid10504.log): This can be reproduced by adding the following test to @TestpublicvoidtestEmptyBuffer() throwsException {
finalintvecLength = 10;
finalVarBinaryVectororigVec = newVarBinaryVector("vec", allocator);
origVec.allocateNew(vecLength);
// Do not set any values (all missing)origVec.setValueCount(vecLength);
finalList<ArrowBuf> origBuffers = origVec.getFieldBuffers();
finalList<ArrowBuf> compressedBuffers = compressBuffers(origBuffers);
finalList<ArrowBuf> decompressedBuffers = deCompressBuffers(compressedBuffers);
// TODO assert that the decompressed buffers are correctAutoCloseables.close(decompressedBuffers);
}This looks like an error in the lz4-java library but I am not sure. I thought I should mention it here first. |
liyafan82
commented
Jan 6, 2021
@emkornfield I think it is a good idea to provide e2e cross-language integration tests. In particular, we need to change the way buffers are released after compressing. Solution to this problem may have impacts to other parts of the code base. So maybe we need another issue to discuss it (if we do not do it in this PR). |
liyafan82
commented
Jan 6, 2021
@HedgehogCode Thanks a lot for your effort and information. I will take a look at the problem. |
liyafan82
commented
Jan 7, 2021
@HedgehogCode The problem happend when lz4-java tried to decompress an empty buffer. I have fixed the problem by taking special case of empty buffers. Thanks again for your kind reminder. |
There was a problem hiding this comment.
nit: the capacity may be (int) (compressedBuffer.writerIndex() - SIZE_OF_MESSAGE_LENGTH)?
There was a problem hiding this comment.
Nice catch. Thank you @stczwd
HedgehogCode
commented
Jan 12, 2021
The comment in the BodyCompression protobuf states:
Should the check for a length of -1 be made outside of Should be pretty easy if I don't miss something: if (decompressedLength == -1L) {
// handle uncompressed buffersreturncompressedBuffer.slice(SIZE_OF_MESSAGE_LENGTH,
compressedBuffer.writerIndex() - SIZE_OF_MESSAGE_LENGTH);
} |
liyafan82
commented
Jan 15, 2021
@HedgehogCode Thanks for your good suggestion. I have revised the code to implement the logic that when the compressed buffer is larger, we directly send the raw buffer with length -1. In addition, I have updated the test cast to make sure the code path of the logic is covered. |
emkornfield
commented
Jan 30, 2021
@liyafan82 per recent discussion on mailing list. I looked into it and the lz4 page mentioned https://commons.apache.org/proper/commons-compress/javadocs/api-release/org/apache/commons/compress/compressors/lz4/package-summary.html as a port, so that might offer better compatibiity as a library |
liyafan82
commented
Feb 1, 2021
@emkornfield Sounds reasonable. I will update the PR accordingly. Thanks for your good suggestion. |
pitrou
commented
Feb 3, 2021
See PR #9408 for integration tests. |
liyafan82
commented
Feb 4, 2021
Switched to the commons-compress library, according to @emkornfield's suggestion. |
emkornfield
commented
Feb 11, 2021
@liyafan82 could you enable the java integration test to confirm that reading the files generated by C++ works before we merge (once we verify it is working I can take a final look) |
There was a problem hiding this comment.
I'm a little hesitant to take a direct dependency on any lz4 library. Is there away that this can be done optionally (similar to how the netty dependency for memory has been isolated?)
There was a problem hiding this comment.
@emkornfield Sounds reasonable. I will try to revise the PR accordingly. Thanks for your good suggestion.
liyafan82
commented
Feb 12, 2021
Sure. I will do some tests for that. |
emkornfield
commented
Feb 13, 2021
To run tests it should be sufficient to unskip the Java implementation in archery. |
d59982e to
5160d84Compareliyafan82
commented
Feb 24, 2021
To avoid the direct dependency on the lz4 library, I have extracted the concrete compression codec implementations to a separate module. Will continue to work on the integration tests. |
emkornfield
commented
Mar 10, 2021
@liyafan82 let me know when you think this is ready for re-review. I think like I said I think getting a baseline working so we can do the follow-up work makes the most sense here. |
liyafan82
commented
Mar 10, 2021
@emkornfield Sorry for my delay. I am a little busy these days. I will try my best to make it ready in one or two days. |
emkornfield
commented
Mar 10, 2021
No, rush just wanted to make sure I knew when it was ready for another pass. |
8aab6b5 to
b28986cCompareliyafan82
commented
Mar 11, 2021
@emkornfield I have replied to each of the previous comment. So maybe it is ready for a new round of review. Thanks. |
emkornfield
left a comment
There was a problem hiding this comment.
Thank @liyafan82 a few more minor comments. I'd like to see this merged sooner rather then later so we can do the follow-up work. If you don't have bandwidth please let me know, and if it OK I can fixup my comments and push to this PR?
There was a problem hiding this comment.
hmm, wonder why netty is required here though, I'll take a closer look.
There was a problem hiding this comment.
please update the docs to match, something like.
"Slice the buffer to contain the uncompressed bytes"
There was a problem hiding this comment.
ahh this is where netty is used. we don't have an arrow wrapper for it?
There was a problem hiding this comment.
I guess no for now. Maybe we can have one in the future, so we can remove the dependency on Netty (and other dependencies on Netty as well).
There was a problem hiding this comment.
With the new enum, maybe we can make this an accessor that returns and enum instead? and then the byte can be extracted from there where necesssary?
liyafan82
commented
Mar 17, 2021
@emkornfield Thanks a lot for the further comments. I think I can fix them up today. |
liyafan82
commented
Mar 17, 2021
Sounds good. I have revised the code accordingly. |
liyafan82
commented
Mar 17, 2021
Updated. Thank you. |
emkornfield
commented
Mar 17, 2021
+1 thank you. @liyafan82 did you have plans to work on the follow-up items or ZSTD? Otherwise I can take them up. @HedgehogCode any thoughts on how to procede for LZ4? We can maybe discuss more on the performance JIRA? |
liyafan82
commented
Mar 18, 2021
@emkornfield Thanks a lot for your effort. I have started working on ARROW-11899 yesterday. |
emkornfield
commented
Mar 18, 2021
If you've already started ARROW-11899 then I'll let you finish it up, hopefully it isn't too much work. We are discussing on the ML the path forward for LZ4 in general, once that is cleared up we can figure out do the work including if @HedgehogCode is interesting in contributing. |
liyafan82
commented
Mar 18, 2021
Sounds good. Hopefully, I will prepare a PR in a few days. |
pitrou
commented
Mar 22, 2021
@liyafan82@emkornfield Can you one of you update https://github.com/apache/arrow/blob/master/docs/source/status.rst#ipc-format once this is all finished? |
liyafan82
commented
Mar 23, 2021
@pitrou I will keep this in mind. Thanks for your kind reminder. |
Support compressing/decompressing RecordBatch IPC buffers by LZ4. Closesapache#8949 from liyafan82/fly_1211_comp Authored-by: liyafan82 <fan_li_ya@foxmail.com> Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
Support compressing/decompressing RecordBatch IPC buffers by LZ4.