Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5722#discussion_r29648064
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1959,30 +1959,41 @@ private[spark] object Utils extends Logging {
        * Attempt to start a service on the given port, or fail after a number 
of attempts.
        * Each subsequent attempt uses 1 + the port used in the previous 
attempt (unless the port is 0).
        *
    -   * @param startPort The initial port to start the service on.
    +   * @param port The minimum and maximum port to start the service on, 
separated by colon.
    +   *             If just set one number, take it as the minimum.
        * @param startService Function to start service on a given port.
        *                     This is expected to throw java.net.BindException 
on port collision.
        * @param conf A SparkConf used to get the maximum number of retries 
when binding to a port.
        * @param serviceName Name of the service.
        */
       def startServiceOnPort[T](
    -      startPort: Int,
    +      port: String,
           startService: Int => (T, Int),
           conf: SparkConf,
           serviceName: String = ""): (T, Int) = {
    -
    -    require(startPort == 0 || (1024 <= startPort && startPort < 65536),
    -      "startPort should be between 1024 and 65535 (inclusive), or 0 for a 
random free port.")
    +    val maxRetries = portMaxRetries(conf)
    +    val ports = port.split(":", 2)
    +    val (minPort, maxPort) = if (ports.length == 2) {
    +      (ports(0).toInt, ports(1).toInt)
    +    } else {
    +      val _minPort = ports(0).toInt
    +      (_minPort, math.min(65535, _minPort + maxRetries))
    +    }
    +    require(minPort == 0 || (1024 <= minPort && minPort <= 65535),
    +      s"Minimum port ${minPort} should be between 1024 and 65535 
(inclusive)," +
    +        " or 0 for a random free port.")
    +    require((1024 <= maxPort && maxPort <= 65535),
    +      s"Maximum port ${maxPort} should be between 1024 and 65535 
(inclusive).")
    +    require(minPort <= maxPort, s"Minimum ${minPort} port should not be" +
    +      s" less than the maximum ${maxPort}.")
     
         val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'"
    -    val maxRetries = portMaxRetries(conf)
         for (offset <- 0 to maxRetries) {
    --- End diff --
    
    @vanzin since you may for example want a single port for one setting, a 
tight range of 3 for another, and a wide range of 100 for another. I could 
conceive that you want to choose from potentially 100 ports, but not retry 100 
times, or specify 1 port but actually allow some retries. But I do agree that 
`maxRetries` becomes largely redundant with this change.


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