unboxlumen opened a new issue, #11663:
URL: https://github.com/apache/rocketmq/issues/11663

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions) of this repository 
and believe that this is not a duplicate.
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   ### Runtime platform environment
   
   Linux, 3-node DLedger group (`enableDLegerCommitLog=true`), 
`brokerRole=SYNC_MASTER`, `flushDiskType=SYNC_FLUSH`, DefaultCluster. No 
controller mode.
   
   ### RocketMQ version
   
   5.3.0
   
   ### JDK Version
   
   JDK 8
   
   ### Describe the Bug
   
   After a DLedger leader switch, a follower's ConsumeQueue stayed frozen at an 
old position while the newly elected leader was assigning `queueOffset` from a 
lower local ConsumeQueue position. The same `queueOffset` therefore mapped to 
different messages on different brokers. On the next switch back, consumer 
offsets synced from the previous leader fell inside the frozen region, and 
messages from the previous day were re-delivered. An application-side dedup 
count showed at least 13,892 message IDs processed on both days in a 4-minute 
window.
   
   The suspected root cause is that DLedger runtime truncation 
(`EntryHandler.handleDoTruncate`) truncates the DLedger data file only and does 
not roll back the RocketMQ ConsumeQueue through 
`DefaultMessageStore.truncateDirtyFiles` / `truncateDirtyLogicFiles`. A 
follower that is ahead of the commitlog's queue offsets then silently skips 
every new message via the `Build consume queue repeatedly` branch 
(`expectLogicOffset < currentLogicOffset` -> `return true`), keeping stale 
entries forever.
   
   ### Observed sequence (sanitized)
   
   Nodes: `node0`, `node1`, `node2`; topic `TopicA`, group `groupA`, queue 2.
   
   1. **2026-11-27 14:16:17, node0 (follower)** — possible precursor:
   
   ```text
   WARN ReputMessageService - The reputFromOffset=623341198984 is smaller than 
minPyOffset=627065225216,
   this usually indicate that the dispatch behind too much and the commitlog 
has expired.
   ```
   
   The jump is 3,724,026,232 bytes. At 14:16:18 the CQ min offsets were 
recomputed.
   
   2. **2026-11-28 13:51:42, node0** — first ConsumeQueue divergence, and it is 
global (multiple topics in the same second):
   
   ```text
   WARN ReputMessageService - [BUG]logic queue order maybe wrong,
     expectLogicOffset: 246105740 currentLogicOffset: 243854520
     Topic: TopicA QID: 2 Diff: 2251220
   ```
   
   `2,251,220 / 20 = 112,561` slots. The same `Diff: +2251220` persisted until 
22:21:40.
   
   3. **2026-11-28 22:21:47, first switch (node2 -> node0)**:
   
   ```text
   node2: INFO DLedgerFlushDataService - Flush data cost=6349 ms
   node0: INFO StateMaintainer - [n0][HeartBeatTimeOut] 
lastLeaderHeartBeatTime: 2026-11-28 22:21:40.718
   node0: INFO StateMaintainer - [n0] [VOTE_RESULT] has been elected to be the 
leader in term 85
   node2: INFO EntryHandler-n2 - [HandleDoTruncate] truncateIndex=886898844 
pos=639520164730
   ```
   
   4. **2026-11-28 22:22:16, node1/node2 (followers)**:
   
   ```text
   WARN ReputMessageService - Build consume queue repeatedly,
     expectLogicOffset: 244616360 currentLogicOffset: 246867580
     Topic: TopicA QID: 2 Diff: -2251220
   ```
   
   `currentLogicOffset 246,867,580 / 20 = 12,343,379` is node2's frozen CQ 
position. `expectLogicOffset 244,616,360 / 20 = 12,230,818` is the first offset 
node0 assigned as leader. node2 kept skipping all of node0's messages; its CQ 
did not advance from 22:21 until 08:02.
   
   5. **2026-11-29 08:02:31, node2 (follower) syncs consumer offsets from 
node0**:
   
   ```text
   INFO BrokerControllerScheduledThread1 - Update slave consumer offset from 
master, node0
   WARN ReputMessageService - Build consume queue repeatedly,
     expectLogicOffset: 245477660 currentLogicOffset: 246867580
     Topic: TopicA QID: 2 Diff: -1389920
   ```
   
   `245,477,680 / 20 = 12,273,884` is the synced consumer offset; it is inside 
