Skip to content

Fix lost progress update in clickhouse-local - #112958

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-local-progress-lost-update
Aug 3, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-local-progress-lost-update

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

LocalConnection::receivePacket built the Progress packet with fetchAndResetPiecewiseAtomically, which already zeroes every counter atomically, and then called reset on the same object. The pipeline keeps incrementing those counters from its own threads while the main thread sits between the two statements, so an increment that landed in that window was thrown away instead of being reported. The extra reset is a leftover from the time when the packet was built with std::move.

The visible effect is that a query run through clickhouse-local could under-report rows_read (and the other progress counters) in the statistics of the JSON/XML output and in the progress bar, always losing a whole block at a time.

This is what made 04651_parquet_v3_dictionary_filter_expanding_codec_budget flaky on master. The test compares the reported rows_read of the same query run under two memory budgets, and one of the two runs reported 54591 instead of 120000 - exactly one lost block of the default 65409 rows. Both master failures so far show the same 54591.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=42d5246e282b55b1d6340059a5c3794905d92b99&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%201%2F3%29&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%201%2F3%29

The race window is only a handful of atomic operations wide, so an ordinary query almost never hits it - the test failed twice out of roughly 700 runs. Lowering interactive_delay makes the packet be assembled far more often and a small max_block_size makes every lost increment visible, which turns it into a reliable reproducer:

$ clickhouse-local --interactive_delay 1000 --max_block_size 1000 \
    --query "SELECT count() FROM numbers_mt(20000000) FORMAT JSON" | grep rows_read

Before: 19999000, 19998000, 20000000 (two of three runs lose one or two blocks). After: 35 out of 35 runs report 20000000. The added test 04669_local_progress_lost_update is that reproducer.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix clickhouse-local under-reporting rows_read and the other progress counters in the statistics of the JSON/XML output and in the progress bar: a progress increment that arrived while the progress packet was being assembled was discarded.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

`LocalConnection::receivePacket` built the `Progress` packet with
`fetchAndResetPiecewiseAtomically`, which already zeroes every counter
atomically, and then called `reset` on the same object. The pipeline keeps
incrementing those counters from its own threads while the main thread sits
between the two statements, so an increment that landed in that window was
thrown away instead of being reported. The extra `reset` is a leftover from
when the packet was built with `std::move`.

The result is that a query run through `clickhouse-local` could under-report
`rows_read` (and every other progress counter) in the `statistics` of the
`JSON`/`XML` output and in the progress bar, always by a whole multiple of a
block.

This is what made `04651_parquet_v3_dictionary_filter_expanding_codec_budget`
flaky: the test compares the reported `rows_read` of the same query run under
two memory budgets, and one of the two runs reported 54591 instead of 120000 -
exactly one lost block of the default 65409 rows.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=42d5246e282b55b1d6340059a5c3794905d92b99&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%201%2F3%29&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%201%2F3%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2d95ee1]

Summary: ✅


AI Review

Summary

This PR removes the redundant state->progress.reset() after fetchAndResetPiecewiseAtomically() in LocalConnection::receivePacket, which matches the lost-update race described in the PR body and is consistent with sibling Progress senders that already rely on the fetch-and-reset helper alone. I did not find a remaining correctness gap in the touched path, and the added regression test plus all-green CI provide proportionate evidence for this fix.

Final Verdict

✅ No blocking or major issues found. No new inline review comments were posted.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

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

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good.

CC @PedroTadim

@alexey-milovidov alexey-milovidov self-assigned this Aug 2, 2026

@PedroTadim PedroTadim 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.

LGTM! Let's wait for the CI

@PedroTadim

Copy link
Copy Markdown
Member

@alexey-milovidov check the failed test

@alexey-milovidov

Copy link
Copy Markdown
Member Author

#113011

