GitHub user cloud-fan opened a pull request: https://github.com/apache/spark/pull/18955
[SPARK-21743][SQL] top-most limit should not cause memory leak ## What changes were proposed in this pull request? For top-most limit, we will use a special operator to execute it: `CollectLimitExec`. `CollectLimitExec` will retrieve `n`(which is the limit) rows from each partition of the child plan output, see https://github.com/apache/spark/blob/v2.2.0/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala#L311. It's very likely that we don't exhaust the child plan output. This is fine when whole-stage-codegen is off, as child plan will release the resource via task completion listener. However, when whole-stage codegen is on, the resource can only be released if all output is consumed. To fix this memory leak, one simple approach is, when `CollectLimitExec` retrieve `n` rows from child plan output, child plan output should only have `n` rows, then the output is exhausted and resource is released. This can be done by wrapping child plan with `LocalLimit` ## How was this patch tested? a regression test You can merge this pull request into a Git repository by running: $ git pull https://github.com/cloud-fan/spark leak Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/18955.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #18955 ---- commit 67ac3aa37ad7762f3d95c7e3f4900ba47124583b Author: Wenchen Fan <wenc...@databricks.com> Date: 2017-08-16T04:27:03Z top-most limit should not cause memory leak ---- --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org