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

    https://github.com/apache/spark/pull/2240#discussion_r17031089
  
    --- Diff: 
core/src/main/scala/org/apache/spark/storage/ShuffleBlockFetcherIterator.scala 
---
    @@ -0,0 +1,267 @@
    +/*
    + * 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.storage
    +
    +import java.util.concurrent.LinkedBlockingQueue
    +
    +import scala.collection.mutable.ArrayBuffer
    +import scala.collection.mutable.HashSet
    +import scala.collection.mutable.Queue
    +
    +import org.apache.spark.{TaskContext, Logging, SparkException}
    +import org.apache.spark.network.{ManagedBuffer, BlockFetchingListener, 
BlockTransferService}
    +import org.apache.spark.serializer.Serializer
    +import org.apache.spark.util.Utils
    +
    +
    +/**
    + * An iterator that fetches multiple blocks. For local blocks, it fetches 
from the local block
    + * manager. For remote blocks, it fetches them using the provided 
BlockTransferService.
    + *
    + * This creates an iterator of (BlockID, values) tuples so the caller can 
handle blocks in a
    + * pipelined fashion as they are received.
    + *
    + * The implementation throttles the remote fetches to they don't exceed 
maxBytesInFlight to avoid
    + * using too much memory.
    + *
    + * @param context
    + * @param blockManager
    + * @param blocksByAddress
    + * @param serializer
    + * @param maxBytesInFlight max size (in bytes) of remote blocks to fetch 
at any given point.
    + */
    +private[spark]
    +final class ShuffleBlockFetcherIterator(
    +    context: TaskContext,
    +    blockTransferService: BlockTransferService,
    +    blockManager: BlockManager,
    +    blocksByAddress: Seq[(BlockManagerId, Seq[(BlockId, Long)])],
    +    serializer: Serializer,
    +    maxBytesInFlight: Long)
    +  extends Iterator[(BlockId, Option[Iterator[Any]])] with Logging {
    +
    +  import ShuffleBlockFetcherIterator._
    +
    +  /**
    +   * Total number of blocks to fetch. This can be smaller than the total 
number of blocks
    +   * in [[blocksByAddress]] because we filter out zero-sized blocks in 
[[initialize]].
    +   *
    +   * This should equal localBlocks.size + remoteBlocks.size.
    +   */
    +  private[this] var numBlocksToFetch = 0
    +
    +  /**
    +   * The number of blocks proccessed by the caller. The iterator is 
exhausted when
    +   * [[numBlocksProcessed]] == [[numBlocksToFetch]].
    +   */
    +  private[this] var numBlocksProcessed = 0
    +
    +  private[this] val startTime = System.currentTimeMillis
    +
    +  /** Local blocks to fetch, excluding zero-sized blocks. */
    +  private[this] val localBlocks = new ArrayBuffer[BlockId]()
    +
    +  /** Remote blocks to fetch, excluding zero-sized blocks. */
    +  private[this] val remoteBlocks = new HashSet[BlockId]()
    +
    +  /**
    +   * A queue to hold our results. This turns the asynchronous model 
provided by
    +   * [[BlockTransferService]] into a synchronous model (iterator).
    +   */
    +  private[this] val results = new LinkedBlockingQueue[FetchResult]
    +
    +  // Queue of fetch requests to issue; we'll pull requests off this 
gradually to make sure that
    +  // the number of bytes in flight is limited to maxBytesInFlight
    +  private[this] val fetchRequests = new Queue[FetchRequest]
    +
    +  // Current bytes in flight from our requests
    +  private[this] var bytesInFlight = 0L
    +
    +  private[this] val shuffleMetrics = 
context.taskMetrics.createShuffleReadMetricsForDependency()
    +
    +  initialize()
    +
    +  private[this] def sendRequest(req: FetchRequest) {
    --- End diff --
    
    note to reviewers: this is the function that changed.


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