Skip to content

Commit

Permalink
[SPARK-31456][CORE] Fix shutdown hook priority edge cases
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Fix application order for shutdown hooks for the priorities of Int.MaxValue, Int.MinValue

### Why are the changes needed?
The bug causes out-of-order execution of shutdown hooks if their priorities were Int.MinValue or Int.MaxValue

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Added a test covering the change.

Closes #28494 from oleg-smith/SPARK-31456_shutdown_hook_priority.

Authored-by: oleg <oleg@nexla.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
oleg authored and dongjoon-hyun committed May 11, 2020
1 parent 5a5af46 commit d7c3e9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ private [util] class SparkShutdownHookManager {
private class SparkShutdownHook(private val priority: Int, hook: () => Unit)
extends Comparable[SparkShutdownHook] {

override def compareTo(other: SparkShutdownHook): Int = {
other.priority - priority
}
override def compareTo(other: SparkShutdownHook): Int = other.priority.compareTo(priority)

def run(): Unit = hook()

Expand Down
6 changes: 5 additions & 1 deletion core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,14 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
manager.add(3, () => output += 3)
manager.add(2, () => output += 2)
manager.add(4, () => output += 4)
manager.add(Int.MinValue, () => output += Int.MinValue)
manager.add(Int.MinValue, () => output += Int.MinValue)
manager.add(Int.MaxValue, () => output += Int.MaxValue)
manager.add(Int.MaxValue, () => output += Int.MaxValue)
manager.remove(hook1)

manager.runAll()
assert(output.toList === List(4, 3, 2))
assert(output.toList === List(Int.MaxValue, Int.MaxValue, 4, 3, 2, Int.MinValue, Int.MinValue))
}

test("isInDirectory") {
Expand Down

0 comments on commit d7c3e9e

Please sign in to comment.