-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12078][Core]Fix ByteBuffer.limit misuse #10076
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,8 +109,8 @@ private[spark] class ExternalBlockStore(blockManager: BlockManager, executorId: | |
| if (externalBlockManager.isDefined) { | ||
| val byteBuffer = bytes.duplicate() | ||
| byteBuffer.rewind() | ||
| val size = bytes.remaining() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting one. The original |
||
| externalBlockManager.get.putBytes(blockId, byteBuffer) | ||
| val size = bytes.limit() | ||
| val data = if (returnValues) { | ||
| Right(bytes) | ||
| } else { | ||
|
|
||
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.
You're right that there's an implicit assumption in some of this code that the buffer's position is 0 on returning, and the entire buffer is filled with valid data. Do we have a situation where the position is not 0 though, but is correctly at the start of the data? at least, this looks like it handles the situation, but it sounds unusual. Equally, if that's an issue, are we sure the entire buffer has valid data, through the end? that assumption is still present here, that the end of the data is the end of the buffer.
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.
If a
ByteBufferis from Netty, the position could be a non-zero value.The
ByteBuffermay contain more data internally, but the user should only read the part betweenpositionandlimit. I think that's defined inByteBuffer/Bufferjavadoc.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.
I found I was wrong about the position of
ByteBufferfrom Netty. Netty will callByteBuffer.sliceto reset the position to 0 before returning it: https://github.com/netty/netty/blob/0f9492c9affc528c766f9677952412564d4a3f6d/buffer/src/main/java/io/netty/buffer/PooledHeapByteBuf.java#L269I think we don't need this patch.