dbtsai commented on a change in pull request #26530: [SPARK-25694][SQL] Add a 
config for `URL.setURLStreamHandlerFactory`
URL: https://github.com/apache/spark/pull/26530#discussion_r347195908
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala
 ##########
 @@ -191,11 +195,18 @@ private[sql] class SharedState(
 }
 
 object SharedState extends Logging {
-  try {
-    URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory())
-  } catch {
-    case e: Error =>
-      logWarning("URL.setURLStreamHandlerFactory failed to set 
FsUrlStreamHandlerFactory")
+  private val fsUrlStreamHandlerFactoryInitialized = new AtomicBoolean(false)
+
+  private def setFsUrlStreamHandlerFactory(conf: SparkConf): Unit = {
+    if (conf.get(DEFAULT_URL_STREAM_HANDLER_FACTORY_ENABLED) &&
+        fsUrlStreamHandlerFactoryInitialized.compareAndSet(false, true)) {
+      try {
+        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory())
 
 Review comment:
   We need to set `isInitialized = true` after the 
`URL.setURLStreamHandlerFactory`, so I feel double-check pattern is much more 
preferable than `AtomicBoolean`.
   
   I mean the other thread constructing `class SharedState`. 
   
   Yeah, let's say two threads are constructing `class SharedState`, and the 
first thread set `isInitialized = true`, and then starts to run actual 
`URL.setURLStreamHandlerFactory`. The second thread see `isInitialized == 
true`, and finishes the construction before the first thread actually 
initializes `URL.setURLStreamHandlerFactory`, this will cause problem.
   
   In double check pattern, this is not an issue since the whole thing will be 
locked until the first thread finishes the initialization. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to