node2's stale CQ region `[12,230,818, 12,343,379)`.
   
   6. **2026-11-29 08:02:37, second switch (node0 -> node2)**:
   
   ```text
   node0: INFO DLedgerFlushDataService - Flush data cost=5620 ms
   node1/node2: INFO StateMaintainer - HeartBeatTimeOut 
lastLeaderHeartBeatTime: 2026-11-29 08:02:31.295
   node2: INFO StateMaintainer - [n2] [VOTE_RESULT] has been elected to be the 
leader in term 86
   node0: INFO EntryHandler-n0 - [HandleDoTruncate] truncateIndex=889006409 
pos=640963826121
   ```
   
   At 08:02:57 the clients rebalanced and the first cross-day duplicate 
appeared at 08:02:57.311.
   
   7. **2026-11-29 08:03:10, node0 (now follower)** — the mirror image of 
node2's gap:
   
   ```text
   WARN ReputMessageService - [BUG]logic queue order maybe wrong,
     expectLogicOffset: 246867580 currentLogicOffset: 245477700
     Topic: TopicA QID: 2 Diff: 1389880
   ```
   
   `1,389,880 / 20 = 69,494` slots, exactly `12,343,379 - 12,273,885`.
   
   8. **2026-11-29 11:35:22, third switch (node2 -> node0)** — same signature 
again:
   
   ```text
   node2: INFO DLedgerFlushDataService - Flush data cost=7284 ms
   node0: INFO StateMaintainer - [n0][HeartBeatTimeOut] 
lastLeaderHeartBeatTime: 2026-11-29 11:35:16.818
   node0: INFO StateMaintainer - [n0] [VOTE_RESULT] has been elected to be the 
leader in term 87
   ```
   
   ### Why the same queueOffset maps to different messages
   
   `queueOffset` is a per-queue logical index assigned by the current leader 
from its local `topicQueueTable`, which is recovered from its local 
ConsumeQueue max. It is not a globally unique message ID and carries no leader 
epoch.
   
   - node2's CQ max was `12,343,379` when it lost leadership at 22:21.
   - node0's CQ max was `112,561` slots lower. When node0 became leader at 
22:21:47, it started assigning new offsets from `12,230,818`, reusing numbers 
node2 had already assigned to older messages.
   - node2, as follower, saw `expect < current` for every new message and took 
the `Build consume queue repeatedly` branch, which returns without writing. Its 
stale entries stayed intact.
   - When node2 became leader again at 08:02:38, the consumer offset synced 
from node0 (`12,273,884`) was inside node2's valid CQ range, so POP's range 
check accepted it, but the CQ entries there still pointed to messages stored on 
11-28 06:43.
   
   An offline decode of the QID 7 samples also confirmed the mapping 
difference: the same slot `5,446,769` points to different physical 
addresses/messages on node2 and node0, with a head-offset difference of 14,538 
slots.
   
   ### Impact
   
   - At least 13,892 unique message IDs were reprocessed on 11-29 in the 
08:02:38–08:07:00 window (single application instance, dedup count by message 
ID).
   - Downstream business operations were repeated; the application's 5-minute 
Redis dedup could not cover a cross-day replay.
   - The cluster remained unstable: three leader switches in ~13 hours, each 
preceded by a 5.6–7.3 s leader flush stall.
   
   ### Questions
   
   1. In DLedger mode, is ConsumeQueue reconciliation after a runtime 
`HandleDoTruncate` expected to be handled? If yes, which code path is 
responsible? `DLedgerCommitLog` recover paths handle restart, but this is a 
runtime switch without restart.
   2. Should a broker with a negative CQ gap (`Build consume queue repeatedly`) 
be allowed to become leader? Should promotion validate/rebuild the local 
ConsumeQueue first?
   3. What is the recommended mitigation for 5.3.0 DLedger deployments: rebuild 
the affected ConsumeQueue from the local commitlog, wipe the follower store and 
resync, or migrate to controller mode?
   4. Can the guard proposed in #11617 (refuse truncation below 
`confirmOffset`) be extended to DLedger mode, or is there an equivalent guard 
planned?
   
   ### Related issues
   
   - #1397 DLedger `logic queue order maybe wrong` after crash (workaround: 
delete the affected store and resync)
   - #7355 / #7599 DLedger abnormal recovery may lose the ConsumeQueue tail 
(fixed for restart recovery)
   - #8539 slave did not synchronize `topicQueueTable` after a switch (closed 
as stale)
   - #11603 / #11617 controller-mode truncation below `confirmOffset`
   - #10666 AutoSwitch HA truncation is not crash-safe
   
   We can provide the full broker logs, ConsumeQueue segment files, and DLedger 
data offsets if needed.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to