Skip to content

Read only necessary columns & respect ttl_only_drop_parts on materialize ttl - #65488

Merged
CurtizJ merged 4 commits into
ClickHouse:masterfrom
zvonand:zvonand-ttl
Sep 23, 2024
Merged

CurtizJ merged 4 commits into
ClickHouse:masterfrom
zvonand:zvonand-ttl

Conversation

@zvonand

@zvonand zvonand commented Jun 20, 2024 •

Copy link
Copy Markdown
Contributor

Finish #59189. A step in direction of implementing #20451.

Respect ttl_only_drop_parts on materialize ttl. Only read the necessary columns to recalculate TTL and drop parts by replacing them with an empty one.

Changelog category (leave one):

  • Performance Improvement

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

Respect ttl_only_drop_parts on materialize ttl; only read necessary columns to recalculate TTL and drop parts by replacing them with an empty one.

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/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@jkartseva jkartseva added the can be tested Allows running workflows for external contributors label Jun 22, 2024
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-performance Pull request with some performance improvements label Jun 22, 2024
@robot-ch-test-poll1

robot-ch-test-poll1 commented Jun 22, 2024 •

Copy link
Copy Markdown
Contributor

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

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

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
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✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@zvonand

zvonand commented Jun 23, 2024

Copy link
Copy Markdown
Contributor Author

Fails:

@alexey-milovidov

Copy link
Copy Markdown
Member

@zvonand, waiting to fix all the flaky tests.

@zvonand

This comment was marked as outdated.

@zvonand

zvonand commented Jun 24, 2024 •

Copy link
Copy Markdown
Contributor Author

@zvonand, waiting to fix all the flaky tests.

If you mean 02125_many_mutations, then I took a closer look at it and I do not see a reason why the test itself shall be failing. Maybe this is caused by its nature: 20000 ALTERs is a huge number, e.g. these may interfere with something inside runner.

I cannot poke the CI from the inside, and, as soon as the flakiness is not related to this PR, I do not see why it is a stopper here. Also, this test has been failing from time to time ever since it was introduced in 2021, and has never been fixed.

@CurtizJ CurtizJ self-assigned this Jul 1, 2024

@CurtizJ CurtizJ left a comment •

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.

In general, I think this approach won't work. I'll think how it's possible to solve this task in the other way.

Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
Comment thread src/Storages/StorageInMemoryMetadata.h Resolved
@CurtizJ

CurtizJ commented Jul 2, 2024

Copy link
Copy Markdown
Member

Hmm, probably it will work. I'll check one more time more closely.

@zvonand

zvonand commented Jul 25, 2024

Copy link
Copy Markdown
Contributor Author

Hmm, probably it will work. I'll check one more time more closely.

@CurtizJ what is your opinion now, does it work? For me, it looks like it does :)

@zvonand

zvonand commented Aug 7, 2024

Copy link
Copy Markdown
Contributor Author

@CurtizJ so, what do you think of this now? (Also, the CI for this PR is really green)

It actually seems to work:

  1. Create table:
SET mutations_sync = 2;
CREATE TABLE test_ttl
(
    `ts` DateTime CODEC(Delta, LZ4),
    `huge_column1` String CODEC(NONE),
    `huge_column2` String CODEC(NONE),
    `huge_column3` String CODEC(NONE)
)
ENGINE = MergeTree
PARTITION BY toDate(ts)
ORDER BY tuple() AS
SELECT
    toDateTime('2020-01-01 00:00:00') + toIntervalMillisecond(number * 5) AS ts,
    randomPrintableASCII(100) AS huge_column1,
    randomPrintableASCII(120) AS huge_column2,
    randomPrintableASCII(130) AS huge_column3
FROM numbers(100000000);
  1. Alter it:
ALTER TABLE test_ttl
    MODIFY SETTING ttl_only_drop_parts = 1;
ALTER TABLE test_ttl
    MODIFY TTL ts + toIntervalDay(1439);

Difference in performance is dramatic (60 seconds in master vs 1 second in this PR)

@alexey-milovidov

Copy link
Copy Markdown
Member

@zvonand

zvonand commented Aug 11, 2024 •

Copy link
Copy Markdown
Contributor Author

Yes, I already seen it and thinking about it, even without 3 reminders in 3 unrelated PRs.
By the way, there is a standalone issue for this test failure: #65762, I have no rights to reopen it.
Also, this PR does not have any tests failed, and it is totally green.

@zvonand
zvonand requested a review from CurtizJ August 21, 2024 13:46
@zvonand

zvonand commented Aug 21, 2024

Copy link
Copy Markdown
Contributor Author

@CurtizJ gentle ping

@zvonand

zvonand commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov do you want me to look into it? I can, but, unfortunately, without promise of quick result.

I also see that other PRs are being reviewed and merged during the last couple of weeks, even though https://aretestsgreenyet.com/ has never been green. Maybe I can also have some in PRs that have been pending for months?

P.S. Btw, looks like the test's original author was @vitlibar, maybe he would know better

@zvonand

zvonand commented Aug 25, 2024

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov none of the tests failed, but looks this page is not supposed do be green at all, right? :)

