-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24822][PySpark] Python support for barrier execution mode #22011
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2406,6 +2406,22 @@ def toLocalIterator(self): | |
| sock_info = self.ctx._jvm.PythonRDD.toLocalIteratorAndServe(self._jrdd.rdd()) | ||
| return _load_from_socket(sock_info, self._jrdd_deserializer) | ||
|
|
||
| def barrier(self): | ||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| Indicates that Spark must launch the tasks together for the current stage. | ||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
| return RDDBarrier(self) | ||
|
|
||
| def _is_barrier(self): | ||
| """ | ||
| Whether this RDD is in a barrier stage. | ||
| """ | ||
| return self._jrdd.rdd().isBarrier() | ||
|
|
||
|
|
||
| def _prepare_for_python_RDD(sc, command): | ||
| # the serialized command will be compressed by broadcast | ||
|
|
@@ -2429,6 +2445,33 @@ def _wrap_function(sc, func, deserializer, serializer, profiler=None): | |
| sc.pythonVer, broadcast_vars, sc._javaAccumulator) | ||
|
|
||
|
|
||
| class RDDBarrier(object): | ||
|
|
||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| An RDDBarrier turns an RDD into a barrier RDD, which forces Spark to launch tasks of the stage | ||
|
||
| contains this RDD together. | ||
|
||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
|
|
||
| def __init__(self, rdd): | ||
| self.rdd = rdd | ||
|
|
||
| def mapPartitions(self, f, preservesPartitioning=False): | ||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| Return a new RDD by applying a function to each partition of this RDD. | ||
|
|
||
| .. versionadded:: 2.4.0 | ||
| """ | ||
| def func(s, iterator): | ||
| return f(iterator) | ||
| return PipelinedRDD(self.rdd, func, preservesPartitioning, isFromBarrier=True) | ||
|
|
||
|
|
||
| class PipelinedRDD(RDD): | ||
|
|
||
| """ | ||
|
|
@@ -2448,7 +2491,7 @@ class PipelinedRDD(RDD): | |
| 20 | ||
| """ | ||
|
|
||
| def __init__(self, prev, func, preservesPartitioning=False): | ||
| def __init__(self, prev, func, preservesPartitioning=False, isFromBarrier=False): | ||
| if not isinstance(prev, PipelinedRDD) or not prev._is_pipelinable(): | ||
| # This transformation is the first in its stage: | ||
| self.func = func | ||
|
|
@@ -2474,6 +2517,7 @@ def pipeline_func(split, iterator): | |
| self._jrdd_deserializer = self.ctx.serializer | ||
| self._bypass_serializer = False | ||
| self.partitioner = prev.partitioner if self.preservesPartitioning else None | ||
| self.is_barrier = prev._is_barrier() or isFromBarrier | ||
|
|
||
| def getNumPartitions(self): | ||
| return self._prev_jrdd.partitions().size() | ||
|
|
@@ -2493,7 +2537,7 @@ def _jrdd(self): | |
| wrapped_func = _wrap_function(self.ctx, self.func, self._prev_jrdd_deserializer, | ||
| self._jrdd_deserializer, profiler) | ||
| python_rdd = self.ctx._jvm.PythonRDD(self._prev_jrdd.rdd(), wrapped_func, | ||
| self.preservesPartitioning) | ||
| self.preservesPartitioning, self.is_barrier) | ||
| self._jrdd_val = python_rdd.asJavaRDD() | ||
|
|
||
| if profiler: | ||
|
|
@@ -2509,6 +2553,9 @@ def id(self): | |
| def _is_pipelinable(self): | ||
| return not (self.is_cached or self.is_checkpointed) | ||
|
|
||
| def _is_barrier(self): | ||
| return self.is_barrier | ||
|
|
||
|
|
||
| def _test(): | ||
| import doctest | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't know why we didn't mark the version so far here but we really should
.. versionadded:: 2.4.0here or