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

    https://github.com/apache/spark/pull/11157#discussion_r55104611
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1940,57 +1940,131 @@ 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 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.
    -   * @return (service: T, port: Int)
    -   */
    +    * 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).
    +    * It takes into consideration port restrictions through the env var 
AVAILABLE_PORTS
    +    *
    +    * @param startPort The initial port to start the service on.
    +    * @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.
    +    * @return (service: T, port: Int)
    +    */
       def startServiceOnPort[T](
    -      startPort: Int,
    -      startService: Int => (T, Int),
    -      conf: SparkConf,
    -      serviceName: String = ""): (T, Int) = {
    +                             startPort: Int,
    +                             startService: Int => (T, Int),
    +                             conf: SparkConf,
    +                             serviceName: String = ""): (T, Int) = {
    +
    +    val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'"
    +
    +    // define some helpers, they all share common data, maybe a service 
abstract class
    +    // for all services could be a good fit here.
    +
    +    def portRangeToList(ranges: String): List[(Long, Long)] = {
    +      ranges.split(" ").map { r => val ret = r.substring(1, r.length - 
1).split(",")
    +        (ret(0).toLong, ret(1).toLong)
    +      }.toList
    +    }
    +
    +    def startOnce(tryPort: Int): (Option[T], Int) = {
    +      val serviceString = if (serviceName.isEmpty) "" else s" 
'$serviceName'"
    +      try {
    +        val (service, port) = startService(tryPort)
    +        logInfo(s"Successfully started service$serviceString on port 
$port.")
    +        (Some(service), port)
    +      } catch {
    +        case e: Exception if isBindCollision(e) =>
    +          logWarning(s"Service$serviceString could not bind on port 
$tryPort. ")
    +          (None, -1)
    +      }
    +    }
    +
    +    def retryPort(next: Int => Int, maxRetries: Int): (T, Int) = {
    +
    --- End diff --
    
    Extra space


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