Skip to content

Enable throttling of lookups for YTsaurus dictionaries - #100044

Merged
alexey-milovidov merged 58 commits into
ClickHouse:masterfrom
MikhailBurdukov:lookup_throttler
Oct 12, 2026
Merged

alexey-milovidov merged 58 commits into
ClickHouse:masterfrom
MikhailBurdukov:lookup_throttler

Conversation

@MikhailBurdukov

@MikhailBurdukov MikhailBurdukov commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Two options were added(lookup_throttler_max_requests_per_second and lookup_max_rows_per_query) in order to control the number of lookups queries to fetch data from ytsaurus

Changelog category (leave one):

  • Improvement

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

Enable throttling of lookups for YTsaurus dictionaries.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

Version info

  • Merged into: 26.10.1.2170-master (included in 26.10 and later)

@kssenii kssenii added the can be tested Allows running workflows for external contributors label Mar 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b9d1c6c]

Summary: ✅


AI Review

Summary

This PR adds dictionary-only YTsaurus lookup controls (lookup_throttler_max_requests_per_second, lookup_max_rows_per_query), moves throttling to the per-HTTP-attempt level so proxy failover also respects the request-rate contract, preserves the old unlimited default for lookup chunking, rejects lookup-only settings on the non-lookup YTsaurus surfaces, and adds focused regression coverage for the previously reported edge cases. After reviewing the current diff, the full prior discussion, the current code, and the latest all-green CI, I did not find any remaining correctness, performance, or contract issues that still hold in the updated branch.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit b9d1c6c.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 45/250 (18.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 19, 2026
Comment thread src/Core/YTsaurus/YTsaurusClient.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

@MikhailBurdukov, Looks all green. Please address the review comments or answer to them.

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b9d1c6c85 with master b94acbe31 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 37a251ffa; 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

9 object files changed (+72.51 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Sources/YTsaurusSource.cpp.o 148.79 KiB 195.75 KiB +46.96 KiB (+31.56%)

719 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

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

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse ProfileEvents::global_counters_storage 12.69 MiB 12.75 MiB +64.00 KiB (+0.49%)
programs/clickhouse-keeper ProfileEvents::global_counters_storage 12.69 MiB 12.75 MiB +64.00 KiB (+0.49%)

Job report

Criss-cross merge (two merge bases) produced ~300 spurious conflicts.
Resolved by taking `master` verbatim for every file the PR does not touch
and re-merging `YTsaurusSource.cpp` and the YTsaurus dictionary source doc
against the real base. The doc page is now autogenerated, so the two new
setting rows moved into the `Documentation` block of
`registerDictionarySourceYTsaurus` instead of the `.mdx`.
The two-merge-base merge silently removed the `contrib/NuRaft`,
`contrib/aws-c-http`, `contrib/chdig` and `contrib/llvm-project` gitlinks
without reporting a conflict. Restored them to the `master` revisions.

Also change the default of `lookup_max_rows_per_query` to `0`.
\`lookup_max_rows_per_query\` defaulted to \`1024\`, which silently changed the
behaviour of every existing dynamic cache dictionary: \`CacheDictionary\`
forwards the whole unique-miss set to \`loadIds\` / \`loadKeys\`, so a single
cache update turned into \`ceil(N / 1024)\` YTsaurus lookup requests on the hot
miss path without any opt-in.

The default is now \`0\` (unlimited): a selective load is sent as one request,
exactly as before this pull request, and chunking is opt-in. Added
\`test_yt_lookups_default_chunk_size_is_unlimited\`, which pins the default by
asserting that a four-key miss under a one-request-per-second throttler never
blocks - a chunked load would.

(The previous commit message mentions this change; it only restored the
submodule gitlinks.)
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Continued this PR: resolved the criss-cross merge conflict with master, addressed the blocking AI Review finding, and verified locally. Head is now 432e70785e61.

Resolved the CONFLICTING state. git merge-base --all origin/master HEAD returned two bases, so the ort virtual base produced ~300 conflicts although the pull request touches 18 files. Resolved mechanically: master verbatim for every file the pull request does not touch, and a re-merge against the real base (c260929910ea) for src/Processors/Sources/YTsaurusSource.cpp (clean) and the YTsaurus dictionary source documentation page. The merge also silently dropped four submodule gitlinks without reporting a conflict — contrib/NuRaft, contrib/aws-c-http, contrib/chdig and contrib/llvm-project — which is why the build could not even configure; they are restored to the master revisions in 0d9653e877bd. The final diff against master is byte-identical to the pull request's own change plus the two items below.

docs/reference/statements/create/dictionary/sources/ytsaurus.mdx is now autogenerated on master, so the two new setting rows moved out of the .mdx and into the Documentation block of registerDictionarySourceYTsaurus, which is the source of truth.

Addressed the AI Review ⚠️ Request changes finding (432e70785e61). lookup_max_rows_per_query defaulted to 1024, which was not an opt-in knob: CacheDictionary forwards the whole unique-miss set to loadIds / loadKeys, so every existing dynamic cache dictionary would have started issuing ceil(N / 1024) YTsaurus requests per cache update. The default is now 0 (unlimited) — one request per selective load, exactly the behaviour before this pull request — and chunking is opt-in. Added test_yt_lookups_default_chunk_size_is_unlimited, which pins the default by asserting that a four-key miss under lookup_throttler_max_requests_per_second = 1 never increments YTsaurusLookupThrottled (a chunked load would block at least three times, as test_yt_lookups_throttler shows).

Verified locally (aarch64, RelWithDebInfo, incremental): all seven YTsaurus translation units compile with no diagnostics, the full clickhouse binary and unit_tests_dbms link, unit_tests_dbms --gtest_filter='*YTsaurus*' passes 3/3, and both stateless tests pass against a scratch server built from this head (04357_ytsaurus_lookup_settings_table_engine_rejected, 04649_ytsaurus_empty_cypress_path_rejected).

CI re-runs on the new head. No other unresolved review threads.

Comment thread src/Core/YTsaurus/YTsaurusClient.cpp Resolved
@abashkeev abashkeev added the comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). label Sep 3, 2026
…proxy failover retries

`lookup_throttler_max_requests_per_second` is documented as a cap on
`lookup_rows` requests sent to YTsaurus, but the token was consumed once in
`YTsaurusClient::lookupRows`, before `executeQuery` iterated over
`http_proxy_urls`. When the first proxy failed, the fallback attempts against
the other proxies were sent without paying for them, so one logical selective
load could exceed the configured rate and `YTsaurusLookupThrottled` was
undercounted exactly in the degraded-proxy case.

`executeQuery` now takes an optional throttler and consumes a token right
before each real HTTP attempt inside the retry loop; `lookupRows` passes the
lookup throttler down. Other query kinds keep passing no throttler.

Adds `test_yt_lookups_throttler_proxy_failover` (dead proxy listed first,
1 request per second, one row per request) asserting that the load still
succeeds and that `YTsaurusLookupThrottled` grows.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Continued this PR: resolved the CONFLICTING state and addressed the AI Review ⚠️ Request changes finding. Head is now c55674c12619.

Merged master (d43beb84ac48). The history is criss-cross again (two merge bases), so the merge was done against the single recent base. The only real conflict was in src/Processors/Sources/YTsaurusSource.cpp: master (6009e90f628e) changed the two YTsaurus source constructors to pass sample_block_->cloneEmpty() to ISource so the header carries no rows, while this PR had split the dynamic-table source into ...Select and ...Lookup. Resolved by applying master's change to all three constructors in the PR's structure. Submodule gitlinks and the PR's file set were verified identical to the pre-merge delta.

Addressed the AI Review finding (c55674c12619, the only unresolved thread): the lookup throttler token was consumed once per lookupRows call, before executeQuery retried across http_proxy_urls, so a failover could send several lookup_rows requests for one token. The token is now consumed per actual HTTP attempt inside the retry loop. New integration test test_yt_lookups_throttler_proxy_failover.

Verified locally: all YTsaurus translation units and the gtest translation unit compile (RelWithDebInfo). The previous head 432e70785e61 was fully green (PR, Style check, Mergeable Check, CH Inc sync), so there were no CI failures to fix.

…uffer`

The declaration of `YTsaurusClient::createQueryRWBuffer` has a double space
after the first comma. It is pre-existing, but the `whitespace_check` style
check only reports such a line when neither neighbouring line looks like
column alignment at that position, and the `request_throttler` comment added
by this pull request removed that accidental exemption, so the check started
failing.

Also write the reference parameters as `const URI & uri` /
`const ReadWriteBufferFromHTTP::OutStreamCallback & out_callback`, matching
the surrounding code.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Fixed the only CI failure and refreshed the branch — new head 08f0e5a56d8b.

Style check (Failures: 1/15, which dropped the other 145 jobs) was the whitespace_check sub-check:

./src/Core/YTsaurus/YTsaurusClient.h:105    ReadBufferPtr createQueryRWBuffer(const URI& uri,  const ReadWriteBufferFromHTTP::OutStreamCallback& out_callback, const std::string & http_method);

The double space after the first comma is pre-existing (it is on master verbatim), but check_whitespaces suppresses such a line when a neighbouring line looks like column alignment at that same column — and the request_throttler comment added in c55674c12619 right below the declaration removed that accidental exemption, so the check started reporting it. Fixed the actual violation in 8c9bb0142228, and wrote the reference parameters as const URI & uri / const ReadWriteBufferFromHTTP::OutStreamCallback & out_callback to match the surrounding code. Verified locally: whitespace_check, cpp, various, ruff, clickhouse_spelling, functional_tests_check, embedded_doc_snippets and the rest all pass now (the only two local failures are environment artifacts — broken symlinks inside my build/ directory and the missing changed_files workflow-hook data).

Also merged current master (08f0e5a56d8b, conflict-free, 2372 commits of drift). Verified the merge did not change the scope — the diff against master is still exactly the same 17 files — and that no submodule gitlink was dropped (identical to master). Rebuilt all 6 YTsaurus translation units plus gtest_ytsaurus_dictionary_source.cpp against the merged tree: all compile. Note master added the contrib/sql-console submodule, which has to be initialised or cmake fails on the missing ch_contrib::sql_console_resources target.

The remaining review thread on YTsaurusClient.cpp is the per-attempt throttling one, already addressed in c55674c12619; the Code Review job never ran on that head because the style failure dropped it, so the AI verdict should refresh on this run.

alexey-milovidov and others added 2 commits September 16, 2026 19:37
…he pre-fix code

Both tests were flagged by the AI review as passing on the behaviour they claim to catch.

`test_yt_lookups_throttler_proxy_failover` used `lookup_max_rows_per_query = 1`, so three misses already made three
logical lookups and `YTsaurusLookupThrottled` grew with the old per-logical-lookup throttling too. A permanently dead
first proxy cannot exercise the per-attempt path at all: the node type `get` issued by `createPipe` before every
selective load already fails over and moves `recently_used_url_index` to the healthy proxy. The test now points the
first proxy at the ClickHouse HTTP port, configured by the new `fake_yt_proxy_http_handlers.xml` to answer
`/api/v3/get` with dynamic-table attributes and to reject `/api/v3/lookup_rows` with a non-retriable `404`. With
`lookup_max_rows_per_query = 0`, `use_lock = 0` and `check_table_schema = 0` the whole miss set is one logical lookup
whose first attempt fails instantly and is retried against the real proxy. The test asserts exactly two `lookup_rows`
attempts in `system.text_log` and exactly one blocked request, which only the retry attempt can have paid for.

`test_yt_lookups_default_chunk_size_is_unlimited` used four keys, which also fit into one request under the earlier
`1024` default. It now looks up 1100 keys and asserts exactly one `lookup_rows` attempt in `system.text_log` and no
blocked request; under a `1024` default the load would take two requests and the second would block.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Addressed both open AI Review findings and refreshed the branch. New head `e8509baa3da7`.

  • `test_yt_lookups_throttler_proxy_failover`: rewritten around a fake proxy served by the ClickHouse HTTP port (new `configs/fake_yt_proxy_http_handlers.xml`), because a dead proxy can never reach the lookup retry path: the node type `get` before each selective load already fails over. The fake answers `get` but rejects `lookup_rows` with a non-retriable `404`; one logical lookup (`lookup_max_rows_per_query = 0`) now shows exactly two `lookup_rows` attempts in `system.text_log` and exactly one throttled request, which fails on the old per-logical-lookup throttling.
  • `test_yt_lookups_default_chunk_size_is_unlimited`: 1100 keys instead of four, asserting exactly one `lookup_rows` attempt and no throttled request, so a `1024` default fails it.
  • Merged current `master` (conflict-free, submodule gitlinks identical, scope still the same PR files plus the new config). Recompiled the two YTsaurus translation units `master` touched since the last merge.

The fake proxy handler config was verified on a local server (`get` returns the JSON with 200, `lookup_rows` returns 404, regular queries unaffected). The integration test module itself is amd64-only and could not be run on this aarch64 machine, so CI is the first real run of the rewritten tests.

alexey-milovidov and others added 4 commits September 26, 2026 02:48
… in `SETTINGS`

`YTsaurusSettings::loadFromQuery` rejected `lookup_throttler_max_requests_per_second` and
`lookup_max_rows_per_query` only when `isChanged` was true, i.e. when the final value differed
from the default. Setting them to their default values on the `YTsaurus` table engine or the
`ytsaurus` table function was still silently accepted. Check the names in `settings_def.changes`
instead, and extend the test with default-valued forms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e fake proxy

`lookup_rows` is a heavy query, and `enable_heavy_proxy_redirection` is on by default, so before
the `lookup_rows` attempt the client requests `/hosts` from the fake proxy. The fake proxy answered
it with `404`, so the client failed over before logging the `lookup_rows` attempt, and the test saw
one attempt instead of two. The fake proxy now names itself in `/hosts`.

The leftover `//tmp/table` of the failed test also broke the next tests
(`test_yt_lookups_default_chunk_size_is_unlimited`, `test_yt_lookups_unlimited_chunk_size`).

Also split a line with two statements in `YTsaurusSourceFactory::createPipe`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=100044&sha=18b03fb805c127fef2ad880c1de281054cb604b6&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20targeted%29
ClickHouse#100044

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (no conflicts), fixed the CI failures and addressed the open review thread. New head b9d1c6c8559.

  • test_ytsaurus/test_dictionaries.py::test_yt_lookups_throttler_proxy_failover (failed in all three integration jobs): lookup_rows is a heavy query, and enable_heavy_proxy_redirection is on by default. So before the lookup_rows attempt the client asked the fake proxy for /hosts, got 404 and failed over without ever logging the lookup_rows attempt. The test therefore saw 1 attempt instead of 2. The server log confirmed it: Error while creating connection with http://localhost:8123 ... http://localhost:8123/hosts. HTTP status code: 404. The fake proxy (configs/fake_yt_proxy_http_handlers.xml) now answers /hosts with itself. test_yt_lookups_default_chunk_size_is_unlimited and test_yt_lookups_unlimited_chunk_size were only fallout: the failed test never removed //tmp/table, so their Node //tmp/table already exists errors came from that leftover.
  • Review (isChanged vs. presence): the lookup-only settings are now rejected whenever their names appear in the SETTINGS clause, including default values. The stateless test was extended to cover this.
  • Split a line in YTsaurusSourceFactory::createPipe that held two statements (...max_streams); else if ...).

Verified locally: the build passes and the stateless test passes with clickhouse local. I could not run the YTsaurus integration tests here because the ytsaurus-local image is amd64-only and this host is aarch64, so CI has to confirm that fix.

@alexey-milovidov alexey-milovidov self-assigned this Oct 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 12, 2026
Merged via the queue into ClickHouse:master with commit e6ad424 Oct 12, 2026
149 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
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-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements 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.

6 participants