Skip to content

Preserve caller queues when applying a LitePull namespace - #11616

Open
MrKen20 wants to merge 3 commits into
apache:developfrom
MrKen20:codex/lite-pull-namespace-copy
Open

MrKen20 wants to merge 3 commits into
apache:developfrom
MrKen20:codex/lite-pull-namespace-copy

Conversation

@MrKen20

@MrKen20 MrKen20 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Found during source review of DefaultLitePullConsumer.

Brief Description

With a namespace configured, assign, pause, and resume changed the Topic of caller-owned MessageQueue objects. Topic participates in hashCode, so a queue already stored in a HashSet could become unfindable. Apply the namespace to queue copies before passing them to the consumer implementation.

The explicit offset APIs now use the same queue namespace as assignment. Copy and normalize the keys for commit(Map, boolean) and commitSync(Map, boolean), and the elements for commit(Set, boolean). This keeps the assigned queue, offset cache, and persistence keys aligned when the caller reuses the original queue. If a map contains both forms of the same queue, use the offset from its already namespaced key. Null and empty inputs follow the existing path.

How Did You Test This Change?

  • The assign, pause, and resume regression tests verify that the original queue is still findable and each operation uses the namespaced queue internally.
  • Tested all three explicit commit APIs with both persist values. The six cases that reuse the original queue after assign() fail on cf2946e and pass with the follow-up. The cached offset reaches 1 in each case. When persist is true, the mock records one broker-write call for demo%orders at offset 1. Controls cover already namespaced queues, no namespace, both forms of the same queue, and null and empty inputs.
  • Ran the targeted Maven suite on JDK 21. All 67 tests passed, including 30 explicit commit cases. Checkstyle and SpotBugs passed.
mvn -B -pl client -am \
  -Dtest=DefaultLitePullConsumerExplicitCommitTest,DefaultLitePullConsumerTest,DefaultLitePullConsumerImplTest,ClientConfigTest \
  -Dsurefire.failIfNoSpecifiedTests=false -Djacoco.skip=true test

Apply namespaces to fresh queue objects for assign, pause and resume. A Topic change alters the MessageQueue hash code and makes the original key unfindable in the caller collection.

Cover all three operations with a caller-owned HashSet and verify that the namespaced internal queue is assigned, paused or resumed.
@codecov-commenter

codecov-commenter commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 50.72%. Comparing base (74c2a8e) to head (171b1d0).
⚠️ Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
...ketmq/client/consumer/DefaultLitePullConsumer.java 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #11616      +/-   ##
=============================================
+ Coverage      50.47%   50.72%   +0.25%     
- Complexity     14711    14806      +95     
=============================================
  Files           1391     1391              
  Lines         103541   103587      +46     
  Branches       13575    13578       +3     
=============================================
+ Hits           52261    52545     +284     
+ Misses         45042    44788     -254     
- Partials        6238     6254      +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MrKen20 MrKen20 changed the title fix(client): preserve caller queues in LitePull namespace wrapping Preserve caller queues when applying a LitePull namespace Nov 25, 2026
@Override
public void assign(Collection<MessageQueue> messageQueues) {
defaultLitePullConsumerImpl.assign(queuesWithNamespace(messageQueues));
defaultLitePullConsumerImpl.assign(wrapQueuesWithNamespace(messageQueues));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a namespace configured, reusing the same MessageQueue for assign() and commit(Map, ...) now silently skips the offset update because the assigned queue is namespaced but the commit key is not. Could we apply the same namespace conversion to the explicit commit APIs without mutating the caller's queues?

@ShannonDing ShannonDing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defensive copy fixes caller-owned queue mutation, but breaks explicit offset commits when the original MessageQueue is reused after assign: the caller’s topic remains orders, while the internal queue uses demo%orders.

Identical regression tests against the parent and PR head confirm:

API persist Parent 74c2a8e Head cf2946e
commit(Map, boolean) true Pass Fail
commit(Set, boolean) true Pass Fail
commit(Set, boolean) false Pass Fail
commitSync(Map, boolean) true Pass Fail
commitSync(Map, boolean) false Pass Fail

All failing calls return normally. With an initial cached offset of 0 and a target offset of 1:

  • persist=false: the cached offset remains 0.
  • persist=true: persistAll removes the namespaced cache entry (READ_FROM_MEMORY = -1), without invoking the broker-write boundary.

The Set tests initialize a valid internal consume offset. No-namespace and explicitly namespaced-queue controls pass on both revisions for both persist values. Tests execute real assignment/offset-store logic with mocked lifecycle, scheduling and network boundaries; no live broker was used.

Please retain the defensive copy and normalize copied Map keys/Set elements in all three explicit commit APIs, preserving caller collections and existing null/empty-input behavior. Please include regression coverage for both persist values.

Use namespaced queue copies for explicit Map and Set offset commits.
Cover both persistence modes and preserve caller-owned inputs.
Install route and broker stubs before the client factory starts so the
scheduled route refresh cannot race with Mockito setup. Use a fresh
factory for each test and release the real transport before replacing it.

@ShannonDing ShannonDing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已验证最新提交修复了上一轮指出的显式提交 namespace 回归:commit(Map, boolean)、commit(Set, boolean) 和 commitSync(Map, boolean) 均能正确处理复用的调用者队列,且不修改调用者对象或集合。

本地相关测试 62/62 通过。保留新增测试、仅将主代码换回首版提交 cf2946e67 后,三个 API × 两种 persist 模式的 6 个复用队列用例全部失败,确认新增测试能够覆盖上一轮问题;恢复最新代码后全部通过。验证使用真实 assignment 和 offset cache,网络边界为 mock。

当前 CI 全部通过,未发现新的阻塞问题,建议合并。LGTM。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants