Skip to content

[SPARK-16432] Empty blocks fail to serialize due to assert in ChunkedByteBuffer #14099

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ import org.apache.spark.storage.StorageUtils
* Read-only byte buffer which is physically stored as multiple chunks rather than a single
* contiguous array.
*
* @param chunks an array of [[ByteBuffer]]s. Each buffer in this array must be non-empty and have
* position == 0. Ownership of these buffers is transferred to the ChunkedByteBuffer,
* so if these buffers may also be used elsewhere then the caller is responsible for
* copying them as needed.
* @param chunks an array of [[ByteBuffer]]s. Each buffer in this array must have position == 0.
* Ownership of these buffers is transferred to the ChunkedByteBuffer, so if these
* buffers may also be used elsewhere then the caller is responsible for copying
* them as needed.
*/
private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) {
require(chunks != null, "chunks must not be null")
require(chunks.forall(_.limit() > 0), "chunks must be non-empty")
require(chunks.forall(_.position() == 0), "chunks' positions must be 0")

private[this] var disposed: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ class ChunkedByteBufferSuite extends SparkFunSuite {
emptyChunkedByteBuffer.toInputStream(dispose = true).close()
}

test("chunks must be non-empty") {
intercept[IllegalArgumentException] {
new ChunkedByteBuffer(Array(ByteBuffer.allocate(0)))
}
}

test("getChunks() duplicates chunks") {
val chunkedByteBuffer = new ChunkedByteBuffer(Array(ByteBuffer.allocate(8)))
chunkedByteBuffer.getChunks().head.position(4)
Expand All @@ -63,8 +57,9 @@ class ChunkedByteBufferSuite extends SparkFunSuite {
}

test("toArray()") {
val empty = ByteBuffer.wrap(Array[Byte]())
val bytes = ByteBuffer.wrap(Array.tabulate(8)(_.toByte))
val chunkedByteBuffer = new ChunkedByteBuffer(Array(bytes, bytes))
val chunkedByteBuffer = new ChunkedByteBuffer(Array(bytes, bytes, empty))
assert(chunkedByteBuffer.toArray === bytes.array() ++ bytes.array())
}

Expand All @@ -79,9 +74,10 @@ class ChunkedByteBufferSuite extends SparkFunSuite {
}

test("toInputStream()") {
val empty = ByteBuffer.wrap(Array[Byte]())
val bytes1 = ByteBuffer.wrap(Array.tabulate(256)(_.toByte))
val bytes2 = ByteBuffer.wrap(Array.tabulate(128)(_.toByte))
val chunkedByteBuffer = new ChunkedByteBuffer(Array(bytes1, bytes2))
val chunkedByteBuffer = new ChunkedByteBuffer(Array(empty, bytes1, bytes2))
assert(chunkedByteBuffer.size === bytes1.limit() + bytes2.limit())

val inputStream = chunkedByteBuffer.toInputStream(dispose = false)
Expand Down