Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ case class RoundRobinPartitioner(partitioning: RoundRobinPartitioning) extends P
private val receivers = partitioning.channels.map(_.toWorkerId).distinct

override def getBucketIndex(tuple: Tuple): Iterator[Int] = {
roundRobinIndex = (roundRobinIndex + 1) % receivers.length
Iterator(roundRobinIndex)
if (receivers.isEmpty) Iterator.empty
else {
val index = roundRobinIndex
roundRobinIndex = (roundRobinIndex + 1) % receivers.length
Iterator(index)
}
}

override def allReceivers: Seq[ActorVirtualIdentity] = receivers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ class PartitionersSpec extends AnyFlatSpec {
val partitioner = RoundRobinPartitioner(partitioning)

val indices = (1 to 7).map(_ => partitioner.getBucketIndex(intTuple(0)).next()).toList
// Implementation increments first, then emits. Starting from 0, the first
// emitted index is therefore 1, then 2, then 0, repeating.
assert(indices == List(1, 2, 0, 1, 2, 0, 1))
// Emits the current index then advances, so the cycle starts at receiver 0.
assert(indices == List(0, 1, 2, 0, 1, 2, 0))
}

it should "emit nothing when there are no receivers" in {
val partitioner =
RoundRobinPartitioner(RoundRobinPartitioning(batchSize = 100, channels = Seq()))
assert(partitioner.getBucketIndex(intTuple(0)).toList == List())
assert(partitioner.allReceivers == Seq())
}

"RoundRobinPartitioner.allReceivers" should "preserve channel order while deduplicating" in {
Expand Down
Loading