mridulm commented on code in PR #38064:
URL: https://github.com/apache/spark/pull/38064#discussion_r1005277570
##########
core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala:
##########
@@ -84,6 +92,64 @@ private[spark] class ChunkedByteBuffer(var chunks:
Array[ByteBuffer]) {
}
}
+ /**
+ * write to stream with zero copy if possible
+ */
+ def writeToStream(out: OutputStream): Unit = {
+ var buffer: Array[Byte] = null
+ val bufferLen = 1024 * 1024
+ writeBufferToDest(this, out.write)
+ }
+
+ /**
+ * write to ObjectOutput with zero copy if possible
+ */
+ override def writeExternal(out: ObjectOutput): Unit = {
+ // we want to keep the chunks layout
+ out.writeInt(chunks.length)
+ chunks.foreach(buffer => out.writeInt(buffer.limit()))
+ chunks.foreach(buffer => out.writeBoolean(buffer.isDirect))
+ writeBufferToDest(this, out.write)
+ }
+
+ override def readExternal(in: ObjectInput): Unit = {
+ val chunksNum = in.readInt()
+ val indices = 0 until chunksNum
+ val chunksSize = indices.map(_ => in.readInt())
+ val chunksDirect = indices.map(_ => in.readBoolean())
Review Comment:
Looks like we are still preservin `chunksDirect`, remove it ? And always
deserialize to heap buffer via `ByteBuffer.wrap` ?
##########
core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala:
##########
@@ -84,6 +92,64 @@ private[spark] class ChunkedByteBuffer(var chunks:
Array[ByteBuffer]) {
}
}
+ /**
+ * write to stream with zero copy if possible
+ */
+ def writeToStream(out: OutputStream): Unit = {
+ var buffer: Array[Byte] = null
+ val bufferLen = 1024 * 1024
+ writeBufferToDest(this, out.write)
+ }
+
+ /**
+ * write to ObjectOutput with zero copy if possible
+ */
+ override def writeExternal(out: ObjectOutput): Unit = {
+ // we want to keep the chunks layout
+ out.writeInt(chunks.length)
+ chunks.foreach(buffer => out.writeInt(buffer.limit()))
+ chunks.foreach(buffer => out.writeBoolean(buffer.isDirect))
+ writeBufferToDest(this, out.write)
+ }
+
+ override def readExternal(in: ObjectInput): Unit = {
+ val chunksNum = in.readInt()
+ val indices = 0 until chunksNum
+ val chunksSize = indices.map(_ => in.readInt())
+ val chunksDirect = indices.map(_ => in.readBoolean())
Review Comment:
Looks like we are still preserving `chunksDirect`, remove it ? And always
deserialize to heap buffer via `ByteBuffer.wrap` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]