@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2d95ee1e7 with master 8c925c5bb (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes, slowest function optimization changes (thinlto), symbol sizes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 685.32 MiB 682.33 MiB -3.00 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes ⚠️

4 object files changed (-40.18 MiB total), 0 added, 685 removed.

Object file Master PR Δ
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/chttp2/transport/cht… 960.56 KiB removed -960.56 KiB (-100.00%)
src/Common/ZooKeeper/CMakeFiles/clickhouse_common_zookeeper_no_log.dir/ZooKeeperImpl.cpp.o 804.97 KiB removed -804.97 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/server/server.cc.o 612.22 KiB removed -612.22 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/load_balancing/rls/rls.cc.o 611.36 KiB removed -611.36 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/client_channel_filt… 548.04 KiB removed -548.04 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/client_channel.cc.o 525.46 KiB removed -525.46 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/retry_interceptor.c… 518.85 KiB removed -518.85 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/lib/channel/promise_based_filter.c… 482.91 KiB removed -482.91 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/load_balancing/grpclb/grpclb.cc.o 434.97 KiB removed -434.97 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/client_call.cc.o 433.89 KiB removed -433.89 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/server_call.cc.o 391.29 KiB removed -391.29 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc++_unsecure.dir/__/grpc/src/cpp/server/server_cc.cc.o 384.88 KiB removed -384.88 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/retry_filter_legacy… 369.55 KiB removed -369.55 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/chttp2/transport/wri… 349.81 KiB removed -349.81 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_grpc_utils.dir/__/google-cloud-cpp/googl… 346.93 KiB removed -346.93 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/inproc/legacy_inproc… 345.35 KiB removed -345.35 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_longrunning_operations_protos.dir/google… 339.33 KiB removed -339.33 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_iam_credentials_v1_iamcredentials_protos… 334.24 KiB removed -334.24 KiB (-100.00%)
contrib/google-protobuf-cmake/CMakeFiles/_libprotobuf-lite.dir/__/google-protobuf/src/google/protob… 316.58 KiB removed -316.58 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/call_spine.cc.o 312.88 KiB removed -312.88 KiB (-100.00%)
Slowest function optimization changes (ThinLTO) ⚠️

Median per-function time ratio to the master baseline is ×1.30 (different machine and build flags); deltas below are relative to that ratio.

Binary Function Master PR Δ vs median
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 17.9 s +17.9 s
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 7.9 s gone -10.2 s (-100%)
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 7.8 s gone -10.1 s (-100%)
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 7.8 s +7.8 s
programs/clickhouse-keeper DB::registerFunctionConversion(DB::FunctionFactory&) 6.0 s 15.5 s +7.6 s (+98%)
programs/clickhouse-keeper _GLOBAL__sub_I_TargetLibraryInfo.cpp 5.6 s 12.0 s +4.7 s (+64%)
programs/clickhouse DB::Parquet::writeColumnChunkBody(DB::Parquet::ColumnChunkWriteState&, DB::Parquet::WriteOptions co… 5.0 s 3.6 s -3.0 s (-45%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.54623650351436… new 2.9 s +2.9 s
programs/clickhouse DB::getSettingsChangesHistory()::$_0::operator()() const 4.3 s 2.9 s -2.7 s (-48%)
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.56540966842… new 2.6 s +2.6 s
programs/clickhouse DB::Aggregator::writeToTemporaryFile(DB::AggregatedDataVariants&, unsigned long) const 3.4 s 1.9 s -2.5 s (-57%)
programs/clickhouse DB::attachSystemTablesServer(std::__1::shared_ptr<DB::Context const>, DB::IDatabase&, bool, bool) 4.3 s 3.2 s -2.4 s (-43%)
programs/clickhouse-keeper _ZN2DB18FunctionArrayIndexINS_16CountEqualActionENS_14NameCountEqualEE15executeIntegralIJDutjmDB8_s… 1.7 s 4.5 s +2.3 s (+104%)
programs/clickhouse-keeper _GLOBAL__sub_I_sqid.cpp 1.7 s 4.4 s +2.3 s (+105%)
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 1.7 s gone -2.2 s (-100%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 1.6 s gone -2.1 s (-100%)
Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Symbol sizes ⚠️
Binary Symbol Master PR Δ
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 439.45 KiB removed -439.45 KiB (-100.00%)
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 439.45 KiB removed -439.45 KiB (-100.00%)
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 439.45 KiB +439.45 KiB
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 439.45 KiB +439.45 KiB
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 114.16 KiB removed -114.16 KiB (-100.00%)
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.54623650351436… new 114.16 KiB +114.16 KiB
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 114.16 KiB removed -114.16 KiB (-100.00%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.54623650351436… new 114.16 KiB +114.16 KiB
programs/clickhouse DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.16712493492… 102.51 KiB removed -102.51 KiB (-100.00%)
programs/clickhouse DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.56540966842… new 102.51 KiB +102.51 KiB
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.16712493492… 102.51 KiB removed -102.51 KiB (-100.00%)
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.56540966842… new 102.51 KiB +102.51 KiB
programs/clickhouse DB::DatabaseDataLakeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.9031… 97.41 KiB removed -97.41 KiB (-100.00%)
programs/clickhouse DB::DatabaseDataLakeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.1111… new 97.41 KiB +97.41 KiB
programs/clickhouse DB::ObjectStorageQueueSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.14… new 92.15 KiB +92.15 KiB
programs/clickhouse DB::ObjectStorageQueueSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.10… 92.15 KiB removed -92.15 KiB (-100.00%)
programs/clickhouse DB::KafkaSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.872715978862839… new 89.47 KiB +89.47 KiB
programs/clickhouse DB::KafkaSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.176316896530569… 89.47 KiB removed -89.47 KiB (-100.00%)
programs/clickhouse DB::DataLakeStorageSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.41967… 88.38 KiB removed -88.38 KiB (-100.00%)
programs/clickhouse DB::DataLakeStorageSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.13841… new 88.38 KiB +88.38 KiB

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit 27da146 Aug 3, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-local-progress-lost-update branch August 3, 2026 18:55
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 2026
pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request Aug 10, 2026
…tic placement

The test asserts that the first `ORDER BY k ASC LIMIT 5` run under the TopK
plan writes a query condition cache entry (`count() > 0`). An entry is only
written when at least one chunk is reduced to zero rows at the `WHERE`
filter, which depends on where the smallest `w = 7` rows happen to land:
placement was `rand()`, so a run could get a `__topKFilter` threshold
trajectory under which every chunk kept at least one row and no entry was
written (2 of 300 runs in a local loop on a release build). ClickHouse#111492 made
this much more likely by shrinking the table from 1M rows (~123 chunks per
scan) to 100k (~12 chunks); the same mode had been seen once with 1M rows
on a flaky-check job before that.

Place the five smallest `w = 7` rows at the front of the part and scatter
every other row with a deterministic hash above the first chunk: the
threshold tracker arms at its final value (`k = 4007`) right after the
first chunk, and every later chunk deterministically empties at the `WHERE`
filter and is recorded (1436 of 1564 marks). Verified locally: 30/30 runs
pass, plus 10/10 with the failing run's randomized settings; the reference
output is unchanged.

Failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112958&sha=ab076f814382fccafac0dd27dbe5e152d7204619&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20sequential%2C%202%2F2%29
PR with the failure: ClickHouse#112958

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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