Github user harishreedharan commented on a diff in the pull request:
https://github.com/apache/spark/pull/1195#discussion_r14309253
--- Diff:
streaming/src/main/scala/org/apache/spark/streaming/receiver/BlockGenerator.scala
---
@@ -134,9 +168,26 @@ private[streaming] class BlockGenerator(
logError(message, t)
listener.onError(message, t)
}
-
+
private def pushBlock(block: Block) {
listener.onPushBlock(block.id, block.buffer)
+
+ var callbackBufferOpt: Option[ArrayBuffer[Callback]] = None
+ // Remove the buffer from the callbacks map. This must be synchronized
to ensure no one else
+ // is editing the buffer or the map at that time.
+ synchronized {
+ callbackBufferOpt = Option(callbacks.remove(block.id))
+ }
+
+ // Call the callbacks
+ callbackBufferOpt match {
+ case Some(callbackBuffer) =>
+ callbackBuffer.map(callback => {
--- End diff --
Pardon my rusty scala, I understand I can get rid of the match-case here (I
initially had map call for that too, but I just felt there were too many map
calls ;)), but how is foreach "cheaper" than map in this case? Wouldn't both
cost pretty much the same?
---
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.
---