liupc opened a new pull request #23693: [SPARK-26768][CORE]Remove useless code 
in BlockManager
URL: https://github.com/apache/spark/pull/23693
 
 
   ## What changes were proposed in this pull request?
   
   Recently, when I was reading some code of `BlockManager.getBlockData`, I 
found that there are useless code that would never reach. The related codes is 
as below:
   
   ```
   override def getBlockData(blockId: BlockId): ManagedBuffer = {
     if (blockId.isShuffle) {
       
shuffleManager.shuffleBlockResolver.getBlockData(blockId.asInstanceOf[ShuffleBlockId])
     } else {
       getLocalBytes(blockId) match {
         case Some(blockData) =>
           new BlockManagerManagedBuffer(blockInfoManager, blockId, blockData, 
true)
         case None =>
           // If this block manager receives a request for a block that it 
doesn't have then it's
           // likely that the master has outdated block statuses for this 
block. Therefore, we send
           // an RPC so that this block is marked as being unavailable from 
this block manager.
           reportBlockStatus(blockId, BlockStatus.empty)
           throw new BlockNotFoundException(blockId.toString)
       }
     }
   }
   ```
   ```
   def getLocalBytes(blockId: BlockId): Option[BlockData] = {
     logDebug(s"Getting local block $blockId as bytes")
     // As an optimization for map output fetches, if the block is for a 
shuffle, return it
     // without acquiring a lock; the disk store never deletes (recent) items 
so this should work
     if (blockId.isShuffle) {
       val shuffleBlockResolver = shuffleManager.shuffleBlockResolver
       // TODO: This should gracefully handle case where local block is not 
available. Currently
       // downstream code will throw an exception.
       val buf = new ChunkedByteBuffer(
         
shuffleBlockResolver.getBlockData(blockId.asInstanceOf[ShuffleBlockId]).nioByteBuffer())
       Some(new ByteBufferBlockData(buf, true))
     } else {
       blockInfoManager.lockForReading(blockId).map { info => 
doGetLocalBytes(blockId, info) }
     }
   }
   ```
   the `blockId.isShuffle` is checked twice, but however it seems that in the 
method calling hierarchy of `BlockManager.getLocalBytes`, the another callsite 
of the `BlockManager.getLocalBytes` is at `TorrentBroadcast.readBlocks` where 
the blockId can never be a `ShuffleBlockId`.
   
   
![image](https://user-images.githubusercontent.com/6747355/51963980-1fe55000-24a0-11e9-961a-e10fe67f8119.png)
   
   
   So I think we should remove these useless code for easy reading.
   
   ## How was this patch tested?
   
   NA
   
   Please review http://spark.apache.org/contributing.html before opening a 
pull request.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to