Github user witgo commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15505#discussion_r96106896
  
    --- Diff: 
core/src/main/scala/org/apache/spark/scheduler/cluster/CoarseGrainedSchedulerBackend.scala
 ---
    @@ -244,32 +245,45 @@ class CoarseGrainedSchedulerBackend(scheduler: 
TaskSchedulerImpl, val rpcEnv: Rp
         // Launch tasks returned by a set of resource offers
         private def launchTasks(tasks: Seq[Seq[TaskDescription]]) {
           for (task <- tasks.flatten) {
    -        val serializedTask = TaskDescription.encode(task)
    -        if (serializedTask.limit >= maxRpcMessageSize) {
    -          scheduler.taskIdToTaskSetManager.get(task.taskId).foreach { 
taskSetMgr =>
    -            try {
    -              var msg = "Serialized task %s:%d was %d bytes, which exceeds 
max allowed: " +
    -                "spark.rpc.message.maxSize (%d bytes). Consider increasing 
" +
    -                "spark.rpc.message.maxSize or using broadcast variables 
for large values."
    -              msg = msg.format(task.taskId, task.index, 
serializedTask.limit, maxRpcMessageSize)
    -              taskSetMgr.abort(msg)
    -            } catch {
    -              case e: Exception => logError("Exception in error callback", 
e)
    -            }
    -          }
    +        val serializedTask = try {
    +          TaskDescription.encode(task)
    +        } catch {
    +          case NonFatal(e) =>
    +            abortTaskSetManager(scheduler, task.taskId,
    +              s"Failed to serialize task ${task.taskId}, not attempting to 
retry it.", Some(e))
    +            null
             }
    -        else {
    +
    +        if (serializedTask != null && serializedTask.limit >= 
maxRpcMessageSize) {
    +          val msg = "Serialized task %s:%d was %d bytes, which exceeds max 
allowed: " +
    +            "spark.rpc.message.maxSize (%d bytes). Consider increasing " +
    +            "spark.rpc.message.maxSize or using broadcast variables for 
large values."
    +          abortTaskSetManager(scheduler, task.taskId,
    +            msg.format(task.taskId, task.index, serializedTask.limit, 
maxRpcMessageSize))
    +        } else if (serializedTask != null) {
    +          if (serializedTask.limit > TaskSetManager.TASK_SIZE_TO_WARN_KB * 
1024) {
    --- End diff --
    
    There are two cases when this nested if can be combined into the else if.
    
    1. The following code to appear twice
    
    ``` scala
    val executorData = executorDataMap(task.executorId)
    executorData.freeCores -= scheduler.CPUS_PER_TASK
    
    logDebug(s"Launching task ${task.taskId} on executor id: ${task.executorId} 
" +
    s" hostname: ${executorData.executorHost}.")
    
    executorData.executorEndpoint.send(LaunchTask(new 
SerializableBuffer(serializedTask)))
    
    ```
    2. Use the return value of the if statement to avoid code duplication
    
    ```scala
      val launchTask = if (serializedTask != null && serializedTask.limit >= 
maxRpcMessageSize) {
          false
        } else if (serializedTask != null &&
          serializedTask.limit > TaskSetManager.TASK_SIZE_TO_WARN_KB * 1024) {
          true
        } else {
          true
        }
        if (launchTask) {
          val executorData = executorDataMap(task.executorId)
          executorData.freeCores -= scheduler.CPUS_PER_TASK
    
          logDebug(s"Launching task ${task.taskId} on executor id: 
${task.executorId} " +
            s" hostname: ${executorData.executorHost}.")
    
          executorData.executorEndpoint.send(LaunchTask(new 
SerializableBuffer(serializedTask)))
        }
    
    ```
    The existing code is more concise than the above.


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

Reply via email to