grpc-okhttp: implement OkHttpReadableBuffer readBytes(ByteBuffer dest)#12579
grpc-okhttp: implement OkHttpReadableBuffer readBytes(ByteBuffer dest)#12579NguyenHoangSon96 wants to merge 2 commits intogrpc:masterfrom
Conversation
|
Hi @ejona86 , can you help me reviewing this PR. |
shivaspeaks
left a comment
There was a problem hiding this comment.
I don't see there'd be any harm with your PR.
Should we go with something like this to align and be consistent with the rest of the codebase?
@Override
public void readBytes(ByteBuffer dest) {
int remaining = dest.remaining();
try {
int read = buffer.read(dest);
if (read < remaining) {
throw new IndexOutOfBoundsException("EOF trying to read " + remaining + " bytes");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
Hi @shivaspeaks |
ejona86
left a comment
There was a problem hiding this comment.
NAK. I don't mind the implementation, but the reason for the change is very, very bad.
Arrow is using our internals via reflection. This is not okay. Not only is it accessing internal classes, it is digging into its fields. In no way is that acceptable, and in no way are we going to assist in that.
This is an Arrow bug, and that code should be removed in Arrow.
There's no need to dig into our internals for accessing the ByteBuffer (which is what GetReadableBuffer reports to do). We have zero-copy APIs. They can use HasByteBuffer.getByteBuffer()+InputStream.skip() to loop through the ByteBuffers. If they want to access all the byte buffers simultaneously (as skip() will deallocate the last byte buffer, just like read() does), then they can use InputStream.mark(). If they want to take over ownership of the ByteBuffers, then they can use Detachable.detach().
|
Closing in favor of deleting the method. #12580 |
|
Sorry about that. I've opened an issue to get rid of the sketchy code: apache/arrow-java#939 (Albeit, I'd rather recommend people use gRPC directly, I don't think having a gRPC wrapper in our code was really ever a good idea in the first place, but I don't think I can win that battle...) |
Proposed Changes
Changes
readToByteBufferShouldSucceedtest runs for OkHttpReadableBuffer.Additional Information
throw new RuntimeException(e), I'm not sure if this line need to be tested.