GitHub user zsxwing opened a pull request:

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

    Fix a race condition in StreamExecution.processAllAvailable

    ## What changes were proposed in this pull request?
    
    There is a race condition in `StreamExecution.processAllAvailable`. Here is 
an execution order to reproduce it.
    
    | Time        |Thread 1           | MicroBatchThread  |
    | ------------- |:-------------:| -----:|
    | 1 | |  `dataAvailable in constructNextBatch` returns false  |
    | 2 | addData(newData)      |   |
    | 3 | `noNewData = false` in  processAllAvailable |  |
    | 4 | | noNewData = true |
    | 5 | `noNewData` is true so just return | |
    
    The root cause is that `checking dataAvailable and change noNewData to 
true` is not atomic. This PR puts these two actions into `synchronized` to make 
sure they are atomic.
    
    In addition, this PR also has the following changes:
    
    - Make `committedOffsets` and `availableOffsets` volatile to make sure they 
can be seen in other threads.
    - Copy the reference of `availableOffsets` to a local variable so that 
`sourceStatuses` can use a snapshot of `availableOffsets`.
    
    ## How was this patch tested?
    
    Existing unit tests.
    


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

    $ git pull https://github.com/zsxwing/spark race-condition

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

    https://github.com/apache/spark/pull/12339.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 #12339
    
----
commit a49a46b51cc1c06a2a1d937f6c41c2f5fa2874ae
Author: Shixiong Zhu <[email protected]>
Date:   2016-04-12T20:57:29Z

    Fix a race condition in processAllAvailable

----


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