Repository navigation
Support the KIP-848 consumer group protocol in the Kafka engine - #127757
rorylshanks wants to merge 8 commits into
Conversation
With `group.protocol=consumer` (KIP-848) the rebalance protocol is always cooperative: rebalances pass only the partitions being added or revoked, and librdkafka rejects `rd_kafka_assign`. Both cppkafka's rebalance handler and `KafkaConsumer` called it, so a `Kafka` table configured with `<group_protocol>consumer</group_protocol>` never got its partitions and consumed nothing. - Bump cppkafka to use `rd_kafka_incremental_assign` / `rd_kafka_incremental_unassign` in the rebalance handler under the cooperative protocol. - `KafkaConsumer` tracks the assignment incrementally, and rewinds with `seek` under the cooperative protocol. After a partial revocation, the partitions that stay assigned are rewound to the committed offsets, since the current batch is dropped. - Document `group_protocol`. - Test it in `test_storage_kafka_sasl`, whose broker is bumped to `cp-kafka:8.0.0` (Kafka 4.0, required by KIP-848). Related: ClickHouse/cppkafka#9 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [f070db6] Summary: ❌
AI ReviewSummaryThe PR enables KIP-848 consumption in the Findings❌ Blockers
Tests
Missing context / blind spots
Final VerdictStatus: ❌ Block. Preserve concrete rollback offsets when no broker checkpoint exists and add the focused |
Under the cooperative protocol re-subscribing a dirty consumer keeps the assignment and the fetch positions, so after a failed insert the next block started after the failed one and its commit skipped it. Rewind to the committed offsets explicitly instead. `seek` also keeps the stored offsets, so an offset-less commit could persist the offsets of rewound messages. Reset them together with the fetch positions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
No conflicts. Picks up the fix for the flaky `05055_format_schema_source_query_background_access` test (ClickHouse#127797). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Pin `contrib/librdkafka` to a fix that stops `rd_kafka_app_polled` from reading `rkcg_flags` and expediting the next heartbeat on the application thread. The consumer group state is owned by the `librdkafka` main thread, which writes `rkcg_flags` without a lock in `rd_kafka_cgrp_handle_ConsumerGroupHeartbeat`, so every poll of a `group.protocol=consumer` consumer raced with heartbeat responses. This was reported by ThreadSanitizer in `test_storage_kafka_sasl/test.py::test_kafka_kip848_consumer_group_protocol`. The main thread already resumes heartbeats after a poll on its own, based on the atomic `rk_ts_last_poll`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127757&sha=8a7d4f876f2fb445eabc63d016c5bec72c7f079d&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%20targeted%29 ClickHouse#127757 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…ocation The existing KIP-848 test changes the group membership only after all the produced rows have reached the target, so it would pass without the rewind of the retained partitions in `KafkaConsumer::doPoll`. Add a focused case: produce continuously with long blocks, add a second member right after a commit so that the revocation drops a block that already holds rows from the partitions the first member keeps (checked via `KafkaRowsRejected`), and verify that all the rows reach the target after the following commits. Move the table and wait helpers to the module level to share them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Replace the timing-based `test_kafka_kip848_partial_revocation_rewinds_unfinished_block` from 89d7879, which produced continuously with 15 s blocks and relied on the revocation arriving while a block was being formed. Add the pausable failpoint `kafka_consumer_pause_mid_block` to `KafkaSource`: it holds the streaming thread after a poll returned nothing while the block already has rows. The test produces a fixed batch to all 6 partitions, holds the first table's block once it has read every row, adds a second group member, and waits until the broker has told the first member to revoke a part of its partitions (no member owns all 6 any more). Then it releases the block: the next poll revokes the partitions, the block is dropped (`KafkaRowsRejected` grows by the whole batch), and every produced id must reach the target exactly once, which needs the rewind of the retained partitions in `KafkaConsumer::doPoll`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| read_from.push_back(offsets[i]); | ||
|
|
||
| if (!read_from.empty()) | ||
| consumer->seek(read_from, SEEK_TIMEOUT_MS); |
There was a problem hiding this comment.
[Blocker] Preserve a concrete rollback offset before the first commit
For a new group or a newly added partition, get_offsets_committed returns OFFSET_INVALID until the first successful commit. Passing that value to seek reapplies auto.offset.reset. With <auto_offset_reset>latest</auto_offset_reset>, a failed first insert therefore rewinds to the current end and permanently skips the discarded rows. The same problem affects retained partitions during a partial revocation before their first commit.
I reproduced the exact seek / store_offsets sequence against the bundled librdkafka revision with group.protocol=consumer: after reading offsets 0–4 without committing, the broker checkpoint was -1001; rollback returned no replay, and the next newly produced message was offset 5. Both controls replayed 0: earliest without a checkpoint, and latest with committed offset 0.
Please retain an explicit block-start offset for each polled partition until its block is committed, and use that concrete offset when no broker checkpoint exists, including across partial revocation. Add a focused latest regression; the existing tests use earliest, which masks this case.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units24 translation units recompiled, 100 s compile time in total, 24 of them have a recent master baseline. |
Establish the group's initial `latest` checkpoint before reading a new partition. Finish each cooperative `kafka_commit_every_batch` insert before polling again so that a handoff can replay an unfinished insert. Cover a failed first insert, partition handoff, and group recovery using an isolated topic for each integration test.
The
Kafkaengine did not work withgroup.protocol=consumer(KIP-848): that protocol's rebalances are always cooperative (only the added or revoked partitions are passed) and librdkafka rejectsrd_kafka_assign, which both cppkafka's rebalance handler andKafkaConsumerused. The consumer never got its partitions.The cppkafka change is in a separate PR; the submodule points to its commit until that is merged.
Related: ClickHouse/cppkafka#9
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
Kafkatable engine now supports the next-generation consumer group protocol of Kafka 4.0 (KIP-848). Set<group_protocol>consumer</group_protocol>in the<kafka>configuration to enable broker-managed incremental partition assignment.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127757]