Skip to content

Bump croaring from v4.5.1 to v5.1.1 - #118917

Merged
thevar1able merged 1 commit into
ClickHouse:masterfrom
actueleai:bump-croaring-v5.1.1
Sep 10, 2026
Merged

thevar1able merged 1 commit into
ClickHouse:masterfrom
actueleai:bump-croaring-v5.1.1

Conversation

@actueleai

@actueleai actueleai commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Bumps croaring from v4.5.1 to v5.1.1 (upstream RoaringBitmap/CRoaring, commit 025ae3f7add169bc820dcfd46fa9304f382ec40a → 342463b31b909737bd6295c69b2f8e0ed9497424). The submodule points at upstream directly, so there is no fork branch and no patches to carry.

The notable upstream fix is in croaring_refcount_dec in include/roaring/portability.h, which compared the pointer rather than the value (return val == 0; → return *val == 0;) and so never signalled a refcount reaching zero on the non-atomic path; ClickHouse builds take the atomic path, so this was latent here. Roaring64Map::write/read/readSafe now route the map size and the high-32-bit keys through the new croaring_htole*/croaring_letoh* helpers — a no-op on little-endian, so the persisted groupBitmap state format is unchanged on every architecture ClickHouse ships. readSafe additionally checks that eight bytes are available before reading the map size and advances via roaring_bitmap_portable_deserialize_size. The rest is additive: cpp/roaring/roaring64.hh, Roaring64Map::containsRange/containsRangeClosed, Roaring::mask/maskClosed, Roaring::serializedSizeInBytesSafe, iterator read_ranges/read_prev_ranges, ROARING_FLAG_FROZEN_ART and RISC-V detection in portability.h. frozenView and portableDeserializeFrozen now return non-const Roaring/Roaring64Map, which is source-compatible since nothing in src binds those results to a const-qualified type.

No ClickHouse-side adaptation was needed — the commit touches only the submodule pointer. The SRCS list in contrib/croaring-cmake/CMakeLists.txt still matches the 22 .c files in the new tree exactly (no .c file was added, removed or renamed between the two tags), and the only upstream src/CMakeLists.txt change is a new ROARING_SANITIZE_MEMORY option that ClickHouse does not use. The OS_FREEBSD bswap64=__bswap64 workaround stays, as portability.h still uses bswap64 there. The 30 files under src/ that include roaring headers — FunctionsBitmap.*, AggregateFunctionGroupBitmapData.h, the text-index posting-list codecs, DeleteBitmap, the Iceberg/DeltaLake deletion vectors and the Puffin format — need no changes.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

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

Bump croaring from v4.5.1 to v5.1.1. Serialized bitmaps are unchanged on little-endian platforms; on big-endian platforms the on-disk layout of groupBitmap states changes to the portable little-endian format.


Workflow [PR]
Sync PR [sync-upstream/pr/118917]

Version info

  • Merged into: 26.9.1.1173-master (included in 26.9 and later)
  • Backported to: 26.8.11.34, 26.7.14.30, 26.3.33.137

Upstream changes of note:

* Fixes `croaring_refcount_dec` in `portability.h`, which compared the
  pointer instead of the value (`val == 0` instead of `*val == 0`) and
  therefore never reported a dropped-to-zero refcount on the non-atomic
  code path.
* Makes the `Roaring64Map` "portable" serialization actually portable by
  converting the map size and the high-32-bit keys through the new
  `croaring_htole*` / `croaring_letoh*` helpers. On little-endian hosts
  this is a no-op, so the on-disk format of `groupBitmap` states is
  unchanged.
* Hardens `Roaring64Map::readSafe`: it now checks that at least eight
  bytes are available before reading the map size and advances the
  cursor using `roaring_bitmap_portable_deserialize_size` instead of the
  size of the bitmap it just built.
* Adds a `roaring64.hh` C++ header, `Roaring64Map::containsRange` and
  `containsRangeClosed`, `Roaring::mask` / `maskClosed`, range-reading
  iterator methods, and RISC-V detection in `portability.h`.
* Relaxes the return types of `frozenView` and `portableDeserializeFrozen`
  from `const Roaring` to `Roaring`.

No source file was added or removed under `contrib/croaring/src`, so
`contrib/croaring-cmake/CMakeLists.txt` needs no change. The public API
changes are additive, so no adaptation was needed in `src`.

Verified locally by building the `_roaring` and `clickhouse` targets and
by comparing bitmap query output between binaries built with v4.5.1 and
v5.1.1: serialized `groupBitmap` states are byte-identical, and states
written by the v4.5.1 binary deserialize identically under v5.1.1.
@thevar1able
thevar1able self-requested a review September 8, 2026 23:25
@thevar1able thevar1able self-assigned this Sep 8, 2026
@thevar1able thevar1able added the can be tested Allows running workflows for external contributors label Sep 8, 2026
@thevar1able
thevar1able marked this pull request as ready for review September 8, 2026 23:25
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [962d7b9]

Summary: ✅


AI Review

Summary

