LuciferYang opened a new issue, #12616:
URL: https://github.com/apache/gluten/issues/12616

   ### Backend
   
   VL (Velox) — the logic is backend-agnostic and lives in `gluten-core`.
   
   ### Bug description
   
   `SparkResourceUtil.getTaskSlots` computes `executorCores / taskCores` with 
no guard:
   
   ```scala
   def getTaskSlots(conf: SparkConf): Int = {
     val executorCores = SparkResourceUtil.getExecutorCores(conf)
     val taskCores = conf.getInt("spark.task.cpus", 1)
     executorCores / taskCores
   }
   ```
   
   `GlutenDriverPlugin.init` reads this slot count and divides by it (e.g. 
`GlutenPlugin.setPredefinedConfigs` does `offHeapSize / taskSlots`), and four 
other callers use it as a denominator too (`MemoryTargets`, 
`ColumnarShuffleWriter`, and the Celeborn/Uniffle writers). Two invalid 
configurations crash there with an opaque error instead of Spark's own clear 
message:
   
   - `spark.task.cpus > spark.executor.cores` (e.g. `executor.cores=1`, 
`task.cpus=2`): integer division yields `0`, so a caller's `offHeapSize / 
taskSlots` throws `ArithmeticException: / by zero`.
   - `spark.task.cpus = 0`: `getTaskSlots` itself throws `ArithmeticException: 
/ by zero`. `getTaskSlots` reads the value with raw `conf.getInt`, which 
bypasses Spark's `CPUS_PER_TASK.checkValue(_ > 0)` (that check only fires on 
the typed `conf.get(CPUS_PER_TASK)`).
   
   The plugin runs at `SparkContext`'s `PluginContainer(this, ...)` step, which 
is before `createTaskScheduler` and the resource-profile validation. So Gluten 
throws first, and the user sees a Gluten `ArithmeticException` stack trace 
instead of Spark's actionable messages (`validateTaskCpusLargeEnough`: "cores 
per executor has to be >= cpus per task", or `CPUS_PER_TASK`: "should be 
positive").
   
   Both are invalid configs that Spark rejects anyway, so the job should not 
start either way. The problem is the diagnostic: an opaque divide-by-zero with 
a Gluten stack trace misattributes the failure to Gluten.
   
   ### Gluten version
   
   main (1.8.0-SNAPSHOT)
   
   ### Spark version
   
   Version-agnostic (applies to spark-3.3 / 3.4 / 3.5 / 4.0 / 4.1).
   
   ### Spark configurations
   
   - `spark.plugins=org.apache.gluten.GlutenPlugin`
   - Either `spark.task.cpus > spark.executor.cores`, or `spark.task.cpus=0`.
   
   ### System information
   
   N/A — logic issue in 
`gluten-core/src/main/scala/org/apache/spark/util/SparkResourceUtil.scala`, 
independent of OS/hardware.
   
   ### Relevant logs
   
   ```text
   java.lang.ArithmeticException: / by zero
     at 
org.apache.spark.util.SparkResourceUtil$.getTaskSlots(SparkResourceUtil.scala:81)
     at 
org.apache.gluten.GlutenPlugin$GlutenDriverPlugin.setPredefinedConfigs(GlutenPlugin.scala:...)
     at org.apache.gluten.GlutenPlugin$GlutenDriverPlugin.init(...)
   ```
   
   ### Fix direction
   
   Guard `getTaskSlots` so it never divides by a non-positive `taskCores` and 
never returns 0: return a single slot for `taskCores <= 0`, and floor the 
quotient at 1 otherwise. Gluten then defers to Spark's own validation for the 
clear error message.
   


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