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

    https://github.com/apache/spark/pull/6672#discussion_r31860010
  
    --- Diff: 
core/src/main/scala/org/apache/spark/storage/BlockStatusListener.scala ---
    @@ -0,0 +1,125 @@
    +/*
    + * 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 scala.collection.mutable
    +
    +import org.apache.spark.scheduler._
    +
    +private[spark] case class BlockUIData(
    +    blockId: BlockId,
    +    storageLevel: StorageLevel,
    +    memSize: Long,
    +    diskSize: Long,
    +    externalBlockStoreSize: Long,
    +    locations: Set[String])
    +
    +private[spark] class BlockStatusListener extends SparkListener {
    +
    +  private val blockManagers = new mutable.HashMap[BlockManagerId, 
mutable.HashSet[BlockId]]
    +  private val blocks = new mutable.HashMap[BlockId, BlockUIData]
    +
    +  override def onBlockUpdated(blockUpdated: SparkListenerBlockUpdated): 
Unit = {
    +    val blockManagerId = blockUpdated.updateBlockInfo.blockManagerId
    +    val blockId = blockUpdated.updateBlockInfo.blockId
    +    val storageLevel = blockUpdated.updateBlockInfo.storageLevel
    +    val memSize = blockUpdated.updateBlockInfo.memSize
    +    val diskSize = blockUpdated.updateBlockInfo.diskSize
    +    val externalBlockStoreSize = 
blockUpdated.updateBlockInfo.externalBlockStoreSize
    +
    +    synchronized {
    +      // Drop the update info if the block manager is not registered
    +      blockManagers.get(blockManagerId) foreach { blocksInBlockManager =>
    +        if (storageLevel.isValid) {
    +          blocksInBlockManager.add(blockId)
    +          val location = s"${blockManagerId.hostPort} / 
${blockManagerId.executorId}"
    +          val newLocations =
    +            blocks.get(blockId).map(_.locations).getOrElse(Set.empty) + 
location
    +          val newStorageLevel = StorageLevel(
    +            useDisk = diskSize > 0,
    +            useMemory = memSize > 0,
    +            useOffHeap = externalBlockStoreSize > 0,
    +            deserialized = storageLevel.deserialized,
    +            replication = newLocations.size
    +          )
    +          blocks.put(blockId,
    +            BlockUIData(
    +              blockId,
    +              newStorageLevel,
    +              memSize,
    +              diskSize,
    +              externalBlockStoreSize,
    +              newLocations))
    +        } else {
    +          // If isValid is not true, it means we should drop the block.
    +          blocksInBlockManager -= blockId
    +          removeBlockFromBlockManager(blockId, blockManagerId)
    --- End diff --
    
    > How will it look if one of the 2 copies of the blocks fall off from the 
executor?
    
    `2x` will become `1x`. When one of 2 copies is removed, an update info with 
`StorageLevel.None` will be sent. Then `removeBlockFromBlockManager` will 
create a new `StorageLevel` with `replication = 1` for this block.


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