hvanhovell commented on code in PR #42473:
URL: https://github.com/apache/spark/pull/42473#discussion_r1292613055


##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala:
##########
@@ -17,17 +17,42 @@
 
 package org.apache.spark.sql.catalyst.encoders
 
-import java.util.concurrent.ConcurrentMap
+import java.lang.ref._
+import java.util.Objects
+import java.util.concurrent.ConcurrentHashMap
 
-import com.google.common.collect.MapMaker
-
-import org.apache.spark.sql.errors.QueryExecutionErrors
-import org.apache.spark.util.Utils
+import org.apache.spark.sql.errors.ExecutionErrors
+import org.apache.spark.util.SparkClassUtils
 
 object OuterScopes {
-  @transient
-  lazy val outerScopes: ConcurrentMap[String, AnyRef] =
-    new MapMaker().weakValues().makeMap()
+  private[this] val queue = new ReferenceQueue[AnyRef]
+  private class HashableWeakReference(val v: AnyRef) extends 
WeakReference[AnyRef](v, queue) {
+    private[this] val hash = v.hashCode()
+    override def hashCode(): Int = hash
+    override def equals(obj: Any): Boolean = obj match {
+      case ref: HashableWeakReference =>
+        (this eq ref) || Objects.equals(get(), ref.get())
+    }
+  }
+
+  private def classLoaderRef(c: Class[_]): HashableWeakReference = {
+    new HashableWeakReference(c.getClassLoader)
+  }
+
+  private[this] val outerScopes = {

Review Comment:
   In Spark Connect it is possible to have multiple sessions that define the 
same classes. Using name based lookup will break in this case. We need to 
include the `ClassLoader`. I have added the `ClassLoader` as the top tier in 
the nested map, this way we can easily discard all the entries for a 
`ClassLoader` as it goes out of scope.



-- 
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]

Reply via email to