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

    https://github.com/apache/spark/pull/8257#discussion_r37271032
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/receiver/BlockGenerator.scala
 ---
    @@ -227,16 +227,21 @@ private[streaming] class BlockGenerator(
       def isStopped(): Boolean = state == StoppedAll
     
       /** Change the buffer to which single records are added to. */
    -  private def updateCurrentBuffer(time: Long): Unit = synchronized {
    +  private def updateCurrentBuffer(time: Long): Unit = {
         try {
    -      val newBlockBuffer = currentBuffer
    -      currentBuffer = new ArrayBuffer[Any]
    -      if (newBlockBuffer.size > 0) {
    -        val blockId = StreamBlockId(receiverId, time - blockIntervalMs)
    -        val newBlock = new Block(blockId, newBlockBuffer)
    -        listener.onGenerateBlock(blockId)
    +      var newBlock: Block = null
    +      synchronized {
    +        if (currentBuffer.nonEmpty) {
    +          val newBlockBuffer = currentBuffer
    +          currentBuffer = new ArrayBuffer[Any]
    +          val blockId = StreamBlockId(receiverId, time - blockIntervalMs)
    +          listener.onGenerateBlock(blockId)
    +          newBlock = new Block(blockId, newBlockBuffer)
    +        }
    +      }
    +
    +      if (newBlock != null) {
    --- End diff --
    
    Sorry that I misunderstood the meaning of `state`. This code is right.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to