Skip to content

Update usearch to include the arena capacity limitation fix - #118828

Merged
scanhex12 merged 1 commit into
masterfrom
usearch-tape-allocator-arena-cap
Sep 8, 2026
Merged

scanhex12 merged 1 commit into
masterfrom
usearch-tape-allocator-arena-cap

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Version info

  • Merged into: 26.9.1.1012 (included in 26.9 and later)
  • Backported to: 26.8.3.80, 26.7.7.64, 26.6.5.90, 26.3.33.33

Bumps `contrib/usearch` from `1ae009a` to `6bd13d4`, the tip of the
`ClickHouse/v2.24.0` branch of the ClickHouse fork, which includes
ClickHouse/usearch#13.

That pull request fixes `memory_mapping_allocator_gt::allocate`
under-allocating an arena: when a single allocation exceeded the additive
allocation threshold, or when `ceil2` overflowed, the new arena could be
smaller than the requested block, so the returned pointer extended past the
mapping and the caller wrote into unmapped memory. The arena is now grown to
at least `head_size() + extended_bytes`, and requests too large to round up
without overflowing are rejected up front.

The range also picks up the external accessor API
(`allocate_vectors_lookup` and `set_vector_at_position`) and relaxes the
size/vector-count check on the legacy load path when `exclude_vectors` is
set. Both are additive and unused by ClickHouse for now.

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

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [04f93ad]

Summary: ✅


AI Review

Summary

This PR bumps contrib/usearch to pull in the arena-capacity fix plus a couple of earlier additive usearch changes. I found one blocker in the allocator patch: it hardens the new-arena sizing path, but it still leaves the preceding space-availability check overflow-prone, so a second oversized allocation can still return a pointer into an already-too-small mapping.

Findings

❌ Blockers

  • [contrib/usearch:1] The vendored memory_mapping_allocator_gt::allocate change in include/usearch/index_plugins.hpp still adds last_usage_ + extended_bytes before deciding whether a new arena is needed. After an initial oversized allocation, the next near-SIZE_MAX request wraps that sum below last_capacity_, skips the reallocation branch, and returns a pointer inside the current mapping even though the block does not fit. That means the PR's advertised fix still allows out-of-mapping writes for repeated oversized allocations.
    Suggested fix: compare against remaining capacity without a wrapping add, e.g. extended_bytes > last_capacity_ - last_usage_, or use an explicit overflow check such as std::add_overflow.
Final Verdict

❌ Changes required. The allocator fix is incomplete and still leaves a reproducible overflow path for repeated oversized allocations.

LLVM Coverage Report

Measured on commit 04f93ad.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

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

Newly covered: +261 lines in 61 files (-238 lines lost coverage) · Details

Full report

@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 Sep 8, 2026
@serxa serxa self-assigned this Sep 8, 2026
@scanhex12
scanhex12 enabled auto-merge September 8, 2026 16:29
Comment thread contrib/usearch
@@ -1 +1 @@
Subproject commit 1ae009a6aa573629c8871ddb97dd6e1a9c03dd5f
Subproject commit 6bd13d4c69a1baef1f668e652c3ca26028970f12

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.

include/usearch/index_plugins.hpp:989-1020 still has a wrapping-space check. The new max_count_bytes guard only proves that head_size() + extended_bytes fits if we go down the "allocate a new arena" path, but before that we still evaluate last_usage_ + extended_bytes >= last_capacity_. Once an arena already exists, a near-max_count_bytes request can make that addition wrap, the condition becomes false, and we return a pointer inside the current mapping even though the block does not fit.

On a 64-bit build with alignment_ak = 8, count_bytes = SIZE_MAX - 4120 gives extended_bytes = 18446744073709547496. After one such allocation, the next allocation wraps last_usage_ + extended_bytes down to 18446744073709543392, which is smaller than last_capacity_, so the allocator skips the reallocation branch and the caller can still write past the mapping. Please compute the needed space without a wrapping add, for example by checking extended_bytes > last_capacity_ - last_usage_ (after maintaining last_usage_ <= last_capacity_) or by using an explicit overflow check.

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

