Commit 062f261
[server] Fix leader using stale RT position when executing topic switch (linkedin#2669)
* [server] Fix leader using stale RT position when executing topic switch in
non-A/A mode
When the leader executes a topic switch,
preparePositionCheckpointAndStartConsumptionAsLeader
uses getLeaderPosition which returns latestProcessedRtPosition from the
previous topic.
Since this is not EARLIEST, calculateRtConsumptionStartPositions is skipped
and the leader
subscribes to the new topic at a position from the old topic, which is
meaningless.
This is exposed by a race condition in testLeaderHonorLastTopicSwitchMessage:
if the leader
processes the first TopicSwitch (to tmp1) before the second (to tmp2) is
drained, it consumes
all of tmp1, updating latestProcessedRtPosition to the end of tmp1. When it
then switches to
tmp2, it uses tmp1's end position, missing all of tmp2's data.
The fix resets latestProcessedRtPosition to EARLIEST before switching, which
forces
calculateRtConsumptionStartPositions to compute the correct start position
from the
TopicSwitch's rewindStartTimestamp. This is safe because
leaderExecuteTopicSwitch only
runs after unsubscribing and waiting for all pending callbacks, and is only
called when
switching to a different topic.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [server] Also reset checkpointed RT position in OffsetRecord during topic
switch
getLatestProcessedRtPosition() falls back to getCheckpointedRtPosition() in
the
OffsetRecord when the in-memory value is EARLIEST. Without also resetting the
checkpointed position, the stale checkpoint from the previous topic would
still
be used as the start position for the new topic.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 7bdc3d2 commit 062f261
1 file changed
Lines changed: 13 additions & 0 deletions
File tree
- clients/da-vinci-client/src/main/java/com/linkedin/davinci/kafka/consumer
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1322 | 1322 | | |
1323 | 1323 | | |
1324 | 1324 | | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
1325 | 1338 | | |
1326 | 1339 | | |
1327 | 1340 | | |
| |||
0 commit comments