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

    https://github.com/apache/spark/pull/21428#discussion_r194911574
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/continuous/shuffle/RPCContinuousShuffleWriter.scala
 ---
    @@ -0,0 +1,54 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.streaming.continuous.shuffle
    +
    +import org.apache.spark.Partitioner
    +import org.apache.spark.rpc.RpcEndpointRef
    +import org.apache.spark.sql.catalyst.expressions.UnsafeRow
    +
    +/**
    + * A [[ContinuousShuffleWriter]] sending data to 
[[RPCContinuousShuffleReader]] instances.
    + *
    + * @param writerId          The partition ID of this writer.
    + * @param outputPartitioner The partitioner on the reader side of the 
shuffle.
    + * @param endpoints         The [[RPCContinuousShuffleReader]] endpoints 
to write to. Indexed by
    + *                          partition ID within outputPartitioner.
    + */
    +class RPCContinuousShuffleWriter(
    +    writerId: Int,
    +    outputPartitioner: Partitioner,
    +    endpoints: Array[RpcEndpointRef]) extends ContinuousShuffleWriter {
    +
    +  if (outputPartitioner.numPartitions != 1) {
    +    throw new IllegalArgumentException("multiple readers not yet 
supported")
    +  }
    +
    +  if (outputPartitioner.numPartitions != endpoints.length) {
    +    throw new IllegalArgumentException(s"partitioner size 
${outputPartitioner.numPartitions} did " +
    +      s"not match endpoint count ${endpoints.length}")
    +  }
    +
    +  def write(epoch: Iterator[UnsafeRow]): Unit = {
    +    while (epoch.hasNext) {
    +      val row = epoch.next()
    +      
endpoints(outputPartitioner.getPartition(row)).askSync[Unit](ReceiverRow(writerId,
 row))
    +    }
    +
    +    endpoints.foreach(_.askSync[Unit](ReceiverEpochMarker(writerId)))
    --- End diff --
    
    you can use `Future.sequence` to send messages in parallel, such as
    ```scala
        import scala.concurrent.Future
        import scala.concurrent.duration.Duration
        import org.apache.spark.util.ThreadUtils
    
        val futures = endpoints.map(_.ask[Unit](ReceiverEpochMarker(writerId)))
        implicit val ec = ThreadUtils.sameThread
        ThreadUtils.awaitResult(Future.sequence(futures), Duration.Inf)
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to