clickhouse-gh Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 04f93ad58 with master 1dd29f835 (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.

Compile time of recompiled translation units

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

Job report

@scanhex12
scanhex12 added this pull request to the merge queue Sep 8, 2026
Merged via the queue into master with commit 5220da5 Sep 8, 2026
174 checks passed
@scanhex12
scanhex12 deleted the usearch-tape-allocator-arena-cap branch September 8, 2026 23:55
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 9, 2026
@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 9, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 9, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 9, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 9, 2026
Backport #118828 to 26.7: Update usearch to include the arena capacity limitation fix
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 9, 2026
Backport #118828 to 26.6: Update usearch to include the arena capacity limitation fix
PedroTadim added a commit that referenced this pull request Sep 10, 2026
Backport #118828 to 26.3: Update usearch to include the arena capacity limitation fix
PedroTadim added a commit that referenced this pull request Sep 10, 2026
Backport #118828 to 26.8: Update usearch to include the arena capacity limitation fix
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 17, 2026
…nt reads

Bump contrib/mariadb-connector-c to pick up a single connector change:
ERR_clear_error() before every SSL_connect/SSL_read/SSL_write whose result is
interpreted through SSL_get_error(), plus capturing errno as the first
statement of ma_tls_set_error().

SSL_get_error() only reports the retry flags of the operation just attempted
while the calling thread's OpenSSL error queue is empty, and openssl.c never
cleared it. A leftover ERR_LIB_SYS entry from any earlier OpenSSL operation on
the same thread is therefore reported first (ossl_ssl_get_error() returns
SSL_ERROR_SYSCALL for ERR_LIB_SYS before it looks at SSL_want_read() and the
BIO retry flag), so a read that OpenSSL had already marked retryable becomes
fatal. ma_tls_set_error() then pops the stale entry, gets NULL from
ERR_reason_error_string() and prints strerror_r(errno) instead, producing

  mysqlxx::BadQuery: TLS/SSL error: Interrupted system call (4)

on a healthy connection, with an errno that need not belong to the failing
call. Every mysql() table function, MySQL table/database engine and MySQL
dictionary read is affected: mysqlxx::Connection::connect enables TLS
unconditionally via mysql_ssl_set, the sampling query profiler is on by
default so query threads take periodic signals, and the TLS path bypasses
ma_recv()'s EINTR retry loop because OPENSSL_USE_BIOMETHOD is undefined and
SSL_set_fd() lets OpenSSL read the socket directly.

No regression test ships with this. With an empty error queue the message is
unreachable on the old pin: sock_read() zeroes errno before every recv, EINTR is
classified retryable, and pvio_socket_wait_io_or_timeout() re-polls it against
its deadline and reports ETIMEDOUT. 428000 instrumented un-injected reads
produced none, and no SQL-reachable producer of a stale ERR_LIB_SYS entry was
found, so the failing arm of a functional test would be unobservable. The fix
was validated by forcing a stale entry on the reading thread instead: 20 of 20
reads and 2-3 of 20 02479_mysql_connect_to_self runs failed before it, 20 of 20
and 50 of 50 passed after, and 125319 stale entries were still measured at SSL
entry on the green arm, so that arm is not vacuous.

The changelog category is the one the fix-carrying contrib bumps use (usearch
ClickHouse#118828, openssl ClickHouse#118927) rather than Bug Fix: the change in this repository is
only the dependency pin, and the Bug Fix category's validation expects a
regression test that reddens on master, which this defect cannot supply.

Related: ClickHouse#105987
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 17, 2026
…nt reads

Bump contrib/mariadb-connector-c to pick up a single connector change:
ERR_clear_error() before every SSL_connect/SSL_read/SSL_write whose result is
interpreted through SSL_get_error(), plus capturing errno as the first
statement of ma_tls_set_error().

SSL_get_error() only reports the retry flags of the operation just attempted
while the calling thread's OpenSSL error queue is empty, and openssl.c never
cleared it. A leftover ERR_LIB_SYS entry from any earlier OpenSSL operation on
the same thread is therefore reported first (ossl_ssl_get_error() returns
SSL_ERROR_SYSCALL for ERR_LIB_SYS before it looks at SSL_want_read() and the
BIO retry flag), so a read that OpenSSL had already marked retryable becomes
fatal. ma_tls_set_error() then pops the stale entry, gets NULL from
ERR_reason_error_string() and prints strerror_r(errno) instead, producing

  mysqlxx::BadQuery: TLS/SSL error: Interrupted system call (4)

on a healthy connection, with an errno that need not belong to the failing
call. Every mysql() table function, MySQL table/database engine and MySQL
dictionary read is affected: mysqlxx::Connection::connect enables TLS
unconditionally via mysql_ssl_set, the sampling query profiler is on by
default so query threads take periodic signals, and the TLS path bypasses
ma_recv()'s EINTR retry loop because OPENSSL_USE_BIOMETHOD is undefined and
SSL_set_fd() lets OpenSSL read the socket directly.

No regression test ships with this. With an empty error queue the message is
unreachable on the old pin: sock_read() zeroes errno before every recv, EINTR is
classified retryable, and pvio_socket_wait_io_or_timeout() re-polls it against
its deadline and reports ETIMEDOUT. 428000 instrumented un-injected reads
produced none, and no SQL-reachable producer of a stale ERR_LIB_SYS entry was
found, so the failing arm of a functional test would be unobservable. The fix
was validated by forcing a stale entry on the reading thread instead: 20 of 20
reads and 2-3 of 20 02479_mysql_connect_to_self runs failed before it, 20 of 20
and 50 of 50 passed after, and 125319 stale entries were still measured at SSL
entry on the green arm, so that arm is not vacuous.

The changelog category is the one the fix-carrying contrib bumps use (usearch
ClickHouse#118828, openssl ClickHouse#118927) rather than Bug Fix: the change in this repository is
only the dependency pin, and the Bug Fix category's validation expects a
regression test that reddens on master, which this defect cannot supply.

Connector change: ClickHouse/mariadb-connector-c#25
Related: ClickHouse#105987
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

5 participants