-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-24107][CORE] ChunkedByteBuffer.writeFully method has not reset the limit value #21175
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 3 commits
fae1814
623f26d
5ba6867
c585131
a2a82f1
217ec9d
2bc19a3
c9a6816
fa99a19
fb527c8
e78ef39
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 |
|---|---|---|
|
|
@@ -63,10 +63,12 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) { | |
| */ | ||
| def writeFully(channel: WritableByteChannel): Unit = { | ||
| for (bytes <- getChunks()) { | ||
| val limit = bytes.limit() | ||
| while (bytes.remaining() > 0) { | ||
|
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 not related to this pr though, |
||
| val ioSize = Math.min(bytes.remaining(), bufferWriteChunkSize) | ||
| bytes.limit(bytes.position() + ioSize) | ||
| channel.write(bytes) | ||
| bytes.limit(limit) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,12 @@ class ChunkedByteBufferSuite extends SparkFunSuite { | |
| assert(chunkedByteBuffer.getChunks().head.position() === 0) | ||
| } | ||
|
|
||
| test("writeFully() does not affect original buffer's position") { | ||
|
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. Hi @Manbuyun .You should add a new unit test to support your own change. For example, "writeFully() can write buffer which is larger than
Author
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. Done. Thanks |
||
| val chunkedByteBuffer = new ChunkedByteBuffer(Array(ByteBuffer.allocate(80*1024*1024))) | ||
|
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. nit: space beside
Author
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. Done. Thanks |
||
| chunkedByteBuffer.writeFully(new ByteArrayWritableChannel(chunkedByteBuffer.size.toInt)) | ||
| assert(chunkedByteBuffer.getChunks().head.position() === 0) | ||
|
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 assert is unnecessary for this PR change. Please replace it with assert channel's length here. |
||
| } | ||
|
|
||
| test("toArray()") { | ||
| val empty = ByteBuffer.wrap(Array.empty[Byte]) | ||
| val bytes = ByteBuffer.wrap(Array.tabulate(8)(_.toByte)) | ||
|
|
||
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.
How about renaming
limittocurChunkLimit?