Skip to content

S3 requests cancel issue and dependency on max_execution_time - #58314

Closed
yariks5s wants to merge 0 commit into
ClickHouse:masterfrom
yariks5s:s3_wrong_links_timeout_fix
Closed

yariks5s wants to merge 0 commit into
ClickHouse:masterfrom
yariks5s:s3_wrong_links_timeout_fix

Conversation

@yariks5s

@yariks5s yariks5s commented Dec 28, 2023 •

Copy link
Copy Markdown
Member

Closes #62371, Closes #59084

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 to CHANGELOG.md):

While executing queries like select * from s3('https://s3queue.clickhouse.com.amazonaws.com/data/*.json', 'JSONEachRow') limit 1, was encountered a delay in the retrial process, taking around 2 hours. This pull request tackles the issue, ensuring that queries undergo retries within the defined max_execution_time limit, preventing prolonged waiting periods. Also, there is not possible to cancel the query, problem description: #58479

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-improvement Pull request with some product improvements label Dec 28, 2023
@robot-ch-test-poll3

robot-ch-test-poll3 commented Dec 28, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 7ec911f with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process⏳ pending
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here❌ failure
Mergeable CheckChecks if all other necessary checks are successful❌ failure
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report❌ failure
Successful checks
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Docs checkBuilds and tests the documentation✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success

@yariks5s yariks5s changed the title S3 requests freezing fix and max_execution_time dependency S3 requests freezing fix and dependency on max_execution_time Dec 28, 2023
Comment thread src/IO/S3/Client.cpp Outdated
Comment on lines +71 to +88
if (execution_time > 0)
{
Int64 retries = 0;
while (true)
{
retries++;
uint64_t calculated_delay = calculateDelayOnRetries(retries, scaleFactor);
if (calculated_delay > maxDelayMs)
{
retries += execution_time / maxDelayMs;
break;
}
execution_time -= calculated_delay;
if (execution_time < 0)
break;
}
maxRetries = maxRetries < retries ? maxRetries : uint32_t(retries);
}

@KochetovNicolai KochetovNicolai Dec 29, 2023 •

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.

I think we can write a formula here, instead of writing the loop.
First, we can calculate how many steps is required to get maxDelayMs: maxDelayMs <= minDelayMs * (scaleFactor ^ steps) => steps = log_(scaleFactor)(maxDelayMs / minDelayMs) = ln(maxDelayMs / minDelayMs) / ln(scaleFactor) (or just log_2(maxDelayMs / minDelayMs) if scaleFactor = 2).

Then, we can get the time required to get to maxDelayMs, its t = minDelayMs * (1 - scaleFactor ^ steps) / (1 - scaleFactor).

If t > max_execution_time, then max_execution_time = minDelayMs * (1 - scaleFactor ^ maxRetries) / (1 - scaleFactor), so (max_execution_time / minDelayMs) * (1 - scaleFactor) = 1 - scaleFactor ^ maxRetries or maxRetries = ln(1 - (max_execution_time / minDelayMs) * (1 - scaleFactor)) / ln(scaleFactor).

In other case, maxRetries = steps + (max_execution_time - t) * maxDelayMs

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.

(but please validate this)

Comment thread src/IO/S3/Client.cpp Outdated
/// Calculating number of retries based on the `max_execution_time` and delays between retries
if (context != nullptr)
{
Int64 execution_time = context->getSettingsRef().max_execution_time.totalMilliseconds() / 2; /// Here we put total time/2 knowing that we will do retries

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.

Let's avoid using context here (end everywhere when possible). It's much better to pass max_execution_time as unit param.

@Avogar

Avogar commented Dec 29, 2023

Copy link
Copy Markdown
Member

BTW, in the logs during query select * from s3('https://s3queue.clickhouse.com.amazonaws.com/data/*.json', 'JSONEachRow') limit 1 I see: Not found address of host: s3queue.clickhouse.com.amazonaws.com. (DNS_ERROR). Should we actually retry this error?

@robot-ch-test-poll3 robot-ch-test-poll3 added pr-bugfix Pull request with bugfix, not backported by default and removed pr-improvement Pull request with some product improvements labels Dec 29, 2023
@CheSema

CheSema commented Jan 2, 2024 •

Copy link
Copy Markdown
Member

Do we create here one more limit settings for such scenario or do we reuse query execution limit?

Why do we bring limits of query execution to the RetryStrategy? Why do not cancel the query by time limit? When query is canceled the retries are supposed to stop. If that doesn't work, I think we should fix that firstly.

@yariks5s

yariks5s commented Jan 3, 2024

Copy link
Copy Markdown
Member Author

The idea is changed because we make a decision about doing a time limits in not appropriate place. Also, there is a problem regarding cancelling of queries that is also need to fix because we check if the query is cancelled only when we receive some sort of data from it and currently, queries can be retried for a long time. The best solution that was discussed is to make a global thread, which will make a decision that we need to cancel the query. It should contain "deadline scheduler", which will check statuses of the processes and then send signal if process should be cancelled.

@yariks5s

yariks5s commented Jan 3, 2024

Copy link
Copy Markdown
Member Author

Note: the commit above can only work as a temporary solution, the full problem is described here and should be solved in the better way.

@yariks5s yariks5s changed the title S3 requests freezing fix and dependency on max_execution_time S3 requests cancel issue and dependency on max_execution_time Jan 3, 2024
@CheSema CheSema self-assigned this Jan 4, 2024
@LGDHuaOPER

Copy link
Copy Markdown

What's the status ?

@yariks5s

Copy link
Copy Markdown
Member Author

@LGDHuaOPER currently working on it🙂

@LGDHuaOPER

Copy link
Copy Markdown

@LGDHuaOPER currently working on it🙂

That's great ! Thank you very much !

@yariks5s yariks5s added the do not test disable testing on pull request label May 6, 2024
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2024

Copy link
Copy Markdown
Contributor

Dear @KochetovNicolai, @CheSema, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@CheSema CheSema self-assigned this Jun 25, 2024
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2024

Copy link
Copy Markdown
Contributor

Dear @CheSema, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@yariks5s yariks5s closed this Sep 23, 2024
@yariks5s
yariks5s force-pushed the s3_wrong_links_timeout_fix branch from eca3a9b to d01c6c1 Compare September 23, 2024 18:25
@yariks5s yariks5s mentioned this pull request Sep 23, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

6 participants