Skip to content

[ISSUE #141] fix(legacy): stop the legacy source rewinding and surface legacy sink async failures - #148

Merged
lizhimins merged 1 commit into
apache:mainfrom
lizhimins:fix-legacy-source-sink-offsets
Oct 26, 2026
Merged

lizhimins merged 1 commit into
apache:mainfrom
lizhimins:fix-legacy-source-sink-offsets

Conversation

@lizhimins

Copy link
Copy Markdown
Member

Motivation

Two silent-wrong-data defects in the legacy connector, both found by an acceptance run against a commercial 5.5.1 cluster (Flink 1.20.3, Application mode) and both in the family ISSUE #141 tracks: the job stays RUNNING, checkpoints succeed, nothing is logged, and the data is wrong.

1. The legacy source re-emits its whole topic, forever. pollAndEmit read the next position back from DefaultLitePullConsumer#committed after every poll. Auto-commit is off by default, so the broker-side commit never advances and every round re-seeked to the same offset. Measured: 101 source messages became 120065 sink messages (118560 duplicates) with the job RUNNING, zero restarts and zero errors.

Two related faults fell out of fixing it:

  • poll drains all assigned queues, so seeking from one queue thread after another thread's poll rewound that queue and re-emitted what it had just drained. The first version of this fix still duplicated 30 messages for exactly this reason; seek + poll + booking are now atomic under the checkpoint lock.
  • initOffsets stored committed() verbatim, which is -1 for a group that has never committed. Only the GROUP_OFFSETS branch had a fallback for that, so with EARLIEST/LATEST the first seek failed with Seek offset illegal and the source gave up, finishing the job having read nothing. It now falls back to the position the preceding seek left in the local offset store.

2. The legacy sink checkpoints over lost records. An async send failure is parked and rethrown from finish(), and invoke() checks it too — but a burst of failures followed by an idle stream never reaches another invoke(), and snapshotState did not check at all. Measured: 101 rejected sends, 101 Async send message failure! errors, 0 task failures, 12 successful checkpoints, a clean stop-with-savepoint, and 0 records in the sink topic. snapshotState now surfaces the parked failure, so a checkpoint cannot commit a loss.

Modification

  • RocketMQSourceFunction: book the read position from the messages a poll drains (per queue, forward-only); make seek + poll + booking atomic; never store a negative start position.
  • RocketMQSink: call checkAsyncSendException() from snapshotState().
  • Tests: RocketMQSourceFunctionTest gains a poll-position test (a stale committed() of 0 must not rewind a position of 6); new RocketMQSinkAsyncFailureTest pins that snapshotState fails the checkpoint when an async send already failed.

Verification

  • mvn -pl flink-connector-rocketmq test: 123 tests, 0 failures, 0 errors.
  • Cluster acceptance, legacy source + legacy sink, 100 messages: duplicates 118560 → 0, missing 0, unexpected 0, tail marker received with matching count.
  • Cluster acceptance, legacy sink in pure async mode with every send rejected (CODE 13): task failures 0 → 3, stack top IOException: Async send message failed at RocketMQSink.checkAsyncSendException ← snapshotState, i.e. the loss is now loud instead of silent.

…surface legacy sink async failures

The legacy source read its next position back from DefaultLitePullConsumer#committed
after every poll. Auto-commit is off by default, so the broker-side commit never
advances and every poll round re-seeked to the same offset and re-emitted the whole
topic: an acceptance run on a commercial 5.5.1 cluster turned 101 source messages
into 120065 sink messages (118560 duplicates) while the job stayed RUNNING with no
restarts and no errors. Book the position from the messages a poll drains instead,
per queue, because poll serves every assigned queue.

Seeking, polling and booking now happen under one lock. poll drains all assigned
queues, so a seek issued by one queue thread after another thread's poll rewound
that queue and duplicated the messages it had just drained; the first version of
this fix still showed 30 duplicates for that reason.

initOffsets also stored committed() verbatim, which is -1 for a group that has
never committed. The EARLIEST and LATEST branches had no fallback for it (only
GROUP_OFFSETS did), so the first seek failed with "Seek offset illegal" and the
source gave up, finishing the job having read nothing. Fall back to the position
the preceding seek left in the local offset store.

The legacy sink parked the first async send failure and rethrew it from finish(),
and invoke() checks it too, but a burst of failures followed by an idle stream
never reaches another invoke, and snapshotState did not check at all: checkpoints
completed over the lost records and stop-with-savepoint succeeded. Check the
parked failure in snapshotState as well, so a checkpoint cannot commit a loss.

Verified on a commercial 5.5.1 cluster with Flink 1.20.3: legacy source + legacy
sink, 100 messages, duplicates 118560 -> 0; legacy sink in pure async mode with
every send rejected, task failures 0 -> 3 with the IOException raised from
snapshotState, i.e. the loss is now loud instead of silent.
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.

1 participant