image

@alexey-milovidov

Copy link
Copy Markdown
Member

It requires at least one million test runs. If it is less than one million it indicates that something is wrong with the CI or everyone is on vacation.

@zvonand

zvonand commented Aug 26, 2024

Copy link
Copy Markdown
Contributor Author

@zvonand, check this: https://s3.amazonaws.com/clickhouse-test-reports/0/0837a51313c5991e57265a5fd3556908bb6f4c2a/integration_tests__asan__old_analyzer__[6_6].html

I already fixed #66835, now I am also investigating on #68355 in free time (but looks like the test itself is not the only issue here), and I have a couple of other tests I plan to take a look at later if they are not fixed by then. I will put this on the list.

TBH I expected some reciprocity, i.e. someone would take a look at some of my not-so-huge PRs that have been waiting for review for months (e.g. this PR or #59138) when I contribute to better tests.
Don't get me wrong, but ghosted PRs are not a good motivation.

@CurtizJ CurtizJ left a comment

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.

Well, I agree that it works. Please fix the requested changes and I'll merge PR. Now your code doesn't remove any parts but works only like materialize_ttl_recalculate_only. Parts are actually removed by assigned TTL merge.

SET mutations_sync = 2

CREATE TABLE test_ttl
(
    `ts` DateTime CODEC(Delta, LZ4),
    `huge_column1` String CODEC(NONE),
    `huge_column2` String CODEC(NONE),
    `huge_column3` String CODEC(NONE)
)
ENGINE = MergeTree
PARTITION BY toDate(ts)
ORDER BY tuple()
AS SELECT
    toDateTime('2020-01-01 00:00:00') + toIntervalMillisecond(number * 5) AS ts,
    randomPrintableASCII(100) AS huge_column1,
    randomPrintableASCII(120) AS huge_column2,
    randomPrintableASCII(130) AS huge_column3
FROM numbers(10000000);

ALTER TABLE test_ttl MODIFY SETTING ttl_only_drop_parts = 1;

ALTER TABLE test_ttl MODIFY TTL ts + toIntervalDay(1439);

SYSTEM FLUSH LOGS;

SELECT
    name,
    event_type,
    merge_reason
FROM system.part_log
WHERE (`table` = 'test_ttl') AND (CAST(splitByChar('_', part_name)[4], 'Int64') > 0) AND (event_type IN ('MergeParts', 'MutatePart'))
ORDER BY event_time_microseconds ASC

Query id: ac76af54-75c4-4bce-95d3-920c5d6bcac9

   ┌─name───────────┬─event_type─┬─merge_reason─┐
1. │ 20200101_1_6_1 │ MergeParts │ RegularMerge │
   └────────────────┴────────────┴──────────────┘
   ┌─name────────────┬─event_type─┬─merge_reason─┐
2. │ 20200101_7_12_1 │ MergeParts │ RegularMerge │
   └─────────────────┴────────────┴──────────────┘
   ┌─name───────────────┬─event_type─┬─merge_reason───┐
3. │ 20200101_7_12_1_15 │ MutatePart │ NotAMerge      │
4. │ 20200101_1_6_1_15  │ MutatePart │ NotAMerge      │
5. │ 20200101_1_14_2_15 │ MergeParts │ TTLDeleteMerge │
   └────────────────────┴────────────┴────────────────┘

Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@zvonand

This comment was marked as outdated.

@CurtizJ
CurtizJ added this pull request to the merge queue Sep 23, 2024
Merged via the queue into ClickHouse:master with commit 2517e8a Sep 23, 2024
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2024
@zvonand
zvonand deleted the zvonand-ttl branch September 23, 2024 14:25
CurtizJ added a commit to CurtizJ/ClickHouse that referenced this pull request Nov 28, 2024
@CurtizJ

CurtizJ commented Nov 28, 2024 •

Copy link
Copy Markdown
Member

Unfortunately a bug has been found. Run test 02521_lightweight_delete_and_ttl.sql with the following table settings:

SETTINGS min_bytes_for_wide_part = 1000000000, index_granularity = 8192, index_granularity_bytes = '10Mi', ttl_only_drop_parts = 1

It results in:

Received exception from server (version 24.12.1):
Code: 341. DB::Exception: Received from localhost:9000. DB::Exception: Exception happened during execution of mutation 'mutation_4.txt' with part 'all_1_2_1_3' reason: 'Code: 10. DB::Exception: Not found column id: in block event_time DateTime UInt32(size = 0). (NOT_FOUND_COLUMN_IN_BLOCK) (version 24.12.1.1)'. This error maybe retryable or not. In case of unretryable error, mutation can be killed with KILL MUTATION query 

2024.11.28 16:52:47.480306 [ 749691 ] {} <Error> MergeTreeBackgroundExecutor: Exception while executing background task {80f2698b-d321-4774-aa9b-4f0af748af14::all_1_2_1_4}: Code: 10. DB::Exception: Not found column id: in block event_ti
me DateTime UInt32(size = 0). (NOT_FOUND_COLUMN_IN_BLOCK), Stack trace (when copying this message, always include the lines below):

0. ./contrib/llvm-project/libcxx/include/exception:141: Poco::Exception::Exception(String const&, int) @ 0x0000000014fc5f32
1. ./build_clang/./src/Common/Exception.cpp:109: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000bc052b9
2. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000006ac4f0c
3. DB::Exception::Exception<String const&>(int, FormatStringHelperImpl<std::type_identity<String const&>::type>, String const&) @ 0x0000000006adc66b
4. ./build_clang/./src/Interpreters/ActionsDAG.cpp:899: DB::ActionsDAG::evaluatePartialResult(std::unordered_map<DB::ActionsDAG::Node const*, DB::ColumnWithTypeAndName, std::hash<DB::ActionsDAG::Node const*>, std::equal_to<DB::ActionsDA
G::Node const*>, std::allocator<std::pair<DB::ActionsDAG::Node const* const, DB::ColumnWithTypeAndName>>>&, std::vector<DB::ActionsDAG::Node const*, std::allocator<DB::ActionsDAG::Node const*>> const&, unsigned long, bool) @ 0x000000001
0566adf
5. ./build_clang/./src/Interpreters/ActionsDAG.cpp:814: DB::ActionsDAG::updateHeader(DB::Block const&) const @ 0x0000000010564f10
6. ./build_clang/./src/Processors/Transforms/ExpressionTransform.cpp:10: DB::ExpressionTransform::ExpressionTransform(DB::Block const&, std::shared_ptr<DB::ExpressionActions>) @ 0x0000000012b39630
7. ./contrib/llvm-project/libcxx/include/__memory/construct_at.h:35: DB::MutateAllPartColumnsTask::prepare() @ 0x00000000124ae143
8. ./build_clang/./src/Storages/MergeTree/MutateTask.cpp:1372: DB::MutateAllPartColumnsTask::executeStep() @ 0x00000000124ab85e
9. ./build_clang/./src/Storages/MergeTree/MutateTask.cpp:1982: DB::ExecutableTaskDropTTLExpiredPartsDecorator::executeStep() @ 0x00000000124b0276
10. ./build_clang/./src/Storages/MergeTree/MutateTask.cpp:2092: DB::MutateTask::execute() @ 0x0000000012496bc2
11. ./build_clang/./src/Storages/MergeTree/MutatePlainMergeTreeTask.cpp:99: DB::MutatePlainMergeTreeTask::executeStep() @ 0x00000000125f80ba
12. ./build_clang/./src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:308: DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::routine(std::shared_ptr<DB::TaskRuntimeData>) @ 0x000000001226ab2f
13. ./build_clang/./src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:353: DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::threadFunction() @ 0x000000001226b1e6
14. ./contrib/llvm-project/libcxx/include/__functional/function.h:848: ? @ 0x000000000bcd568e
15. ./contrib/llvm-project/libcxx/include/__functional/invoke.h:359: ? @ 0x000000000bcda002
16. ./contrib/llvm-project/libcxx/include/__functional/function.h:848: ? @ 0x000000000bcd3183
17. ./contrib/llvm-project/libcxx/include/__functional/invoke.h:359: ? @ 0x000000000bcd845b
18. ? @ 0x00007ba47fa94ac3
19. ? @ 0x00007ba47fb26850
 (version 24.12.1.1)

I'll revert for now.

@zvonand

zvonand commented Nov 28, 2024

Copy link
Copy Markdown
Contributor Author

Unfortunately a bug has been found. Run test `` with the following table settings:

Which test?

@zvonand

zvonand commented Nov 28, 2024 •

Copy link
Copy Markdown
Contributor Author

@CurtizJ you did not specify the test name

@CurtizJ

CurtizJ commented Nov 28, 2024

Copy link
Copy Markdown
Member

Sorry, test 02521_lightweight_delete_and_ttl.sql.

@zvonand

zvonand commented Nov 29, 2024

Copy link
Copy Markdown
Contributor Author

Ok, I will take a look and reintroduce it

@zvonand

zvonand commented Nov 29, 2024

Copy link
Copy Markdown
Contributor Author

@CurtizJ could you please share the full log of the failed test run? I do not see this exact fail in ci db

github-merge-queue Bot pushed a commit that referenced this pull request Nov 30, 2024
Revert "Merge pull request #65488 from zvonand/zvonand-ttl"
robot-clickhouse added a commit that referenced this pull request Nov 30, 2024
robot-ch-test-poll2 added a commit that referenced this pull request Nov 30, 2024
Backport #72599 to 24.11: Revert "Merge pull request #65488 from zvonand/zvonand-ttl"
robot-clickhouse added a commit that referenced this pull request Dec 3, 2024
CurtizJ added a commit that referenced this pull request Dec 8, 2024
Backport #72599 to 24.10: Revert "Merge pull request #65488 from zvonand/zvonand-ttl"
zvonand added a commit to zvonand/ClickHouse that referenced this pull request Dec 15, 2024
github-merge-queue Bot pushed a commit that referenced this pull request Jan 28, 2025
Reintroduce respect `ttl_only_drop_parts` on `materialize ttl`, #65488
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-performance Pull request with some performance 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