You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/10/20 16:23:44 UTC

[GitHub] [hudi] alexeykudinkin commented on a diff in pull request #7014: [HUDI-4971] Remove direct use of kryo from `SerDeUtils`

alexeykudinkin commented on code in PR #7014:
URL: https://github.com/apache/hudi/pull/7014#discussion_r1000856404


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/SerDeUtils.scala:
##########
@@ -17,39 +17,26 @@
 
 package org.apache.spark.sql.hudi
 
-import java.io.ByteArrayOutputStream
-
-import com.esotericsoftware.kryo.Kryo
-import com.esotericsoftware.kryo.io.{Input, Output}
 import org.apache.spark.SparkConf
-import org.apache.spark.serializer.KryoSerializer
+import org.apache.spark.serializer.{KryoSerializer, SerializerInstance}
+
+import java.nio.ByteBuffer
 
 
 object SerDeUtils {
 
-  private val kryoLocal = new ThreadLocal[Kryo] {
+  private val SERIALIZER_THREAD_LOCAL = new ThreadLocal[SerializerInstance] {
 
-    override protected def initialValue: Kryo = {
-      val serializer = new KryoSerializer(new SparkConf(true))
-      serializer.newKryo()
+    override protected def initialValue: SerializerInstance = {
+      new KryoSerializer(new SparkConf(true)).newInstance()
     }
   }
 
   def toBytes(o: Any): Array[Byte] = {
-    val outputStream = new ByteArrayOutputStream(4096 * 5)
-    val output = new Output(outputStream)
-    try {
-      kryoLocal.get.writeClassAndObject(output, o)
-      output.flush()
-    } finally {
-      output.clear()
-      output.close()
-    }
-    outputStream.toByteArray
+    SERIALIZER_THREAD_LOCAL.get.serialize(o).array()

Review Comment:
   We can't return an array, since `ByteBuffer` might be pointing into the bigger scratchpad (`array()` will just return an ref to underlying one)



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org