Fix `deltaSumTimestamp` returning wrong results for signed integer types crossing zero by thevar1able · Pull Request #104830 · ClickHouse/ClickHouse · GitHub
Skip to content

Fix deltaSumTimestamp returning wrong results for signed integer types crossing zero#104830

Merged
thevar1able merged 7 commits into
masterfrom
fix-deltaSumTimestamp-signed-types
Jun 15, 2026
Merged

Fix deltaSumTimestamp returning wrong results for signed integer types crossing zero#104830
thevar1able merged 7 commits into
masterfrom
fix-deltaSumTimestamp-signed-types

Conversation

@thevar1able

@thevar1able thevar1able commented May 13, 2026

Copy link
Copy Markdown
Member

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 deltaSumTimestamp returning wrong results for signed integer types crossing zero. Resolves #104750.

Version info

  • Merged into: 26.6.1.830

@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 13, 2026
Comment thread tests/queries/0_stateless/04234_deltaSumTimestamp_signed_types.sql Outdated
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

Maoyao233 pushed a commit to Maoyao233/ClickHouse that referenced this pull request Jun 8, 2026
`test_hedged_requests/test.py::test_stuck_replica` is chronically flaky
on heavily overcommitted ASan/UBSan integration shards. The failure shape
in CIDB is identical across 9 unrelated PRs in the past 30 days:

    pause_container('node_1') did not become observably effective within
    90.0s ... still succeed after ~890 probe iterations; last outcome:
    server replied (4 bytes)

The probe in `_wait_for_pause_effective` keeps receiving live ClickHouse
exception packets from `node_1` for the entire 90s budget, which proves
that `docker compose pause` returned success while the cgroup freezer
never actually froze the user-space tasks. The existing SIGSTOP fallback
in `ClickHouseCluster.pause_container` only fires when `docker compose
pause` raises an exception, not when it lies about success, so the
escalation path was never taken.

Switch this test to `cluster.pause_container_using_signal`, which uses
`SIGSTOP`/`SIGCONT` from the start. A signal cannot be silently lost the
way the cgroup freezer can, so the pause becomes observable on the very
first probe iteration. Same helper is already used by
`test_postgresql_replica_database_engine` for the same reason.

The change is local to one call site. The chronic flake hit
`Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6)` in the
following PRs (CIDB, last 30 days): ClickHouse#103404, ClickHouse#106311, ClickHouse#105010, ClickHouse#105056,
ClickHouse#104830, ClickHouse#106025, ClickHouse#100391, ClickHouse#106571, ClickHouse#103229. All show the same
`server replied (4 bytes)` outcome, distinguishing this from generic
flakiness.

Related: ClickHouse#106571
04234 collided with several tests added on master since the branch
diverged; move deltaSumTimestamp test to the next free number 04339.
The fix also changes dispatch for Int8/Int16 value types in
`createWithTwoTypes` and for signed Int32/Int64 timestamp types in
`createWithTwoTypesSecond`, but the test only exercised Int32/Int64
values with unsigned timestamps. Add focused cases crossing zero for:
- Int8 and Int16 values;
- the result type of every signed value width;
- Int32 and Int64 signed timestamps (via state merge ordering).

Addresses the review feedback on uncovered code paths.
The previous comment justified treating signed and unsigned data types
the same way, which is exactly what introduced the bug: the serialized
binary representation is identical, but the arithmetic differs once
values cross zero. Document this so the unification is not reintroduced.
@clickhouse-gh

clickhouse-gh Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.10% 85.10% +0.00%
Functions 92.40% 92.30% -0.10%
Branches 77.40% 77.30% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 16/16 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@thevar1able thevar1able marked this pull request as ready for review June 15, 2026 14:06

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

Just to be sure, this is backwards compatible with the states already stored in tables?

@evillique evillique self-assigned this Jun 15, 2026
@thevar1able thevar1able added this pull request to the merge queue Jun 15, 2026
Merged via the queue into master with commit c3c6de7 Jun 15, 2026
166 checks passed
@thevar1able thevar1able deleted the fix-deltaSumTimestamp-signed-types branch June 15, 2026 16:30
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 15, 2026
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.

deltaSumTimestamp returns wrong results for signed integers crossing from negative to positive

4 participants