GitHub user jinxing64 opened a pull request:

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

    [SPARK-19438] Both reading and updating executorDataMap should be guarded 
by CoarseGrainedSchedulerBackend.this.synchronized when handle RegisterExecutor.

    ## What changes were proposed in this pull request?
    
    Currently when handle `RegisterExecutor` in 
`CoarseGrainedSchedulerBackend`, `executorDataMap` is guarded by 
`CoarseGrainedSchedulerBackend.this.synchronized` when updating, which can 
cause `numPendingExecutors` incorrect. 
    Code is like below:
    ```
            if (executorDataMap.contains(executorId)) {
              executorRef.send(RegisterExecutorFailed("Duplicate executor ID: " 
+ executorId))
              context.reply(true)
            } else {
              ...
              CoarseGrainedSchedulerBackend.this.synchronized {
                executorDataMap.put(executorId, data)
                if (currentExecutorIdCounter < executorId.toInt) {
                  currentExecutorIdCounter = executorId.toInt
                }
                if (numPendingExecutors > 0) {
                  numPendingExecutors -= 1
                  logDebug(s"Decremented number of pending executors 
($numPendingExecutors left)")
                }
              }
    ```
    Consider SPARK-19437 and a scenario like below:
    An executor sent `RegisterExecutor` twice by `askWithRetry`, and the 
interval between the two is quite small. Thus it might be possible that both of 
them will go to `else` branch, thus `numPendingExecutors` will be deducted 
twice and become incorrect. Currently, the `askWithRetry` of `RegisterExecutor` 
only exists in some unit tests, but it makes sense to make it stronger when 
handling `RegisterExecutor`.
    
    **TO FIX**
    Use CoarseGrainedSchedulerBackend.this.synchronized to guard 
executorDataMap when both reading and updating.
    
    ## How was this patch tested?
    The code logic is not changed, just manually tested. SPARK-19437 can also 
help verify this fix.


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

    $ git pull https://github.com/jinxing64/spark SPARK-19438

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

    https://github.com/apache/spark/pull/16780.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 #16780
    
----
commit 7bb3a438eff8c8ab9567a50ca59da2e179939e76
Author: jinxing <[email protected]>
Date:   2017-02-02T15:54:08Z

    [SPARK-19438] Both reading and updating executorDataMap should be guarded 
by CoarseGrainedSchedulerBackend.this.synchronized when handle RegisterExecutor.

----


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