-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from gianm/rowkey-hashing
Rollup-aware partitioning by default for Maps, and a Partitioner interface for other types.
- Loading branch information
Showing
12 changed files
with
729 additions
and
139 deletions.
There are no files selected for viewing
53 changes: 19 additions & 34 deletions
53
core/src/main/scala/com/metamx/tranquility/beam/HashPartitionBeam.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 |
---|---|---|
@@ -1,44 +1,29 @@ | ||
/* | ||
* Tranquility. | ||
* Copyright 2013, 2014, 2015 Metamarkets Group, Inc. | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 | ||
* | ||
* Licensed 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 | ||
* | ||
* 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. | ||
* 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 com.metamx.tranquility.beam | ||
|
||
import com.google.common.hash.Hashing | ||
import com.metamx.common.scala.Logging | ||
import com.twitter.util.Future | ||
import com.metamx.tranquility.partition.HashCodePartitioner | ||
|
||
/** | ||
* Partitions events based on their hashCode modulo the number of delegate beams, and propagates the partitioned events | ||
* via the appropriate beam. | ||
*/ | ||
class HashPartitionBeam[A]( | ||
val delegates: IndexedSeq[Beam[A]] | ||
) extends Beam[A] with Logging | ||
beams: IndexedSeq[Beam[A]] | ||
) extends MergingPartitioningBeam[A](new HashCodePartitioner[A], beams) | ||
{ | ||
def propagate(events: Seq[A]) = { | ||
val futures = events.groupBy(event => Hashing.consistentHash(event.hashCode, delegates.size)) map { | ||
case (i, group) => | ||
delegates(i).propagate(group) | ||
} | ||
Future.collect(futures.toList).map(_.sum) | ||
} | ||
|
||
def close() = { | ||
Future.collect(delegates map (_.close())) map (_ => ()) | ||
} | ||
|
||
override def toString = "HashPartitionBeam(%s)" format delegates.mkString(", ") | ||
override def toString = s"HashPartitionBeam(${beams.mkString(", ")})" | ||
} |
48 changes: 48 additions & 0 deletions
48
core/src/main/scala/com/metamx/tranquility/beam/MergingPartitioningBeam.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,48 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 com.metamx.tranquility.beam | ||
|
||
import com.metamx.common.scala.Logging | ||
import com.metamx.tranquility.partition.Partitioner | ||
import com.twitter.util.Future | ||
|
||
/** | ||
* Partitions events based on the output of a Partitioner, and propagates the partitioned events via the | ||
* appropriate underlying beams. | ||
*/ | ||
class MergingPartitioningBeam[A]( | ||
val partitioner: Partitioner[A], | ||
val beams: IndexedSeq[Beam[A]] | ||
) extends Beam[A] with Logging | ||
{ | ||
def propagate(events: Seq[A]) = { | ||
val futures = events.groupBy(partitioner.partition(_, beams.size)) map { | ||
case (i, group) => | ||
beams(i).propagate(group) | ||
} | ||
Future.collect(futures.toList).map(_.sum) | ||
} | ||
|
||
def close() = { | ||
Future.collect(beams map (_.close())) map (_ => ()) | ||
} | ||
|
||
override def toString = s"MergingPartitioningBeam(${beams.mkString(", ")})" | ||
} |
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.