-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33277][PYSPARK][SQL] Use ContextAwareIterator to stop consuming after the task ends. #30899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,7 @@ trait EvalPythonExec extends UnaryExecNode { | |
|
|
||
| inputRDD.mapPartitions { iter => | ||
| val context = TaskContext.get() | ||
| val contextAwareIterator = new ContextAwareIterator(iter, context) | ||
|
|
||
| // The queue used to buffer input rows so we can drain it to | ||
| // combine input with output from Python. | ||
|
|
@@ -120,7 +121,7 @@ trait EvalPythonExec extends UnaryExecNode { | |
| }.toSeq) | ||
|
|
||
| // Add rows to queue to join later with the result. | ||
| val projectedRowIter = iter.map { inputRow => | ||
| val projectedRowIter = contextAwareIterator.map { inputRow => | ||
| queue.add(inputRow.asInstanceOf[UnsafeRow]) | ||
| projection(inputRow) | ||
| } | ||
|
|
@@ -137,3 +138,18 @@ trait EvalPythonExec extends UnaryExecNode { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A TaskContext aware iterator. | ||
| * | ||
| * As the Python evaluation consumes the parent iterator in a separate thread, | ||
| * it could consume more data from the parent even after the task ends and the parent is closed. | ||
| * Thus, we should use ContextAwareIterator to stop consuming after the task ends. | ||
| */ | ||
| class ContextAwareIterator[IN](iter: Iterator[IN], context: TaskContext) extends Iterator[IN] { | ||
|
||
|
|
||
| override def hasNext: Boolean = | ||
| !context.isCompleted() && !context.isInterrupted() && iter.hasNext | ||
|
|
||
| override def next(): IN = iter.next() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add "If an off-heap column vector exists in the parent iterator, it could cause segmentation fault which crashes the executor." here too?
Current phrase is not clear why it is bad to read closed parent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the sentence. Thanks!