This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
Refactor Storm
platform to introduce Edge
s
#728
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
summingbird-storm/src/main/scala/com/twitter/summingbird/storm/EdgeGrouping.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.twitter.summingbird.storm | ||
|
||
import org.apache.storm.topology.BoltDeclarer | ||
import org.apache.storm.tuple.{ Fields => StormFields } | ||
|
||
/** | ||
* This trait is used to represent different grouping strategies in `Storm`. | ||
*/ | ||
sealed trait EdgeGrouping { | ||
/** | ||
* How to apply this `EdgeGrouping` to edge between `parentName` node and bolt declared by `declarer`. | ||
*/ | ||
def apply(declarer: BoltDeclarer, parentName: String): Unit | ||
} | ||
|
||
object EdgeGrouping { | ||
case object Shuffle extends EdgeGrouping { | ||
override def apply(declarer: BoltDeclarer, parentName: String): Unit = | ||
declarer.shuffleGrouping(parentName) | ||
} | ||
case object LocalOrShuffle extends EdgeGrouping { | ||
override def apply(declarer: BoltDeclarer, parentName: String): Unit = | ||
declarer.localOrShuffleGrouping(parentName) | ||
} | ||
case class Fields(fields: StormFields) extends EdgeGrouping { | ||
override def apply(declarer: BoltDeclarer, parentName: String): Unit = | ||
declarer.fieldsGrouping(parentName, fields) | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
summingbird-storm/src/main/scala/com/twitter/summingbird/storm/EdgeType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.twitter.summingbird.storm | ||
|
||
import com.twitter.bijection.{ Injection, Inversion } | ||
import org.apache.storm.tuple.Fields | ||
import java.util.{ ArrayList => JAList, List => JList } | ||
|
||
import com.twitter.summingbird.online.executor.KeyValueShards | ||
|
||
import scala.collection.{ Map => CMap } | ||
import scala.util.Try | ||
|
||
/** | ||
* This trait represents an edge in Storm topology DAG between two nodes. | ||
* @tparam T represents type of tuples sent over this `Edge`. | ||
*/ | ||
sealed trait EdgeType[T] { | ||
/** | ||
* Storm's `Fields` are going to be sent over this `Edge`. | ||
*/ | ||
val fields: Fields | ||
|
||
/** | ||
* Injection from values (which are going to be sent) to Storm's values. | ||
* Each element in returned array corresponds to element in `Fields` at the same index. | ||
*/ | ||
val injection: Injection[T, JList[AnyRef]] | ||
|
||
/** | ||
* Grouping for this `Edge`. | ||
*/ | ||
val grouping: EdgeGrouping | ||
} | ||
|
||
object EdgeType { | ||
/** | ||
* Simplest possible type of `Edge`, without any assumptions about content inside. | ||
*/ | ||
case class Item[T] private[storm] (edgeGrouping: EdgeGrouping) extends EdgeType[T] { | ||
override val fields: Fields = new Fields("value") | ||
override val injection: Injection[T, JList[AnyRef]] = EdgeTypeInjections.forItem | ||
override val grouping: EdgeGrouping = edgeGrouping | ||
} | ||
|
||
/** | ||
* This `Edge` type used for aggregated key value pairs emitted by partial aggregation. | ||
* @param shards is a number which was used for partial aggregation. | ||
*/ | ||
case class AggregatedKeyValues[K, V](shards: KeyValueShards) extends EdgeType[(Int, CMap[K, V])] { | ||
override val fields: Fields = new Fields("aggKey", "aggValue") | ||
override val injection: Injection[(Int, CMap[K, V]), JList[AnyRef]] = EdgeTypeInjections.forKeyValue | ||
override val grouping: EdgeGrouping = EdgeGrouping.Fields(new Fields("aggKey")) | ||
} | ||
|
||
def itemWithShuffleGrouping[T]: Item[T] = Item[T](EdgeGrouping.Shuffle) | ||
def itemWithLocalOrShuffleGrouping[T]: Item[T] = Item[T](EdgeGrouping.LocalOrShuffle) | ||
} | ||
|
||
private object EdgeTypeInjections { | ||
def forItem[T]: Injection[T, JList[AnyRef]] = new Injection[T, JList[AnyRef]] { | ||
override def apply(tuple: T): JAList[AnyRef] = { | ||
val list = new JAList[AnyRef](1) | ||
list.add(tuple.asInstanceOf[AnyRef]) | ||
list | ||
} | ||
|
||
override def invert(valueIn: JList[AnyRef]): Try[T] = Inversion.attempt(valueIn) { input => | ||
input.get(0).asInstanceOf[T] | ||
} | ||
} | ||
|
||
def forKeyValue[K, V]: Injection[(K, V), JList[AnyRef]] = new Injection[(K, V), JList[AnyRef]] { | ||
override def apply(tuple: (K, V)): JAList[AnyRef] = { | ||
val (key, value) = tuple | ||
val list = new JAList[AnyRef](2) | ||
list.add(key.asInstanceOf[AnyRef]) | ||
list.add(value.asInstanceOf[AnyRef]) | ||
list | ||
} | ||
|
||
override def invert(valueIn: JList[AnyRef]): Try[(K, V)] = Inversion.attempt(valueIn) { input => | ||
val key = input.get(0).asInstanceOf[K] | ||
val value = input.get(1).asInstanceOf[V] | ||
(key, value) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add: "Used for rate limiting."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done