Repository navigation
fix(kafka): use explicit transaction checkpoints - #27593
mergify[bot] merged 2 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
6b968c2 to
0ed6cb6
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking correctness issue: the statement suffix is separated, but the queue is still session-global and is not closed at every real transaction terminal.
TxnHandler.Commit publishes or discards the queue, but two other production paths call commitUnsafe directly:
createUnsafecommits an active transaction beforeBEGINcreates the replacement transaction (pkg/frontend/txn.go:551).SetAutocommitcommits the active transaction for OFF -> ON (pkg/frontend/txn.go:1197).
Neither path finalizes Kafka progress for the transaction that just became durable. This leaves callbacks from generation N in the queue for generation N+1. A concrete counterexample is:
SET autocommit=0;
<successful Kafka INSERT>; -- progress belongs to txn N
BEGIN; -- createUnsafe commits txn N, but keeps its progress
ROLLBACK; -- rolls back txn N+1 and discards txn N progress
I added a temporary white-box regression against this exact lifecycle: the old txn operator had commitCalls == 1, but after the replacement txn rollback the progress callback observed [false]; the required result is [true]. This recreates the same durable-data / missing-LAST_KAFKA_MESSAGE_ID / missing-group-offset split that this PR is meant to eliminate.
The same missing terminal exists when SET autocommit=1 commits an active transaction and a later assignment in the same multi-assignment SET fails: statement cleanup discards progress for data that is already durable. A second temporary regression also produced actual [false], expected [true].
Please bind queued progress to a transaction generation, or centralize progress finalization so every actual commit/rollback terminal handles its own generation exactly once. Add regressions for at least active-txn BEGIN rollover and OFF -> ON autocommit followed by a later SET error, in addition to the current statement-savepoint tests.
The #27587 path itself is correctly fixed and its unit/E2E tests are useful. Performance-wise, the new per-statement mark measured 4.17-4.19 ns/op and 0 allocs/op on Apple M4, so that mutex is not a blocker. FinalizeKafkaProgressFrom is O(k) and copies k callback pointers; the larger pre-existing Kafka-txn risk is retaining one client per queued scan and serial finalization of up to 15 seconds per callback, so total commit latency/resource growth is not transaction-wide bounded. That deserves follow-up/coalescing, but it is not the reason for this request-changes decision.
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head 0ed6cb61499098194dbc6e88d8467af504c08b3c against base 92ea12a6c6ffcb0baa0e1bf5de1fa64d8eac01f3. The statement-suffix fix closes #27587 itself, but the new transaction-owned queue is not finalized at every real transaction terminal.
TxnHandler.Commit publishes/discards the queue around commitUnsafe, but createUnsafe calls commitUnsafe directly before replacing an active transaction, and SetAutocommit does the same for OFF -> ON. Neither path closes the Kafka-progress generation that just became durable.
A deterministic public sequence is:
SET autocommit = 0;
-- successful INSERT ... SELECT from Kafka queues progress for txn N
BEGIN; -- createUnsafe commits txn N but leaves its progress queued
ROLLBACK; -- rolls back txn N+1 and discards txn N progressThe Kafka rows from txn N are durable while LAST_KAFKA_MESSAGE_ID() and the consumer offset are lost, recreating the exact data/progress split this PR is meant to prevent. The OFF -> ON path has the same generation leak and can later discard already-durable progress on statement failure.
Bind progress to a transaction generation or centralize finalization at the actual commit/rollback ownership boundary so every terminal closes exactly its own generation once. Add regressions through active-transaction BEGIN rollover and OFF -> ON autocommit, including commit failure and a later failure in the same SET statement.
fengttt
left a comment
There was a problem hiding this comment.
This is not the right thing to do. Should not manage any kafka state in transaction or anything.
Only supported transaction consistent offset management is via,
autocommit = off
explicit offset management in same transaction in ANOTHER table.
0ed6cb6 to
9fe21be
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 63ab449.
The revised ownership model is correct. Kafka progress is statement/session state and the MatrixOne transaction manager no longer publishes, discards, or rolls it back. A drained source transfers its client/progress to the session only after source-pipeline success; executeStmtWithResponse finalizes the detached queue once after the complete statement and after transaction finalization, while source failure and Session.Close discard it. The transaction workspace converts panics to an execution error before this terminal, so panic/error/cancel paths do not publish a failed scan.
For transaction-consistent consumption, the documented autocommit=false checkpoint-table workflow has the right first owner and commit point: lock the ordinary MO checkpoint row, consume from that durable start id, write destination rows, then update the checkpoint from LAST_KAFKA_MESSAGE_ID() in the same MO transaction. Rollback restores both MO tables; the session last id intentionally remains non-transactional and is not the retry source. The real E2E covers rollback and commit, and the simulator covers the manual-checkpoint error stages.
I also checked multi-statement terminals, transaction commit/rollback paths, queue detach/clear ordering, client release, repeated cleanup, and the existing bounded 15-second autocommit broker commit. No new wait, retry, memory-growth, or log-storm blocker is introduced by this delta. This is a focused correction/removal of misplaced ownership rather than a new architecture requiring a separate design gate; docs/cn/kafka_exttab.md now records the stable contract and limitations.
Validation on this exact head:
- focused frontend tests passed;
- simulator success/error tests passed for 20 repetitions;
- focused frontend race tests passed for 10 repetitions;
- diff check passed;
- latest CI is green.
No blocking findings.
aunjgr
left a comment
There was a problem hiding this comment.
Approved at exact head 63ab4495629ce3e23e7d8139b9b7634b9c019cb7 against base 5bc051abc44f34ccb6813e2a0bb5585d5a1db67e.
The revision now follows the recorded ownership contract: Kafka offsets and LAST_KAFKA_MESSAGE_ID() are whole-statement/session state, not MatrixOne transaction state. Source EOF transfers the client exactly once; source/pipeline failure discards locally; successful source reset queues it; the statement terminal publishes or discards after transaction finalization; and session close drains leftovers. Removing all transaction-manager callbacks eliminates the cross-generation ownership problem rather than coordinating another queue state machine.
The documented autocommit=false checkpoint-table workflow gives transaction-consistent consumers the correct durable owner and retry source. Rollback restores destination and checkpoint together while the session last ID intentionally remains non-transactional. The E2E and simulator cover rollback, commit, and manual-checkpoint failure stages. I found no additional correctness, wait, leak, or unbounded-growth blocker.
Merge Queue Status
This pull request spent 49 minutes 40 seconds in the queue, including 49 minutes 6 seconds running CI. Required conditions to merge
|
Conflict in test/kafkaexttab/kafka_e2e_local_test.go with matrixorigin#27593 (fix(kafka): use explicit transaction checkpoints), which reworked the simulator's transaction bookkeeping while this branch added error-mode cases to the same two switches. Both sides are additive: upstream's ROLLBACK line now clears pendCheckpointSet instead of pendLastSet, and its kafka_checkpoint query case sits alongside the error-mode cases. Taken as such, with upstream's rewritten line kept. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_016qdL5akNrbUfXfqjC659n6
What type of PR is this?
Which issue(s) this PR fixes:
issue #27587
What this PR does / why we need it:
Kafka scan progress is statement/session state, not MatrixOne transaction
state. The previous transaction-owned queue could publish or discard progress
at the wrong lifecycle terminal and still could not make a Kafka group offset
atomic with MatrixOne data.
This change:
TxnHandler.Commitand rollback paths;LAST_KAFKA_MESSAGE_ID()is statement/session state;with
autocommit=false, lock/read an ordinary checkpoint-table row, writedestination data, and update that checkpoint with
LAST_KAFKA_MESSAGE_ID()in the same MatrixOne transaction;explicit checkpoint roll back and commit atomically;
callbacks and covers manual-checkpoint error paths.
Local validation on
63ab44956:make config,make err-check, andgit diff --check: pass;checkpoint rollback/commit atomicity.