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

Consider lightweight deleted rows when selecting parts to merge #58223

Merged
merged 5 commits into from Mar 15, 2024

Conversation

jewelzqiu
Copy link
Contributor

@jewelzqiu jewelzqiu commented Dec 26, 2023

resolves #56728

Changelog category (leave one):

  • Improvement

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

Consider lightweight deleted rows when selecting parts to merge

@tavplubix tavplubix added the can be tested Allows running workflows for external contributors label Jan 3, 2024
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-improvement Pull request with some product improvements label Jan 3, 2024
@robot-clickhouse-ci-1
Copy link
Contributor

robot-clickhouse-ci-1 commented Jan 3, 2024

This is an automated comment for commit be4554b 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
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❌ failure
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
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ 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
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
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✅ 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. Integrational 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
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ 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
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

@jewelzqiu
Copy link
Contributor Author

jewelzqiu commented Jan 5, 2024

@yakov-olkhovskiy failed integration test looks unrelated to the PR

Copy link
Member

@yakov-olkhovskiy yakov-olkhovskiy left a comment

Choose a reason for hiding this comment

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

I think we shouldn't calculate existing_rows_count on mutate, but rather on delete itself and then update on merge along with raws_count

src/Storages/MergeTree/MutateTask.cpp Outdated Show resolved Hide resolved
@jewelzqiu
Copy link
Contributor Author

I think we shouldn't calculate existing_rows_count on mutate, but rather on delete itself and then update on merge along with raws_count

@yakov-olkhovskiy I don't understand the delete and merge, but I guess you are suggesting the following approach?

Calculating existing count while writing _row_exists column for the new part

also @davenger do you have any comment on this?

@yakov-olkhovskiy
Copy link
Member

yes, I meant calculate on DELETE FROM and update as needed on merge

@jewelzqiu
Copy link
Contributor Author

yes, I meant calculate on DELETE FROM and update as needed on merge

@yakov-olkhovskiy lightweight deleted rows will be physically deleted during merge, so we only need to calculate existing count during mutation on _row_exists column. I will try to implement this.

@tavplubix
Copy link
Member

