Skip to content

Convert asserts to chasserts - #105256

Merged
antaljanosbenjamin merged 22 commits into
masterfrom
convert-asserts-to-chasserts
May 29, 2026
Merged

antaljanosbenjamin merged 22 commits into
masterfrom
convert-asserts-to-chasserts

Conversation

@antaljanosbenjamin

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Some tests might fail in debug builds because of existing asserts. I converted all asserts in our code base (only src directory) to chassert so their check is actually enforced in our CI.

@clickhouse-gh

clickhouse-gh Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a91de4a]

Summary: ✅


AI Review

Summary

This PR broadly converts project assert checks to chassert, adds a style-check rule banning new assert uses, and includes a focused ProtobufList parser-reset regression test. The ProtobufList state-reset fix now has targeted coverage, but I cannot approve while the PR still removes the documented debug-only escape hatch for heavy assertions.

Findings

⚠️ Majors

  • [ci/jobs/scripts/check_style/check_cpp.sh:453; src/Databases/DatabaseReplicatedWorker.cpp:693] [dismissed by author -- https://github.com/Convert asserts to chasserts #105256#discussion_r3302719976, https://github.com/Convert asserts to chasserts #105256#discussion_r3302718049] base/base/defines.h documents chassert for lightweight checks only and explicitly leaves heavy checks debug-only, but this style rule now forbids assert unconditionally. The current diff already converts assertions that do remote or mutable work, for example zookeeper->exists, zookeeper->get, and db_disk->existsFileOrDirectory in DatabaseReplicatedWorker, DDLWorker, and DatabaseOnDisk, so sanitizer builds now perform Keeper RPCs or disk lookups only because an assertion is enabled. Keep an explicit escape hatch for heavy debug-only assertions and move remote/disk checks back to debug-only assert or to normal validation based on already-fetched local state.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: preserve a supported debug-only assertion path for heavy checks, and remove Keeper/disk work from chassert before enforcing the blanket style-check ban.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR. labels May 18, 2026
@Algunenano Algunenano self-assigned this May 18, 2026
Comment thread contrib/librdkafka Resolved
@antaljanosbenjamin
antaljanosbenjamin force-pushed the convert-asserts-to-chasserts branch from eec60e5 to 56e789f Compare May 18, 2026 17:34
@antaljanosbenjamin antaljanosbenjamin removed the submodule changed At least one submodule changed in this PR. label May 18, 2026
Comment thread src/Storages/StorageStripeLog.cpp Resolved
Comment thread src/Interpreters/SessionLog.cpp Resolved
@nikitamikhaylov

Copy link
Copy Markdown
Member

It would be nice to add the rule to the stylecheck.

@antaljanosbenjamin

Copy link
Copy Markdown
Member Author

It would be nice to add the rule to the stylecheck.

Yes, I am planning to do that also, but first I want to see how easy to make this work. The style-check is somewhat independent from this, because even if I cannot convert all of these asserts, I can still add a stylecheck, that is only for the new code.

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

Some minor comments

Comment thread src/Formats/ProtobufReader.cpp Resolved
Comment thread src/IO/readDecimalText.h Resolved
@antaljanosbenjamin

Copy link
Copy Markdown
Member Author

@Algunenano I found even more assert and added the style-check. Please check the new changes.

@antaljanosbenjamin
antaljanosbenjamin force-pushed the convert-asserts-to-chasserts branch from cb51920 to a24f314 Compare May 20, 2026 10:06
@Algunenano

Copy link
Copy Markdown
Member

Stress test fix: #105410 (or cherry-pick it here)

@antaljanosbenjamin

Copy link
Copy Markdown
Member Author

I think I will merge this as is and your PR can be merged separately.

huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request May 20, 2026
…s test

`FunctionsStressTestThread::run` calls `context->setCurrentQueryId("")`
on every iteration but never refreshes `ThreadStatus::query_id`. When
the destructor's `(no ctx && empty id) || (ctx && id matches)` check
became a `chassert` (PR ClickHouse#105256), every worker tripped it.

Detach from the thread group right before `thread_status.reset()` so
the destructor sees the cleared state.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105256&sha=a24f314f927ad5c12e928028e20be8d32d10b302&name_0=PR&name_1=Unit%20tests%20%28tsan%2C%20function_prop_fuzzer%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Comment thread src/Databases/DatabaseReplicated.cpp Resolved
antaljanosbenjamin and others added 3 commits May 26, 2026 15:05
Reasoning: ProtobufListInputFormat::resetParser now calls serializer->resetState, but ProtobufSerializerEnvelope::resetState only resets envelope-level flags and does not clear ProtobufSerializerMessage::FieldInfo::field_read. If readRow throws after at least one field was already marked as read, the catch path rolls back columns but leaves field_read dirty. On the next row, stale field_read can suppress default insertion for absent fields, producing incorrect row values or column-size divergence.
@clickhouse-gh

clickhouse-gh Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 1813/2051 (88.40%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 61 line(s) · Uncovered code

Full report · Diff report

@antaljanosbenjamin
antaljanosbenjamin added this pull request to the merge queue May 29, 2026
Merged via the queue into master with commit f671235 May 29, 2026
166 checks passed
@antaljanosbenjamin
antaljanosbenjamin deleted the convert-asserts-to-chasserts branch May 29, 2026 15:10
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 29, 2026
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
…s test

`FunctionsStressTestThread::run` calls `context->setCurrentQueryId("")`
on every iteration but never refreshes `ThreadStatus::query_id`. When
the destructor's `(no ctx && empty id) || (ctx && id matches)` check
became a `chassert` (PR ClickHouse#105256), every worker tripped it.

Detach from the thread group right before `thread_status.reset()` so
the destructor sees the cleared state.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105256&sha=a24f314f927ad5c12e928028e20be8d32d10b302&name_0=PR&name_1=Unit%20tests%20%28tsan%2C%20function_prop_fuzzer%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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.

5 participants