Skip to content

[ISSUE #151] fix(remoting): make split assignment and partition discovery survive direct-connect route races - #152

Merged
lizhimins merged 1 commit into
apache:mainfrom
lizhimins:direct-connect-stability
Oct 29, 2026
Merged

lizhimins merged 1 commit into
apache:mainfrom
lizhimins:direct-connect-stability

Conversation

@lizhimins

Copy link
Copy Markdown
Member

What is the purpose of the change

Fixes the two silent defects reported in #151, both observed during an acceptance run against an open-source RocketMQ 5.5.1 cluster with clients connecting to NameServers directly (no proxy):

  1. Starting-offset race (D24) — RebalancePullImpl.computePullFromWhereWithException in rocketmq-client 5.5.1 is hard-coded to return 0, so assign() lets the client-internal rebalance thread dispatch a first pull from offset 0 while handleSplitsChanges is still seeking to the configured starting offset. With latest / timestamp / explicit-offset modes, a random subset of queues (~half per run, subset varies) replays history. No Flink-side lock scope can win this race — the pull happens on client-internal threads, and presetting the offset store does not help because computePullFromWhere never reads it (both alternatives were tried and verified ineffective).
    Fix: enforce the starting offset deterministically at the fetch() outlet — records with queueOffset < max(startingOffset, 0) are dropped using the split's recorded starting offset. seek() remains as a traffic-reduction optimization.

  2. Route-fetch failure misread as an empty route (D26) — during a NameServer outage every fetchMessageQueues call fails and the periodic discovery flattens the failures into an empty queue set; diffed against the allocated set, that revokes every split, and the queues returning after recovery go through initializeSourceSplits again (observed: job restart + 150 replayed records). The client already treats the NameServer as a weak dependency (topicRouteTable keeps the last route on refresh failure), so the connector needs no route cache of its own — only the failure semantics fixed here.
    Fix: failed topics are excluded from the round (they cannot contribute decreases); a round where every topic failed is skipped; an empty result while queues are allocated keeps the current assignment. Genuine deletions surface again on later rounds.

Also documents that EXACTLY_ONCE is not supported on proxy-fronted endpoints (transaction state lives in per-proxy-process memory and commits can be silently dropped), while direct deployments support it.

Brief change log

  • RocketMQSplitReader.fetch(): drop records below the split's starting offset at the outlet.
  • RocketMQSourceEnumerator: per-topic failure isolation in requestServiceDiscovery, null round on total failure, empty-set guard in handleSourceQueueChange.
  • New tests: RocketMQSourceEnumeratorDiscoveryToleranceTest (5 cases, including documenting the empty-set diff hazard); existing split-reader tests cover the offset filter.
  • docs/remoting-connector.md: EXACTLY_ONCE support matrix per endpoint type.

Verifications

  • Module build green: 143 tests, 0 failures (spotless applied).
  • Cluster A/B for the outage scenario (2 brokers × 2 queues, ns ×1 stopped 60s):
    • before: job RESTARTING, sink 200 → 350 (+150 replayed);
    • after: job RUNNING in 6/6 samples during the outage, guard log every discovery round, zero decreases, sink grew exactly by the second wave (202 = 101 + 101, 0 replayed), producer recovered within 150s of the NameServer returning.
  • Cluster three-tier re-verification for the starting-offset fix: latest / timestamp / specific=10 all show 0 out-of-range records and sink physical offsets exactly 101 per tier.

Closes #151

… discovery survive direct-connect route races

Two silent defects surface when the client talks to NameServers directly
(open-source deployment, no proxy):

1. Starting offsets are ignored for a random subset of queues.
   RebalancePullImpl.computePullFromWhereWithException is hard-coded to 0,
   so assign() lets the client-internal rebalance thread dispatch a first
   pull from offset 0 while handleSplitsChanges is still seeking to the
   configured starting offset. No Flink-side lock scope can win that race.
   Enforce the starting offset deterministically at the fetch() outlet
   instead: records below max(startingOffset, 0) are dropped there, and
   seek() remains as a traffic optimization.

2. A NameServer outage restarts the job and rewinds offsets. The periodic
   partition discovery flattened per-topic route fetch failures into an
   empty queue set; diffed against the allocated set that revokes every
   split, and the queues returning after recovery are re-initialized from
   scratch (observed: +150 replayed records). A failed fetch says nothing
   about the actual route: exclude failed topics from the round, skip the
   round when every topic failed, and keep the current assignment when an
   empty result arrives while queues are allocated. Genuine deletions
   surface again on later rounds.

Also document that EXACTLY_ONCE is not supported on proxy-fronted
endpoints (transaction state lives in per-proxy-process memory and is
silently dropped), while direct deployments do support it.

Cluster verification of the outage scenario after the fix: job RUNNING
throughout the 60s NameServer stop, zero split decreases, zero replay
(sink grew exactly by the second wave), producer recovered within 150s
of the NameServer coming back.
@lizhimins
lizhimins force-pushed the direct-connect-stability branch from b34b979 to 3d8b17c Compare October 29, 2026 05:56
@lizhimins
lizhimins merged commit 80a98ac into apache:main Oct 29, 2026
2 checks passed
lizhimins added a commit that referenced this pull request Nov 6, 2026
…me re-added queues from checkpoint offsets (#162)

Two gaps remained in periodic partition discovery after #152:

1. A partial route-fetch failure across multiple topics still revoked the
   failed topic's queues: requestServiceDiscovery only skipped the round
   when every topic failed, and the plain set difference against the
   allocated set reported the failed topic's queues as decreased. The
   discovery callable now returns the failed topics together with the
   discovered queues, and the coordinator excludes their queues from the
   decrease evaluation. A failed fetch is no evidence of absence.

2. A revoked queue that reappeared restarted from the configured starting
   selector: initializeSourceSplits discarded the checkedOffsets entry on
   decrease, so the re-added queue was re-resolved (with EARLIEST, replaying
   the whole queue). The last checkpointed offset is now retained for
   revoked queues and preferred when the queue reappears, the same rule the
   migration path already applies to surviving queues. The selector still
   applies to genuinely new queues, and after coordinator failover where
   the retained offsets are lost.

RocketMQSourceEnumeratorDiscoveryToleranceTest now covers the per-topic
exclusion on partial failures at both the handler and the diff level; the
new RocketMQSourceEnumeratorRevokedOffsetResumeTest covers checkpoint
resume, new-queue selector fallback, mixed rounds, and the NO_STOPPING_OFFSET
guard.
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.

remoting source: starting-offset race on split assignment and route-fetch failures misread as empty routes

1 participant