Skip to content

Fix polling interval adjustment logic when KafkaConsumer has no partition assignment - #100431

Merged
azat merged 3 commits into
ClickHouse:masterfrom
sugaf1204:fix/reset-waited-for-assignment-on-assign
May 24, 2026
Merged

azat merged 3 commits into
ClickHouse:masterfrom
sugaf1204:fix/reset-waited-for-assignment-on-assign

Conversation

@sugaf1204

@sugaf1204 sugaf1204 commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

waited_for_assignment was not reset on partition assign, causing the shortened poll interval to persist even after a successful assignment.

This also increases the fetch rate, leading to more empty poll results and smaller data parts due to fewer records per fetch, which increases merge overhead and degrades performance.

Reset the counter on assignto restore the configured poll interval.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixes Kafka table engine consumers that kept using a short poll interval after partition assignment, so they return to the configured kafka_poll_timeout_ms and avoid excessive empty polls, smaller inserted parts, and extra merge overhead after rebalances.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Touches Kafka consumer group rebalance/assignment handling; although the code change is small, it affects polling behavior and could impact ingestion performance or latency if incorrect.

Overview
Fixes a Kafka engine bug where consumers that previously had no partition assignment could keep using the shortened fallback poll timeout even after an assignment was later received, by resetting waited_for_assignment in the assignment callback.

Adds an integration test that simulates broker unavailability and subsequent recovery, asserting the consumer reaches an assignment and that empty polls after recovery take roughly the configured kafka_poll_timeout_ms (not the 50ms fallback).

Reviewed by Cursor Bugbot for commit 7ba9a55. Bugbot is set up for automated code reviews on this repo. Configure here.

Version info

  • Merged into: 26.6.1.114

@CLAassistant

CLAassistant commented Mar 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…tion assignment

waited_for_assignment was not reset on partition assign, causing the
shortened poll interval to persist even after a successful assignment.
This also increases the fetch rate, leading to more empty poll results
and smaller data parts due to fewer records per fetch, which increases
merge overhead and degrades performance. Reset the counter on assign
to restore the configured poll interval.
@sugaf1204
sugaf1204 force-pushed the fix/reset-waited-for-assignment-on-assign branch from 08e3662 to 1ee2bf3 Compare March 28, 2026 17:40
@sugaf1204 sugaf1204 changed the title Reset waited_for_assignment on partition assign in KafkaConsumer Fix polling interval adjustment logic when KafkaConsumer has no partition assignment Mar 28, 2026
@sugaf1204

Copy link
Copy Markdown
Contributor Author

Hi @filimonov , could you please take a look when you have time?

@azat azat self-assigned this May 15, 2026

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, sounds reasonable
Can you please share some numbers how it can affect?

@azat azat added the can be tested Allows running workflows for external contributors label May 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7ba9a55]

Summary: ❌

job_name test_name status info comment
Unit tests (asan_ubsan, function_prop_fuzzer) FAIL
FunctionsStress.stress FAIL cidb, issue
AllTests FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/check_report_messages.py FAIL

AI Review

Summary

This PR fixes KafkaConsumer poll-timeout behavior after assignment recovery by resetting waited_for_assignment in the assignment callback, and adds an integration regression test that exercises the no-assignment wait path, verifies reassignment, and checks that empty polls after recovery use the configured kafka_poll_timeout_ms again. The previous review concerns on missing regression evidence and placeholder changelog text are addressed in the current revision, and no new correctness, safety, or compatibility issues were found in the changed code.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 21, 2026
Comment thread src/Storages/Kafka/KafkaConsumer.cpp Resolved
Comment thread src/Storages/Kafka/KafkaConsumer.cpp Resolved
@sugaf1204

Copy link
Copy Markdown
Contributor Author

Thanks, sounds reasonable Can you please share some numbers how it can affect?

Thanks for the reply, I compared the metrics between the time when this issue occurred and after recovery via Kafka table DETACH/ATTACH.

kafka_flush_interval_ms is 15000, other is default.

Metric Before After Change
InsertedRows rate (cluster total) 179,581 rows/s 181,452 rows/s +1.0%
InsertedBytes rate (cluster total) 320.9 MB/s 341.1 MB/s +6.3%
KafkaRowsRead rate (cluster total) 30,352 rows/s 33,498 rows/s +10.4%
InsertQuery rate 10–12 /s/host ~2 /s/host ~1/5
Rows per INSERT 3,621–4,517 16,780–23,746 ×4.6–5.5
PartsActive 20K–22K parts/host 6.5K–7.2K parts/host ~1/3
Merge rate 358–407 /s/host 141–169 /s/host ~1/2
MergedRows rate 786K–1034K rows/s 536K–735K rows/s -30–40%
jemalloc resident 47–58 GB/host 43–53 GB/host -2.6 to -4.9 GB/host

Overall throughput stayed effectively unchanged, while significantly reducing insert frequency, active parts, merge pressure, and resident memory usage.

@clickhouse-gh

clickhouse-gh Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (4/4) · Uncovered code

Full report · Diff report

@azat azat added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels May 24, 2026

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sugaf1204 thanks for the numbers, looks good (I've also updated the entry to "Improvement", since bug-fix is a very strong label, and improvement suits better here)

@azat
azat enabled auto-merge May 24, 2026 09:31
@azat
azat added this pull request to the merge queue May 24, 2026
Merged via the queue into ClickHouse:master with commit 0050dcc May 24, 2026
164 of 167 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 24, 2026
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
…for-assignment-on-assign

Fix polling interval adjustment logic when KafkaConsumer has no partition assignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants