Skip to content

Conversation

@JiaQiTang98
Copy link
Contributor

@JiaQiTang98 JiaQiTang98 commented Sep 16, 2025

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

@clickhouse-gh
Copy link

clickhouse-gh bot commented Sep 16, 2025

Workflow [PR], commit [477858c]

Summary:

@JiaQiTang98 JiaQiTang98 added the can be tested Allows running workflows for external contributors label Sep 16, 2025
@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 16, 2025
@JiaQiTang98 JiaQiTang98 added bug Confirmed user-visible misbehaviour in official release pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 18, 2025
@JiaQiTang98 JiaQiTang98 requested a review from vdimir September 18, 2025 00:23
@vdimir vdimir self-assigned this Sep 19, 2025
@vdimir vdimir removed the pr-backport Changes, backported to release branch. Do not use manually - automated use only! label Sep 19, 2025
Copy link
Member

@vdimir vdimir left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, it's really a great catch! So basically, max_temporary_data_on_disk_size was not properly tested and barely usable. Have you checked by the chance if the metrics were correct before and are now fixed by this change?

@@ -0,0 +1,35 @@
<clickhouse>
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it would be better to add this test case to the integration test suite at https://github.com/ClickHouse/ClickHouse/tree/master/tests/integration/test_temporary_data rather than as a stateless test that runs a separate server. However, this is fine for now - we can refactor it in a separate PR if we decide it's necessary.

void freeAlloc();

TemporaryDataOnDiskScope * parent;
std::shared_ptr<TemporaryDataOnDiskScope> parent;
Copy link
Member

Choose a reason for hiding this comment

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

Are there cases where TemporaryDataBuffer's lifetime is greater than TemporaryDataOnDiskScope? I assume the initial intent was to keep the buffer's lifetime shorter than the scope lifetime, so I'm asking just to better understanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For MergeSortingTransform, its TemporaryDataOnDiskScope is created here.

tmp_data_on_disk = data->childScope(CurrentMetrics::TemporaryFilesForSort);

And In MergeSortingTransform, we create tmp_stream use raw pointer of tmp_data

TemporaryBlockStreamHolder tmp_stream(shared_header_without_constants, tmp_data.get(), reserve_size);

Subsequently, we use tmp_stream to create BufferingToFileSink. This BufferingToFileSink is destroyed in SortingTransform at a point later than the destruction of MergeSortingTransform, which causes the lifetime of TemporaryDataBuffer to exceed that of TemporaryDataOnDiskScope

auto sink = std::make_shared<BufferingToFileSink>(shared_header_without_constants, std::move(tmp_stream), log);

And I also encountered a Fatal error here with raw pointer

@vdimir vdimir added pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed bug Confirmed user-visible misbehaviour in official release labels Sep 19, 2025
@JiaQiTang98
Copy link
Contributor Author

Thanks for the fix, it's really a great catch! So basically, max_temporary_data_on_disk_size was not properly tested and barely usable. Have you checked by the chance if the metrics were correct before and are now fixed by this change?

Yeah, I have checked the metrics were correct after the fix

@alexey-milovidov
Copy link
Member

@vdimir vdimir added this pull request to the merge queue Sep 22, 2025
@vdimir
Copy link
Member

vdimir commented Sep 22, 2025

@vdimir, can we use MemoryTracker for this purpose?

clickhouse-inc.slack.com/archives/C02F2LML5UG/p1737064859711219?thread_ts=1737058291.049439&cid=C02F2LML5UG

@alexey-milovidov I initially tried using MemoryTracker, but found that class specifically designed for RAM accounting and more complex than what we need here. So, we decided to implement separate counters for external memory instead. We could revisit this approach, though I'm not sure if it would be worth it.

Merged via the queue into ClickHouse:master with commit 0225be9 Sep 22, 2025
123 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2025
robot-ch-test-poll4 added a commit that referenced this pull request Sep 22, 2025
Cherry pick #87140 to 25.9: fix: fix server level max temporary size limit
robot-ch-test-poll2 added a commit that referenced this pull request Sep 22, 2025
Cherry pick #87140 to 25.7: fix: fix server level max temporary size limit
robot-ch-test-poll2 added a commit that referenced this pull request Sep 22, 2025
Cherry pick #87140 to 25.8: fix: fix server level max temporary size limit
clickhouse-gh bot added a commit that referenced this pull request Sep 22, 2025
Backport #87140 to 25.9: fix: fix server level max temporary size limit
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 22, 2025
@JiaQiTang98 JiaQiTang98 added v25.4-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Sep 22, 2025
clickhouse-gh bot added a commit that referenced this pull request Sep 22, 2025
Backport #87140 to 25.7: fix: fix server level max temporary size limit
clickhouse-gh bot added a commit that referenced this pull request Sep 22, 2025
Backport #87140 to 25.8: fix: fix server level max temporary size limit
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 22, 2025
azat added a commit that referenced this pull request Sep 23, 2025
…25.9/87449

* u/backport/25.9/87449:
  Backport #87426 to 25.9: Ignore only not found errors for s3_plain_rewritable (and some other S3 code)
  Backport #87231 to 25.9: Fix "Too large size passed to allocator" UB in JOIN due to mixed const and non-const blocks
  Backport #87198 to 25.9: Disable the setting by default
  Backport #87392 to 25.9: Fix EmbeddedRocksDB upgrade
  Backport #87140 to 25.9: fix: fix server level max temporary size limit
  Backport #87178 to 25.9: PR: fix LEFT/INNER ... RIGHT ... JOINS chain
  Update autogenerated version to 25.10.1.1 and contributors
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 25, 2025
robot-clickhouse-ci-1 added a commit that referenced this pull request Sep 25, 2025
Cherry pick #87140 to 25.3: fix: fix server level max temporary size limit
robot-clickhouse-ci-1 added a commit that referenced this pull request Sep 25, 2025
Cherry pick #87140 to 25.6: fix: fix server level max temporary size limit
@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 25, 2025
clickhouse-gh bot added a commit that referenced this pull request Sep 25, 2025
Backport #87140 to 25.6: fix: fix server level max temporary size limit
vdimir added a commit that referenced this pull request Oct 1, 2025
Backport #87140 to 25.3: fix: fix server level max temporary size limit
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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud pr-bugfix Pull request with bugfix, not backported by default 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The statistic value of temporary data size always increases

7 participants