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

    https://github.com/apache/spark/pull/6607#discussion_r32878356
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/scheduler/ReceiverTracker.scala
 ---
    @@ -308,12 +336,25 @@ class ReceiverTracker(ssc: StreamingContext, 
skipReceiverLaunch: Boolean = false
             supervisor.start()
             supervisor.awaitTermination()
           }
    +
           // Run the dummy Spark job to ensure that all slaves have registered.
           // This avoids all the receivers to be scheduled on the same node.
           if (!ssc.sparkContext.isLocal) {
             ssc.sparkContext.makeRDD(1 to 50, 50).map(x => (x, 
1)).reduceByKey(_ + _, 20).collect()
           }
     
    +      // Get the list of executors and schedule receivers
    +      val executors = getExecutors(ssc)
    +      val locations = scheduleReceivers(receivers, executors)
    +      val tempRDD =
    +        if (locations(0) != null) {
    --- End diff --
    
    First of all, in Scala, we try to not rely on null rather use Option and 
None. Here a suggestion, which I think is a cleaner design with clean 
semantics. The makeRDD is designed to take a `sequence of (item, locations)`. 
If for a item, the location is a empty (not null, just empty seq), then that 
automatically means there is no preferred location. That's intuitive. 
    
    So the `scheduleReceiver` can designed as follows.
    1. `scheduleReceiver`  always returns a Array[ArrayBuffer[String]] where 
any of the buffers can be empty, but there are no nulls. 
    2. the logic in this location becomes 
    ```
    if (sparkContext is local) {
       // make RDD
    } else {
       // schedule receivers
       // make RDD with returned result
    }
    ```
    if there were no executors at that point of time, all the buffers will be 
empty, 
    which is perfectly okay to pass on to makeRDD. The code stays simple with 
only condition, and no matter what the executors are empty or not, it just 
works.
    
    How does this sound?



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