Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounting of temporary data on the disk, pt1 #40893

Merged
merged 19 commits into from
Sep 30, 2022
Merged

Conversation

vdimir
Copy link
Member

@vdimir vdimir commented Sep 1, 2022

Changelog category (leave one):

  • New Feature

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

  • Support limiting of temporary data stored on disk using settings max_temporary_data_on_disk_size_for_user/max_temporary_data_on_disk_size_for_query .

Use new interface for:

  • Sorting
  • Aggregation
  • Partial Merge Join
  • Backups ???
  • Check other places where temporary files are used
  • Documentation for the new settings

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

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-feature Pull request with new product feature label Sep 1, 2022
@kssenii kssenii self-assigned this Sep 1, 2022
@vdimir vdimir changed the title Account temoray data on disk Accounting of temoray data on the disk Sep 1, 2022
@vdimir vdimir force-pushed the vdimir/track-tmp-disk branch 2 times, most recently from 9692119 to 0829dc4 Compare September 1, 2022 16:04
@kssenii kssenii changed the title Accounting of temoray data on the disk Accounting of temporary data on the disk Sep 1, 2022
@vdimir vdimir marked this pull request as ready for review September 15, 2022 10:20
@vdimir
Copy link
Member Author

vdimir commented Sep 15, 2022

@kssenii refactoring of partial merge join to use new interface is pretty tricky. Probably it's better to make it in several steps. Let's finish this PR with sorting and aggregation to have it in master, and I'll continue the rest of TODOs in separate PRs.

@vdimir vdimir changed the title Accounting of temporary data on the disk Accounting of temporary data on the disk, pt1 Sep 15, 2022


