Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions core/src/main/java/org/apache/spark/TaskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TaskContext implements Serializable {
* @param taskMetrics performance metrics of the task
*/
@DeveloperApi
public TaskContext(Integer stageId, Integer partitionId, Long attemptId, Boolean runningLocally,
public TaskContext(int stageId, int partitionId, long attemptId, boolean runningLocally,
TaskMetrics taskMetrics) {
this.attemptId = attemptId;
this.partitionId = partitionId;
Expand All @@ -65,7 +65,6 @@ public TaskContext(Integer stageId, Integer partitionId, Long attemptId, Boolean
this.taskMetrics = taskMetrics;
}


/**
* :: DeveloperApi ::
* Contextual information about a task which can be read or mutated during execution.
Expand All @@ -76,16 +75,14 @@ public TaskContext(Integer stageId, Integer partitionId, Long attemptId, Boolean
* @param runningLocally whether the task is running locally in the driver JVM
*/
@DeveloperApi
public TaskContext(Integer stageId, Integer partitionId, Long attemptId,
Boolean runningLocally) {
public TaskContext(int stageId, int partitionId, long attemptId, boolean runningLocally) {
this.attemptId = attemptId;
this.partitionId = partitionId;
this.runningLocally = runningLocally;
this.stageId = stageId;
this.taskMetrics = TaskMetrics.empty();
}


/**
* :: DeveloperApi ::
* Contextual information about a task which can be read or mutated during execution.
Expand All @@ -95,7 +92,7 @@ public TaskContext(Integer stageId, Integer partitionId, Long attemptId,
* @param attemptId the number of attempts to execute this task
*/
@DeveloperApi
public TaskContext(Integer stageId, Integer partitionId, Long attemptId) {
public TaskContext(int stageId, int partitionId, long attemptId) {
this.attemptId = attemptId;
this.partitionId = partitionId;
this.runningLocally = false;
Expand All @@ -107,9 +104,9 @@ public TaskContext(Integer stageId, Integer partitionId, Long attemptId) {
new ThreadLocal<TaskContext>();

/**
* :: Internal API ::
* This is spark internal API, not intended to be called from user programs.
*/
* :: Internal API ::
* This is spark internal API, not intended to be called from user programs.
*/
public static void setTaskContext(TaskContext tc) {
taskContext.set(tc);
}
Expand All @@ -118,10 +115,8 @@ public static TaskContext get() {
return taskContext.get();
}

/**
* :: Internal API ::
*/
public static void remove() {
/** :: Internal API :: */
public static void unset() {
taskContext.remove();
}

Expand All @@ -130,22 +125,22 @@ public static void remove() {
new ArrayList<TaskCompletionListener>();

// Whether the corresponding task has been killed.
private volatile Boolean interrupted = false;
private volatile boolean interrupted = false;

// Whether the task has completed.
private volatile Boolean completed = false;
private volatile boolean completed = false;

/**
* Checks whether the task has completed.
*/
public Boolean isCompleted() {
public boolean isCompleted() {
return completed;
}

/**
* Checks whether the task has been killed.
*/
public Boolean isInterrupted() {
public boolean isInterrupted() {
return interrupted;
}

Expand Down Expand Up @@ -246,12 +241,12 @@ public long attemptId() {
}

@Deprecated
/** Deprecated: use getRunningLocally() */
/** Deprecated: use isRunningLocally() */
public boolean runningLocally() {
return runningLocally;
}

public boolean getRunningLocally() {
public boolean isRunningLocally() {
return runningLocally;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class DAGScheduler(
job.listener.taskSucceeded(0, result)
} finally {
taskContext.markTaskCompleted()
TaskContext.remove()
TaskContext.unset()
}
} catch {
case e: Exception =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ private[spark] class ResultTask[T, U](
ByteBuffer.wrap(taskBinary.value), Thread.currentThread.getContextClassLoader)

metrics = Some(context.taskMetrics)
try {
func(context, rdd.iterator(partition, context))
} finally {
context.markTaskCompleted()
}
func(context, rdd.iterator(partition, context))
}

// This is only callable on the driver side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ private[spark] class ShuffleMapTask(
log.debug("Could not stop writer", e)
}
throw e
} finally {
context.markTaskCompleted()
}
}

Expand Down
8 changes: 6 additions & 2 deletions core/src/main/scala/org/apache/spark/scheduler/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ private[spark] abstract class Task[T](val stageId: Int, var partitionId: Int) ex
if (_killed) {
kill(interruptThread = false)
}
runTask(context)
try {
runTask(context)
} finally {
context.markTaskCompleted()
TaskContext.unset()
}
}

def runTask(context: TaskContext): T
Expand Down Expand Up @@ -93,7 +98,6 @@ private[spark] abstract class Task[T](val stageId: Int, var partitionId: Int) ex
if (interruptThread && taskThread != null) {
taskThread.interrupt()
}
TaskContext.remove()
}
}

Expand Down