zhztheplayer commented on code in PR #10708:
URL:
https://github.com/apache/incubator-gluten/pull/10708#discussion_r2352760750
##########
gluten-core/src/main/scala/org/apache/spark/util/SparkDirectoryUtil.scala:
##########
@@ -67,16 +68,19 @@ class SparkDirectoryUtil private (val roots: Array[String])
extends Logging {
}
object SparkDirectoryUtil extends Logging {
+ private val state = new AtomicBoolean(false)
Review Comment:
Let's rename it. E.g., `INSTANCE_INITIALIZED`
##########
gluten-core/src/main/scala/org/apache/spark/util/SparkDirectoryUtil.scala:
##########
@@ -67,16 +68,19 @@ class SparkDirectoryUtil private (val roots: Array[String])
extends Logging {
}
object SparkDirectoryUtil extends Logging {
+ private val state = new AtomicBoolean(false)
private var INSTANCE: SparkDirectoryUtil = _
- def init(conf: SparkConf): Unit = synchronized {
+ def init(conf: SparkConf): Unit = {
val roots = Utils.getConfiguredLocalDirs(conf)
init(roots)
}
- private def init(roots: Array[String]): Unit = synchronized {
+ private def init(roots: Array[String]): Unit = {
if (INSTANCE == null) {
- INSTANCE = new SparkDirectoryUtil(roots)
+ if (state.compareAndSet(false, true)) {
+ INSTANCE = new SparkDirectoryUtil(roots)
+ }
return
Review Comment:
It's not the hot code path, let's remove the `if (INSTANCE == null)`
condition.
Just directly call `compareAndSet`.
##########
gluten-core/src/main/scala/org/apache/spark/util/SparkDirectoryUtil.scala:
##########
@@ -87,7 +91,7 @@ object SparkDirectoryUtil extends Logging {
}
}
- def get(): SparkDirectoryUtil = synchronized {
+ def get(): SparkDirectoryUtil = {
assert(INSTANCE != null, "Default instance of SparkDirectoryUtil was not
set yet")
INSTANCE
}
Review Comment:
The get operation is not synchronized.
--
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]