GitHub user liancheng opened a pull request:

    https://github.com/apache/spark/pull/15976

    [SPARK-18403][SQL] Fix unsafe data false sharing issue in 
ObjectHashAggregateExec

    [SPARK-18403][SQL] Fix unsafe data false sharing issue in 
ObjectHashAggregateExec
    
    ## What changes were proposed in this pull request?
    
    This PR fixes a random OOM issue occurred while running 
`ObjectHashAggregateSuite`.
    
    This issue can be steadily reproduced under the following conditions:
    
    1. The aggregation must be evaluated using `ObjectHashAggregateExec`;
    2. There must be an input column whose data type involves `ArrayType` (an 
input column of `MapType` may even cause SIGSEGV);
    3. Sort-based aggregation fallback must be triggered during evaluation.
    
    The root cause is that while falling back to sort-based aggregation, we 
must sort and feed already evaluated partial aggregation buffers living in the 
hash map to the sort-based aggregator using an external sorter. However, the 
underlying mutable byte buffer of `UnsafeRow`s produced by the iterator of the 
external sorter is reused and may get overwritten when the iterator steps 
forward. After the last entry is consumed, the byte buffer points to a block of 
uninitialized memory filled by `5a`. Therefore, while reading an 
`UnsafeArrayData` out of the `UnsafeRow`, `5a5a5a5a` is treated as array size 
and triggers a memory allocation for a ridiculously large array and immediately 
blows up the JVM with an OOM.
    
    To fix this issue, we only need to add `.copy()` accordingly.
    
    ## How was this patch tested?
    
    New regression test case added in `ObjectHashAggregateSuite`.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/liancheng/spark investigate-oom

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/15976.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 #15976
    
----
commit 4b88eed0f5f2cb34d217d833dbe085f9d0277a94
Author: Cheng Lian <[email protected]>
Date:   2016-11-21T23:41:23Z

    Fix unsafe data false sharing issue in ObjectHashAggregateExec

----


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