Please consider extending count.txt instead of adding another file (but it's just a suggestion)

@jewelzqiu
Copy link
Contributor Author

Please consider extending count.txt instead of adding another file (but it's just a suggestion)

@tavplubix It is ok to do that for new parts, but I think we should not change the count.txt content of existing parts?
If existing parts cannot be handled, then the original issue still remains...

@tavplubix
Copy link
Member

we should not change the count.txt content of existing parts?

Yes, but we also cannot add another file to an existing part without running a mutation. And it both cases we should take compatibility into account

@yakov-olkhovskiy
Copy link
Member

yakov-olkhovskiy commented Jan 10, 2024

@jewelzqiu DELETE FROM is a special case of ALTER ... UPDATE mutation:
https://github.com/ClickHouse/ClickHouse/blob/master/src/Interpreters/InterpreterDeleteQuery.cpp#L88
I think most straightforward way is to add existing_rows_count during this mutation, but whenever this counter is used treat it as optional - i.e. if it isn't present - continue as it was before, if it is present - use it - this way it will be backward compatible. As alternative if this counter is not present - calculate it on the fly (as it was done in previous attempt) - but I'm not sure it's a good solution though - it will add (temporary, for old parts) overhead we want to avoid...

@jewelzqiu
Copy link
Contributor Author

Let me summarize current options (add drawbacks):

For existing parts:

  1. calculate on part loading (leads to longer starting time)
  2. lazy calculation when accessed (leads to slower background processing)

For new parts:

  1. extends count.txt (differs from public knowledge about count.txt)
  2. add existing_count.txt (adds new file to data part)

Personally I prefer calculating on loading for existing parts, because:

  1. starting time is less important
  2. no need to lock the calculation

As for the new parts I can live with either option, maybe extending count.txt is slightly better logically

@yakov-olkhovskiy @tavplubix what are your thoughts?

@yakov-olkhovskiy
Copy link
Member

for existing parts there is another option - left as it is
@tavplubix ?

@tavplubix
Copy link
Member

for existing parts there is another option - left as it is

Yes, we can just leave old parts as they are. Eventually, they will be merged and the existing rows count will be added

@tavplubix
Copy link
Member

tavplubix commented Jan 11, 2024

we should not change the count.txt content of existing parts?

Yes, but we also cannot add another file to an existing part without running a mutation. And it both cases we should take compatibility into account

Just in case, let me clarify what is the most complex part about compatibility:

Imagine you have a cluster of multiple replicas, and you do rolling upgrade, upgrading them one by one (the usual scenario). You have upgraded one replica. It gets new INSERT and DELETE queries and execute meres and mutations. It writes a part with a new existing_count.txt file or count.txt in the new format. Parts are being replicated to other replicas (with old version), but other replicas do not expect that. Also, it's impossible to downgrade if something went wrong during upgrading.

Possible (the simplest) solution: add a setting to enable/disable the new format

@yakov-olkhovskiy
Copy link
Member

@tavplubix let's say we have new part with existing_count.txt replicated to old version - wouldn't it just be ignored? or we count it as an error if unknown file is present?

@tavplubix
Copy link
Member

let's say we have new part with existing_count.txt replicated to old version - wouldn't it just be ignored?

I'm not sure, need to check

@jewelzqiu
Copy link
Contributor Author

jewelzqiu commented Jan 12, 2024

for existing parts there is another option - left as it is

If so, it doesn't help resolving the original issue: existing large parts with lightweight deleted rows cannot be merged

As for ability to downgrade to older version, I think both adding existing_rows_count.txt and changing count.txt will cause error

To minimize the impact on existing architecture, we could implement this way:

  1. for existing parts, calculate on parts loading
  2. during _row_exists related mutation, calculate while writing new parts
  3. for other mutations, copy existing_rows_count from source part
  4. for merged or inserted part, existing_rows_count equals rows_count

No files will be add or changed

@yakov-olkhovskiy @tavplubix

@lqhl
Copy link

lqhl commented Jan 17, 2024

for existing parts there is another option - left as it is

If so, it doesn't help resolving the original issue: existing large parts with lightweight deleted rows cannot be merged

As for ability to downgrade to older version, I think both adding existing_rows_count.txt and changing count.txt will cause error

To minimize the impact on existing architecture, we could implement this way:

1. for existing parts, calculate on parts loading

2. during `_row_exists` related mutation, calculate while writing new parts

3. for other mutations, copy `existing_rows_count` from source part

4. for merged or inserted part, `existing_rows_count` equals `rows_count`

No files will be add or changed

@yakov-olkhovskiy @tavplubix

hi @yakov-olkhovskiy @tavplubix , can we proceed with this design? it won't change or add any files in data parts.

@yakov-olkhovskiy
Copy link
Member

If so, it doesn't help resolving the original issue: existing large parts with lightweight deleted rows cannot be merged

the idea was that we gradually get rid of old parts without existing_rows_count.txt and all new parts with lightweight deletes would have it

As for ability to downgrade to older version

it's not only ability to downgrade though - the question is how old version would behave having new parts replicated from new version. Probably this question is the same with ability to downgrade - i.e. how old version behaves having new parts.

Overall I think we can proceed with your plan (maybe (1) is not necessary), but we definitely should investigate all these concerns.

@jewelzqiu jewelzqiu changed the title Add existing_count.txt & Consider deleted rows when selecting parts to merge Consider lightweight deleted rows when selecting parts to merge Jan 18, 2024
@jewelzqiu
Copy link
Contributor Author

  1. for existing parts, calculate on parts loading
  2. during _row_exists related mutation, calculate while writing new parts
  3. for other mutations, copy existing_rows_count from source part
  4. for merged or inserted part, existing_rows_count equals rows_count

@yakov-olkhovskiy I have implemented such method with a setting for step 1

Copy link
Member

@yakov-olkhovskiy yakov-olkhovskiy left a comment

Choose a reason for hiding this comment

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

I'm not sure how effective this solution will be without existing_rows_count in metadata...

src/Storages/MergeTree/IMergeTreeDataPart.h Outdated Show resolved Hide resolved
@yakov-olkhovskiy
Copy link
Member

@jewelzqiu I'm leaving for vacation for a week - let's continue when I'm back. Overall I think the usefulness if this without metadata will be quite limited...

@jewelzqiu
Copy link
Contributor Author

Overall I think the usefulness if this without metadata will be quite limited...

@yakov-olkhovskiy well, it is useful if load_existing_rows_count_for_old_parts enabled though.
To maintain backward compatibility, it is safer to disable it by default and enable it on demand

@yakov-olkhovskiy
Copy link
Member

@jewelzqiu I'm not sure on perspectives of enabling this by default though - it will slow down startup. I will discuss it tomorrow with the team... the PR itself looks good - I'll go through it one more time if we will decide to merge it...

@yakov-olkhovskiy
Copy link
Member

@tavplubix we abandoned the idea to have it in metadata - now it only calculates on a fly - do you still have any suspicions this feature could not work with SharedMergeTree?

@tavplubix tavplubix marked this pull request as draft February 28, 2024 23:10
@jewelzqiu jewelzqiu marked this pull request as ready for review February 29, 2024 01:56
@jewelzqiu jewelzqiu force-pushed the existing-count branch 2 times, most recently from 94c5846 to f1b37b6 Compare March 1, 2024 05:59
jewelzqiu and others added 3 commits March 12, 2024 13:07
@jewelzqiu
Copy link
Contributor Author

@yakov-olkhovskiy Any update? I have rebased on to latest master several days ago

@yakov-olkhovskiy yakov-olkhovskiy merged commit a31f551 into ClickHouse:master Mar 15, 2024
224 of 233 checks passed
@yakov-olkhovskiy
Copy link
Member

@jewelzqiu I merged it but maybe you would like to make an additional PR documenting this feature so ppl can use it...

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 15, 2024
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-improvement Pull request with some product 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.

Merge issue about large data part with lightweight delete
6 participants