This PR bumps croaring from v4.5.1 to v5.1.1. Most of the upstream delta is additive and CI is green, but the bump also pulls in the upstream big-endian IO fix for Roaring64Map, which changes the serialized bytes on s390x. ClickHouse stores that exact encoding in AggregateFunction(groupBitmap, UInt64) states and DeleteBitmap VERSION_R64 bodies, so the upgrade is not format-preserving for the repository's documented experimental s390x target. I would not merge this without a ClickHouse-side compatibility plan.

Findings

❌ Blockers

  • [contrib/croaring:1] The submodule bump changes the Roaring64Map wire format on big-endian hosts, but ClickHouse persists that payload in both AggregateFunction(groupBitmap, UInt64) states (src/AggregateFunctions/AggregateFunctionGroupBitmapData.h:140-162) and DeleteBitmap VERSION_R64 bodies (src/Storages/MergeTree/UniqueKey/DeleteBitmap.cpp:314-416). A pre-upgrade s390x payload with map_size = 1 is written as host-order bytes 00 00 00 00 00 00 00 01; after this bump the new reader byte-swaps that field and mis-parses it as 0x0100000000000000, so old data becomes unreadable after upgrade and new data becomes unreadable after downgrade. This is a serialization compatibility break without any ClickHouse-side version bump or migration path.
    Suggested fix: preserve the legacy encoding for existing ClickHouse formats on big-endian, or add explicit versioned readers/writers for the affected Roaring64Map payloads before updating the submodule.
Final Verdict

Request changes. The croaring update needs a compatibility story for persisted 64-bit roaring data on s390x before it is safe to merge.

LLVM Coverage Report

Measured on commit 962d7b9.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +252 lines in 87 files (-192 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. labels Sep 8, 2026
Comment thread contrib/croaring
@@ -1 +1 @@
Subproject commit 025ae3f7add169bc820dcfd46fa9304f382ec40a
Subproject commit 342463b31b909737bd6295c69b2f8e0ed9497424

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This bump pulls in upstream commit 07c3d83 ("fixing support for big endian (IO)"), which changes the bytes produced and consumed by roaring::Roaring64Map::{write,read,readSafe} on big-endian hosts. ClickHouse persists that exact format in at least two places: AggregateFunction(groupBitmap, UInt64) states (src/AggregateFunctions/AggregateFunctionGroupBitmapData.h:140-162) and DeleteBitmap VERSION_R64 bodies (src/Storages/MergeTree/UniqueKey/DeleteBitmap.cpp:314-416).

The incompatibility is concrete: before this bump, an s390x bitmap with map_size = 1 serialized the outer count as host-order bytes 00 00 00 00 00 00 00 01; after the bump, the new reader applies croaring_letoh64 and interprets that same payload as 0x0100000000000000, so pre-upgrade data stops parsing. The reverse break exists on downgrade because the new writer emits little-endian bytes instead. Since the repository documents experimental s390x support, this is a real on-disk/state compatibility change, not just an upstream implementation detail.

Please keep the old encoding for existing ClickHouse formats on big-endian, or add an explicit versioned migration/read path for these Roaring64Map payloads before taking the submodule bump.

@clickhouse-gh clickhouse-gh Bot added the comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. label Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 962d7b928 with master 9c307529d (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

21 object files changed (+125.67 KiB total), 0 added.

Object file Master PR Δ
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupNumericI… 7.20 MiB 7.25 MiB +55.99 KiB (+0.76%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsNumericIndexedVector.cpp.o 33.69 MiB 33.72 MiB +29.16 KiB (+0.08%)
contrib/croaring-cmake/CMakeFiles/_roaring.dir/__/croaring/src/roaring64.c.o 85.37 KiB 102.75 KiB +17.38 KiB (+20.36%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@thevar1able
thevar1able added this pull request to the merge queue Sep 10, 2026
Merged via the queue into ClickHouse:master with commit 24e1ad3 Sep 10, 2026
174 checks passed
@thevar1able
thevar1able deleted the bump-croaring-v5.1.1 branch September 10, 2026 20:32
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 10, 2026
@subkanthi subkanthi mentioned this pull request Sep 16, 2026
11 of 17 tasks
@ahmadov ahmadov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 24, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 24, 2026
bbrown-oai pushed a commit to bbrown-oai/ClickHouse that referenced this pull request Sep 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
@nickitat

nickitat commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

@thevar1able it wasn't false alarm

Screenshot 2026-09-29 at 12 53 28

Also related to #115805

clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 21, 2026
When the bitmap argument of `bitmapContains` is constant, keep a
`roaring::BulkContext` across rows and call `containsBulk`. The context
caches the container found by the previous lookup, so values that share
the high 16 bits (sorted or clustered keys) skip the container search.

This recovers the regression from the `croaring` v4.5.1 -> v5.1.1 bump
(ClickHouse#118917). Upstream commit
RoaringBitmap/CRoaring@98509153 ("optimize bin search") replaced the
plain `binarySearch` used by `ra_get_index` with a block-based search
that is faster for random keys but about 2x slower for predictable ones,
which is what `bitmapContains` over ordered data produces. With the bulk
context the lookup is faster than before the bump: the `scalar` perf
query goes from 57 ms to 42 ms locally.

Related: ClickHouse#115805
Related: ClickHouse#118917

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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 comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-build Pull request with build/testing/packaging improvement pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants