This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/main by this push:
new 723b64a90f perf(amber): round-robin partitioner even distribution
(#9587)
723b64a90f is described below
commit 723b64a90f6a6423767465399003837cfcf165cb
Author: Matthew B. <[email protected]>
AuthorDate: Sat Nov 21 06:03:00 2026 +0000
perf(amber): round-robin partitioner even distribution (#9587)
### What changes were proposed in this PR?
- RoundRobinPartitioner.getBucketIndex emits the current index and then
advances, so the cycle starts at receiver 0, and returns an empty
iterator when there are no receivers instead of throwing
ArithmeticException.
### Any related issues, documentation, discussions?
Closes: #9584
### How was this PR tested?
- Run `sbt "WorkflowExecutionService/testOnly *PartitionersSpec"` under
JDK 17; the spec now expects the cycle to start at receiver 0 and adds a
case that an empty receiver set yields no bucket index.
- Could NOT run locally: the amber module needs its jOOQ DAO regenerated
from the DDL (a DB-backed build step) to compile, which this environment
cannot do, so the spec runs in CI's build / amber job.
### Was this PR authored or co-authored using generative AI tooling?
Co-authored with Claude Opus 4.8 in compliance with ASF
---
.../sendsemantics/partitioners/RoundRobinPartitioner.scala | 8 ++++++--
.../sendsemantics/partitioners/PartitionersSpec.scala | 12 +++++++++---
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/RoundRobinPartitioner.scala
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/RoundRobinPartitioner.scala
index 185f2e5e3a..63f247c438 100644
---
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/RoundRobinPartitioner.scala
+++
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/RoundRobinPartitioner.scala
@@ -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
diff --git
a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/PartitionersSpec.scala
b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/PartitionersSpec.scala
index 10d244b744..b343dbd81f 100644
---
a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/PartitionersSpec.scala
+++
b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/sendsemantics/partitioners/PartitionersSpec.scala
@@ -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 {