-
Notifications
You must be signed in to change notification settings - Fork 29k
[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 6 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) { | ||
|
||
| 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("SPARK-24107: writeFully() write buffer which is larger than bufferWriteChunkSize") { | ||
| val chunkedByteBuffer = new ChunkedByteBuffer(Array(ByteBuffer.allocate(80 * 1024 * 1024))) | ||
|
||
| chunkedByteBuffer.writeFully(new ByteArrayWritableChannel(chunkedByteBuffer.size.toInt)) | ||
| assert(chunkedByteBuffer.size === (80L * 1024L * 1024L)) | ||
|
||
| } | ||
|
|
||
| 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?