/*
* Used to account amount of temporary data written to dicsk.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Used to account amount of temporary data written to dicsk.
* Used to account amount of temporary data written to disk.

extern const int NOT_ENOUGH_SPACE;
}

void TemporaryDataOnDiskScope::deltaAlloc(int comp_delta, int uncomp_delta)
Copy link
Member

Choose a reason for hiding this comment

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

Probably compressed instead of comp would be more readable, takes a few seconds to understand what comp is.


void TemporaryDataOnDiskScope::deltaAlloc(int comp_delta, int uncomp_delta)
{
size_t current_consuption = stat.compressed_size.fetch_add(comp_delta) + comp_delta;
Copy link
Member

Choose a reason for hiding this comment

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

Why comp_delta is added twice? should it be just size_t current_consuption = stat.compressed_size.fetch_add(comp_delta)?

Comment on lines 28 to 32
if (parent)
parent->deltaAlloc(comp_delta, uncomp_delta);

if (comp_delta > 0 && limit && current_consuption > limit)
throw Exception("Memory limit exceeded", ErrorCodes::MEMORY_LIMIT_EXCEEDED);
Copy link
Member

Choose a reason for hiding this comment

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

should we catch exception from parent->deltaAlloc and restore just updated stat before rethrowing?

src/Interpreters/TemporaryDataOnDisk.cpp Outdated Show resolved Hide resolved
"Disk '{}' is not local and can't be used for temporary files", disk->getName());
}

shared->temp_data_on_disk = std::make_shared<TemporaryDataOnDiskScope>(volume, max_size);
Copy link
Member

Choose a reason for hiding this comment

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

what if shared->temp_data_on_disk was already set?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can be set only here in setTemporaryStorage and setTemporaryStorage is called once.

src/Interpreters/Context.h Outdated Show resolved Hide resolved
parent->deltaAlloc(comp_delta, uncomp_delta);

if (comp_delta > 0 && limit && current_consuption > limit)
throw Exception("Memory limit exceeded", ErrorCodes::MEMORY_LIMIT_EXCEEDED);
Copy link
Member

Choose a reason for hiding this comment

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

why exception is about memory limit if the data is stored on disk?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to ErrorCodes::TOO_MANY_ROWS_OR_BYTES

if (out_writer)
{
out_writer->finalize();
updateAlloc(0);
Copy link
Member

Choose a reason for hiding this comment

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

did not understand why zero update alloc updateAlloc(0) is needed, looks noop.

Copy link
Member Author

Choose a reason for hiding this comment

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

The finalize probably can flush some buffers, so amount of bytes can be changed. Argument is amount of rows and it's a bit inconsistent (doesn't take buffered data into account), so removed num rows at all.

src/Interpreters/TemporaryDataOnDisk.cpp Outdated Show resolved Hide resolved
@vdimir vdimir force-pushed the vdimir/track-tmp-disk branch 6 times, most recently from 7d526aa to e40e832 Compare September 27, 2022 08:03
@@ -107,6 +107,13 @@ class DiskDecorator : public IDisk
bool supportsChmod() const override { return delegate->supportsChmod(); }
void chmod(const String & path, mode_t mode) override { delegate->chmod(path, mode); }

const IDisk & getNestedDisk() const
Copy link
Member

Choose a reason for hiding this comment

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

maybe getNestedDiskOrThis()?

src/Processors/Transforms/AggregatingTransform.cpp Outdated Show resolved Hide resolved
src/Interpreters/Aggregator.h Outdated Show resolved Hide resolved
src/Disks/DiskDecorator.h Outdated Show resolved Hide resolved
src/Processors/Transforms/MergeSortingTransform.cpp Outdated Show resolved Hide resolved
@vdimir
Copy link
Member Author

vdimir commented Sep 30, 2022

CI failures:

Integration tests (release) [1/2] — fail: 1, passed: 1025, flaky: 0

test_disks_app_func - #41933

Integration tests (release) [2/2] — fail: 1, passed: 1139, flaky: 0

test_cluster_copier/test.py::test_copy_with_recovering - #30399

Stateless tests (aarch64) — fail: 1, passed: 4488, skipped: 19

02267_file_globs_schema_inference - known issue fixed in master

Stress test (debug) — Download script failed

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://github.com/ClickHouse/ClickHouse/releases/download/v22.9.3.18-stable/clickhouse-common-static_22.9.3.18_amd64.deb

Stress test (msan) — Sanitizer assert (in stderr.log)

#41548

Stress test (tsan) — Backward compatibility check: OOM killer (or signal 9) in clickhouse-server.log

@@ -399,6 +399,9 @@ static constexpr UInt64 operator""_GiB(unsigned long long value)
M(UInt64, max_network_bandwidth_for_user, 0, "The maximum speed of data exchange over the network in bytes per second for all concurrently running user queries. Zero means unlimited.", 0)\
M(UInt64, max_network_bandwidth_for_all_users, 0, "The maximum speed of data exchange over the network in bytes per second for all concurrently running queries. Zero means unlimited.", 0) \
\
M(UInt64, max_temp_data_on_disk_size_for_user, 0, "The maximum amount of data consumed by temporary files on disk in bytes for all concurrently running user queries. Zero means unlimited.", 0)\
Copy link
Member

Choose a reason for hiding this comment

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

temp -> temporary please.

Copy link
Member

@alexey-milovidov alexey-milovidov Oct 1, 2022

Choose a reason for hiding this comment

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

Need "temporary" instead of "temp" for the following reasons:

  1. We hate abbrs wholeheartedly.
  2. If you abbreviate "temporary", it is difficult to remember if it should be "temp" or "tmp" or "t".
  3. There are other settings with the full "temporary" word.
  4. The "temp" abbreviation can be confused with the words "tempo" and "temperature" and "Temple OS".

Copy link
Member Author

@vdimir vdimir Oct 1, 2022

Choose a reason for hiding this comment

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

@alexey-milovidov

Let's rename it before it is in release #41984

Also, I noticed that there's no setting for global. I'll add it. Where should it be configured? In config.xml, I suppose, not in settings? What section?

Copy link
Member

Choose a reason for hiding this comment

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

config.xml, similarly to max_memory_usage_for_server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature Pull request with new product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants