Copilot commented on code in PR #13098:
URL: https://github.com/apache/gluten/pull/13098#discussion_r4073297548


##########
gluten-core/src/test/scala/org/apache/spark/util/SparkDirectoryUtilSuite.scala:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.util
+
+import org.apache.spark.SparkConf
+
+import org.scalatest.funsuite.AnyFunSuite
+
+import java.io.File
+import java.nio.file.Files
+
+class SparkDirectoryUtilSuite extends AnyFunSuite {
+
+  test("namespace fails fast naming the configured local dirs when none can be 
created") {
+    // A regular file cannot host a local directory, so directory creation 
fails
+    // for every configured root.
+    val notADir = Files.createTempFile("gluten-not-a-dir", ".tmp")
+    notADir.toFile.deleteOnExit()
+    val conf = new SparkConf()
+      .set("spark.master", "local[1]")
+      .set("spark.local.dirs", notADir.toAbsolutePath.toString)
+      .set("spark.local.dir", notADir.toAbsolutePath.toString)
+    SparkDirectoryUtil.init(conf)
+    val exception = intercept[IllegalStateException] {
+      SparkDirectoryUtil.get().namespace("test-namespace")
+    }

Review Comment:
   `SparkDirectoryUtil.init(conf)` mutates global singleton state, and per the 
shown `init(roots)` logic it cannot be reinitialized with different roots once 
set. This makes the test order-dependent and potentially flaky when the overall 
test JVM has already initialized `SparkDirectoryUtil` elsewhere. Prefer 
avoiding the global singleton in unit tests by adding a small test-only 
factory/reset hook (e.g., `SparkDirectoryUtil.createForTesting(roots: 
Array[String])` or `resetForTesting()`), and use that here so the suite is 
hermetic.



##########
gluten-core/src/main/scala/org/apache/spark/util/SparkDirectoryUtil.scala:
##########
@@ -98,16 +103,19 @@ class Namespace(private val parents: Array[File], private 
val name: String) {
       path.toFile
   }
 
+  if (all.isEmpty) {
+    throw new IllegalStateException(
+      s"No available Gluten local directory in namespace '$name'")

Review Comment:
   This `Namespace`-level safety-net error omits the set of candidate parent 
directories, which can make debugging harder (especially if `namespace(...)` is 
bypassed or called from other paths). Consider including the parent list (or 
the resolved `all` roots) in the message so operators can immediately see what 
was attempted.



##########
gluten-core/src/main/scala/org/apache/spark/util/SparkDirectoryUtil.scala:
##########
@@ -57,8 +56,14 @@ class SparkDirectoryUtil private (val roots: Array[String]) 
extends Logging {
   private val NAMESPACE_MAPPING: java.util.Map[String, Namespace] =
     new ConcurrentHashMap[String, Namespace]
 
-  def namespace(name: String): Namespace =
+  def namespace(name: String): Namespace = {
+    if (ROOTS.isEmpty) {
+      throw new IllegalStateException(
+        s"No available Gluten local directory for namespace '$name': none of 
the configured " +
+          s"local directories ${roots.mkString(", ")} could be created")

Review Comment:
   The exception message concatenates configured roots via `roots.mkString(\", 
\")` without delimiters/quoting, which can be ambiguous (e.g., paths containing 
commas/spaces) and also reads oddly if `roots` is empty. Consider formatting as 
`Array(...)` (or quoting each path) and explicitly handling the empty-config 
case (e.g., clearly stating that no local directories were configured) to make 
the failure actionable.



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