Repository navigation
Conversation
Use the existing TreeMap through NavigableMap.ceilingEntry and fall back to firstEntry when the lookup wraps around the ring. This avoids creating a tail-map view and searching again for the selected key. Preserve hashing and node placement. Cover signed hash boundaries, collisions and removal alongside existing routing tests. Fixes apache#11620 Assisted-By: OpenAI Codex
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #11621 +/- ##
=============================================
+ Coverage 50.86% 50.89% +0.02%
- Complexity 14881 14887 +6
=============================================
Files 1391 1391
Lines 103773 103774 +1
Branches 13614 13614
=============================================
+ Hits 52789 52811 +22
+ Misses 44724 44704 -20
+ Partials 6260 6259 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Distzzc
left a comment
There was a problem hiding this comment.
ceilingEntry preserves exact-match routing, and firstEntry preserves wrap-around. I compiled the base (e114b542) and this revision (45fde8c6) with javac --release 8 on JDK 17 and ran the same deterministic cases against both. Across 256 rounds covering node additions and removals, signed hash boundaries, virtual-node collisions, and empty rings, all 9,216 routing results and 1,024 replica counts matched. The five tests in ConsistentHashRouterTest also passed on the candidate revision.
@Distzzc |
Which Issue(s) This PR Fixes
Fixes #11620.
Brief Description
AllocateMessageQueueConsistentHash.allocateroutes each message queue throughConsistentHashRouter.routeNode. The current lookup creates a tail-map view, checks it, finds its first key and then searches the ring again for the corresponding value.Use
NavigableMap.ceilingEntryto obtain the successor and its value together, falling back tofirstEntryon wrap-around. The ring remains a TreeMap and lookup complexity remains O(log V); this removes repeated tree searches and temporary views. There is no new API, configuration, dependency or retained cache. Hashing, node placement and membership changes are unchanged. The separate shared-MD5 concurrency issue #11264 is outside this change.Add two tests for signed hash extremes and collision/removal behavior alongside the existing exact-match, successor, wrap-around and empty-ring tests.
How Did You Test This Change?
mvn -B -ntp -pl common -am test -Dtest=ConsistentHashRouterTest -Dsurefire.failIfNoSpecifiedTests=false: BUILD SUCCESS, 5 tests, 0 failures/errors/skips. Lifecycle Checkstyle reported 0 violations and SpotBugs passed.AllocateMessageQueueConsitentHashTestand its three client strategy/interface sources withjavac --release 8, using the built common module and its Maven test dependencies, and ran it via JUnitCore: 7 tests passed. This checks queue assignment after consumer additions/removals; it was not a full client-module Maven run.git diff --checkpassed. The standalone Maven/JMH reproduction project below packaged successfully and its executable jar completed a two-size smoke run. Full broker/integration suites were not run.Upstream CI on
45fde8c6e0055e8b2c95410323f308559348914dhas also completed successfully: all seven workflows (Maven builds/tests on Linux, Windows and macOS, Bazel, integration tests, coverage, CodeQL, license and spelling checks). Codecov reports that all modified coverable lines are covered. This is additional CI evidence; the local validation scope above is unchanged.Measurement
The benchmark calls the actual
routeNodeimplementation and includes default MD5 hashing and its per-call allocations. Ring construction and input generation are setup work. It cycles through 1,024 prebuilt queue keys, with 10 virtual nodes per physical node. This isolates the changed lookup; it does not establish an end-to-end rebalance or message-throughput gain.Windows, Intel i5-12500H, Oracle JDK 17.0.4.1, JMH 1.37, one fixed logical processor for both versions,
-Xms256m -Xmx256m, GC profiler, two forks, five one-second warmups and ten one-second measurements. Mean +/- JMH 99.9% confidence error:The 8-node time intervals overlap, so no speedup is claimed there. The 128-node mean is about 24% lower. Allocation savings depend on JVM optimization, including whether the returned entry escapes; the table reports measurements rather than a fixed object-size guarantee. A shorter initial run was noisy, so these default-MD5 comparisons were repeated with longer measurement after concurrent build work finished.
Baseline:
e114b542620c4169d016f25b63c2c377b2e279a7; candidate: this PR. Both were compiled for Java 8 and run on the same JDK 17.Reproduce with Maven and JMH (compiles the selected checkout's production sources)
Save
pom.xmlandRingLookupBenchmark.javabelow together in a separate benchmark directory. Run once withrocketmq.checkoutpointing to the baseline checkout, then again with it pointing to the candidate.clean packageprevents reuse of the other version's classes. Use separate JSON output files and the same JDK, JVM flags and CPU affinity for both runs. Replace the example paths for your system; the Maven and Java commands work on Windows and POSIX systems.mvn -B -ntp -f /path/to/benchmark/pom.xml -Drocketmq.checkout=/path/to/rocketmq-checkout clean package java -jar /path/to/benchmark/target/benchmarks.jar -p hash=MD5 -f 2 -wi 5 -i 10 -w 1s -r 1s -prof gc -jvmArgs "-Xms256m -Xmx256m" -rf json -rff /path/to/before.jsonpom.xml:RingLookupBenchmark.java:OpenAI Codex assisted with investigation, implementation, tests, benchmarks and this description. The commit includes an
Assisted-Bytrailer.