Repository navigation
Improve canceling queries with url() function - #102801
Conversation
|
@vdimir could you please assign |
|
Workflow [PR], commit [20b3344] Summary: ✅ AI ReviewSummaryThis PR improves cancellation checks for Findings
Tests
ClickHouse Rules
Final Verdict
|
|
@murphy-4o I see all tests were successfully passed (failed tests are not related). Is there anything else should I do in this PR? |
|
@murphy-4o, @vdimir could you please review this PR? |
| @@ -386,8 +386,17 @@ StorageURLSource::StorageURLSource( | |||
| while (getContext()->getSettingsRef()[Setting::engine_url_skip_empty_files] && uri_and_buf.second->eof()); | |||
There was a problem hiding this comment.
When engine_url_skip_empty_files=1, the while (... && uri_and_buf.second->eof()) loop can trigger retried HTTP requests before setCancellationCheck is installed. In that case, KILL QUERY still cannot interrupt retries during this phase.
Please install the cancellation callback immediately after getFirstAvailableURIAndReadBuffer returns (before the eof() loop), so retries in the empty-file-skip path are also cancellable.
|
|
||
| if (auto * http_buf = dynamic_cast<ReadWriteBufferFromHTTP *>(uri_and_buf.second.get())) | ||
| { | ||
| http_buf->setCancellationCheck([this]() { return isCancelled(); }); |
There was a problem hiding this comment.
setCancellationCheck is still attached only after getFirstAvailableURIAndReadBuffer returns, but getFirstAvailableURIAndReadBuffer itself can execute retried HTTP work before that callback is installed:
- inside
StorageURLSource::getFirstAvailableURIAndReadBuffer,res->eof()is called whenengine_url_skip_empty_files=1and there are multiple URI options; eof()can triggerReadWriteBufferFromHTTP::nextImpl→doWithRetries.
So cancellation can still be delayed until after those retries finish.
Could we pass a cancellation checker into getFirstAvailableURIAndReadBuffer and install it on res immediately after create, before any eof/retrying calls?
LLVM Coverage Report
Changed lines: 100.00% (33/33) | lost baseline coverage: 1 line(s) · Uncovered code |
|
@murphy-4o could you remove PR from the merge queue? Because I am going to push refactored test in few minutes and we need to see the CI results again. |
Apologies for missing your message earlier. Please submit a new PR for the refactor. |
@murphy-4o I created follow-up PR #104014 with refactoring. Please set |
|
This has introduced flakiness in the CI and |
@Algunenano the follow up PR #104014 could fix the flakyness. I see you have reverted it too. Could you remind the link to see the flaky tests in ClickHouse? |
|
I reverted both because I could not revert just the old one. You can check the CI db with something like this |
|
|
@Algunenano it's clear why you reverted both PRs. But please read: |
|
Yes, I never said the new tests were flaky. I even said explicitly that |
|
I see in CI new test Now I will try to see what is with |
|
@Algunenano @murphy-4o void ReadWriteBufferFromHTTP::doWithRetries(std::function<void()> && callable,
std::function<void()> on_retry,
bool mute_logging, CheckCancelled check_cancelled) const
{
[[maybe_unused]] auto milliseconds_to_wait = read_settings.http_retry_initial_backoff_ms;
bool is_retriable = true;
std::exception_ptr exception = nullptr;
for (size_t attempt = 1; attempt <= read_settings.http_max_tries; ++attempt)
{
if (check_cancelled && check_cancelled())
{
throw Exception(ErrorCodes::QUERY_WAS_CANCELLED, "Query was cancelled during HTTP request");
}
It's placed at the beginning of the loop and it influences the propagation of CANNOT_PARSE_INPUT_ASSERTION_FAILED which So it's correct to revert my two PRs. I will create new PR to put the cancellation check in the right place and I will carefully check |
|
Hopefully I was able to reproduce it by running: python3 -m ci.praktika run "Stateless tests (amd_debug, flaky check)" --test 02270_errors_in_files_s3 on my local machine. So it will fix it and create new PR. |
|
I have fixed the cancellation callback in #104089 now test |
Apply the edit-changelog skill workflow to the autogenerated 26.5 section: add the release header, drop the NO CL ENTRY and NOT FOR CHANGELOG / INSIGNIFICANT sections, rescue user-visible entries into Bug Fix, Performance Improvement and Improvement, reconcile reverted PRs against the rest of the changelog (drop entries for ClickHouse#102801, ClickHouse#103547, ClickHouse#103858, ClickHouse#104800), record the isPrime / isProbablePrime revert-of-revert and follow-up PRs on the original entry, prune Build/Testing to user-affecting items, and apply a focused round of per-entry rewrites (proper-noun capitalization, backticked identifiers, common typos). Date, presentation URL and video URL in the release header are left as FIXME placeholders.
Check query cancellation between HTTP retry attempts, so that `KILL QUERY` and client disconnects stop a query over the `url` table function instead of waiting until all the retries are exhausted. `ReadWriteBufferFromHTTP` accepts an optional cancellation callback and, from the second attempt on, leaves `doWithRetries` by `break` instead of throwing, so the original HTTP error is still reported on the first attempt. `StorageURLSource` passes `isCancelled` down to the buffer and checks for cancellation after every step of its lazy initialization that can issue an HTTP request. This is a resubmission of ClickHouse#104089 by Roman Vasin (@rvasin) into the main repository, so that we can continue to work on it. That pull request in turn fixes the reverted ClickHouse#102801 and ClickHouse#104014. Differences from the original pull request: a comment in `ReadWriteBufferFromHTTP::initialize` that a bad merge had garbled is restored, the condition of the `chassert` in `readBigAt` is parenthesized, and the test is renumbered to `04615` because `04078` is taken on `master`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve canceling queries with url() function by checking query cancellation between HTTP retry attempts.
Related #97459
Version info
26.5.1.262