[SPARK-6891] Fix the bug that ExecutorAllocationManager will request negative number executors #5676
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.
In ExecutorAllocationManager, executor allocate schedule at a fix rate(100ms), it will call the method 'addOrCancelExecutorRequests' first, and then remove expired excutors.
Suppose at time T, no task is running or pending, and there a 5 executors runing, but all expired.
Suppose still no task is running or pending at T+1, the method 'targetNumExecutors' will return -5, and method 'addExecutors' will be called,
private def addExecutors(maxNumExecutorsNeeded: Int): Int = {
val currentTarget = targetNumExecutors
....
val actualMaxNumExecutors = math.min(maxNumExecutors, maxNumExecutorsNeeded)
val newTotalExecutors = math.min(currentTarget + numExecutorsToAdd, actualMaxNumExecutors)
val addRequestAcknowledged = testing || client.requestTotalExecutors(newTotalExecutors)
....
}
newTotalExecutors will be a negative number, when client.requestTotalExecutors(newTotalExecutors) called, it will throw an exception.
Let method 'targetNumExecutors' return a value not less than minNumExecutors, then the newTotalExecutors will never be negative.
And targetNumExecutors not less than minNumExecutors is also make sense.