Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-45753][CORE] Support spark.deploy.driverIdPattern #43615

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ private[deploy] class Master(
private val forwardMessageThread =
ThreadUtils.newDaemonSingleThreadScheduledExecutor("master-forward-message-thread")

private val driverIdPattern = conf.get(DRIVER_ID_PATTERN)

// For application IDs
private def createDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US)

Expand Down Expand Up @@ -1175,7 +1177,7 @@ private[deploy] class Master(
}

private def newDriverId(submitDate: Date): String = {
val appId = "driver-%s-%04d".format(createDateFormat.format(submitDate), nextDriverNumber)
val appId = driverIdPattern.format(createDateFormat.format(submitDate), nextDriverNumber)
yaooqinn marked this conversation as resolved.
Show resolved Hide resolved
nextDriverNumber += 1
appId
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/scala/org/apache/spark/internal/config/Deploy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.internal.config

import java.util.Date

private[spark] object Deploy {
val RECOVERY_MODE = ConfigBuilder("spark.deploy.recoveryMode")
.version("0.8.1")
Expand Down Expand Up @@ -82,4 +84,12 @@ private[spark] object Deploy {
.checkValue(_ > 0, "The maximum number of running drivers should be positive.")
.createWithDefault(Int.MaxValue)

val DRIVER_ID_PATTERN = ConfigBuilder("spark.deploy.driverIdPattern")
.doc("The pattern for driver ID generation based on Java `String.format` method. " +
"The default value is `driver-%s-%04d` which represents the existing driver id string " +
", e.g., `driver-20231031224459-0019`. Please be careful to generate unique IDs")
.version("4.0.0")
.stringConf
.checkValue(!_.format(new Date(), 0).exists(_.isWhitespace), "Whitespace is not allowed.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We execute String.format here in advance to prevent the failure in Master class.

.createWithDefault("driver-%s-%04d")
}
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ class MasterSuite extends SparkFunSuite
private val _waitingDrivers =
PrivateMethod[mutable.ArrayBuffer[DriverInfo]](Symbol("waitingDrivers"))
private val _state = PrivateMethod[RecoveryState.Value](Symbol("state"))
private val _newDriverId = PrivateMethod[String](Symbol("newDriverId"))

private val workerInfo = makeWorkerInfo(4096, 10)
private val workerInfos = Array(workerInfo, workerInfo, workerInfo)
Expand Down Expand Up @@ -1236,6 +1237,20 @@ class MasterSuite extends SparkFunSuite
private def getState(master: Master): RecoveryState.Value = {
master.invokePrivate(_state())
}

test("SPARK-45753: Support driver id pattern") {
val master = makeMaster(new SparkConf().set(DRIVER_ID_PATTERN, "my-driver-%2$05d"))
val submitDate = new Date()
assert(master.invokePrivate(_newDriverId(submitDate)) === "my-driver-00000")
assert(master.invokePrivate(_newDriverId(submitDate)) === "my-driver-00001")
}

test("SPARK-45753: Prevent invalid driver id patterns") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a test case for that.

val m = intercept[IllegalArgumentException] {
makeMaster(new SparkConf().set(DRIVER_ID_PATTERN, "my driver"))
}.getMessage
assert(m.contains("Whitespace is not allowed"))
}
}

private class FakeRecoveryModeFactory(conf: SparkConf, ser: serializer.Serializer)
Expand Down