Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/5782#discussion_r29399610
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/jdbc/jdbc.scala ---
@@ -179,4 +184,63 @@ package object jdbc {
}
}
+
+ private [sql] case class DriverWrapper(wrapped: Driver) extends Driver {
+ override def acceptsURL(url: String): Boolean = wrapped.acceptsURL(url)
+
+ override def jdbcCompliant(): Boolean = wrapped.jdbcCompliant()
+
+ override def getPropertyInfo(url: String, info: Properties):
Array[DriverPropertyInfo] = {
+ wrapped.getPropertyInfo(url, info)
+ }
+
+ override def getMinorVersion: Int = wrapped.getMinorVersion
+
+ override def getParentLogger: java.util.logging.Logger =
wrapped.getParentLogger
+
+ override def connect(url: String, info: Properties): Connection =
wrapped.connect(url, info)
+
+ override def getMajorVersion: Int = wrapped.getMajorVersion
+ }
+
+ /**
+ * java.sql.DriverManager is always loaded by bootstrap classloader,
+ * so it can't load JDBC drivers accessible by Spark ClassLoader.
+ *
+ * To solve the problem, drivers from user-supplied jars are wrapped
+ * into thin wrapper.
+ */
+ private [sql] object DriverRegistry extends Logging {
+
+ val wrapperMap: mutable.Map[String, DriverWrapper] = mutable.Map.empty
+
+ val lock = new ReentrantLock()
+
+ def register(className: String): Unit = {
+ val cls = Utils.getContextOrSparkClassLoader.loadClass(className)
+ if (cls.getClassLoader == null) {
+ logTrace(s"$className has been loaded with bootstrap ClassLoader,
wrapper is not required")
+ } else if (wrapperMap.get(className).isDefined) {
+ logTrace(s"Wrapper for $className already exists")
+ } else {
+ lock.lock()
--- End diff --
given this is unlikely to be a performance bottleneck, why not just use a
synchronized block?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]