Skip to content

DatabaseCatalog drops tables faster - #66065

Merged
CheSema merged 13 commits into
masterfrom
chesema-faster-drop
Jul 10, 2024
Merged

CheSema merged 13 commits into
masterfrom
chesema-faster-drop

Conversation

@CheSema

@CheSema CheSema commented Jul 3, 2024 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

DatabaseCatalog drops tables faster by using up to database_catalog_drop_table_concurrency threads

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

@robot-ch-test-poll robot-ch-test-poll added the pr-improvement Pull request with some product improvements label Jul 3, 2024
@robot-ch-test-poll

robot-ch-test-poll commented Jul 3, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit bde1d2f 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
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. 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
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
Stateful testsRuns stateful 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

@tavplubix tavplubix self-assigned this Jul 4, 2024
@CheSema
CheSema force-pushed the chesema-faster-drop branch from 9561d30 to 3a87479 Compare July 6, 2024 14:06
@CheSema
CheSema marked this pull request as ready for review July 8, 2024 13:57
@CheSema
CheSema marked this pull request as draft July 8, 2024 15:42
@CheSema
CheSema marked this pull request as ready for review July 8, 2024 19:16
@CheSema
CheSema requested a review from tavplubix July 9, 2024 10:54
@CheSema

CheSema commented Jul 9, 2024

Copy link
Copy Markdown
Member Author

Stress tests (tsan) -- fatal as here #64945

Stateless tests (release) --
00992_system_parts_race_condition_zookeeper_long #57418
03144_parallel_alter_add_drop_column_zookeeper_on_steroids -- flaks in master

Stress test (debug)
some distributed query from 00159_parallel_formatting_http.sh hanged.

Stateless Tests (tsan)
00002_log_and_exception_messages_formatting -- noise from Have {} tables in queue to drop. Some of them are being dropped in sync mode. Schedule background task ASAP

Comment on lines +1255 to +1260
for (auto it = tables_marked_dropped.begin(); it != tables_marked_dropped.end(); ++it)
{
try
{
dropTableFinally(table);
std::lock_guard lock(tables_marked_dropped_mutex);
[[maybe_unused]] auto removed = tables_marked_dropped_ids.erase(table.table_id.uuid);
assert(removed);
}
catch (...)
bool in_use = it->table && !it->table.unique();
bool old_enough = it->drop_time <= current_time;
if (!in_use && old_enough)
result.emplace_back(it);

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.

Does it make sense to calculate the number of tables in use and min drop time while iterating through tables here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could, but I was a big confused that we did all that in one iteration like it has a big sense.
I broke it into several iterations to make sure that there is no need to do it on that way.
First iteration -- just take numbers for INFO level logging. That logs are important.
Second iteration -- collect what to drop.
Third iteration -- seeing actual data after collected tables are dropped we decide when it has to be rescheduled.

Comment thread src/Interpreters/DatabaseCatalog.cpp Resolved
@CheSema

CheSema commented Jul 10, 2024 •

Copy link
Copy Markdown
Member Author

@CheSema

CheSema commented Jul 10, 2024

Copy link
Copy Markdown
Member Author

Stateless Tests (debug, S3 Storage) -- Logical error: 'Inconsistent AST formatting
#62975

Stateless Tests (debug) [2/2] -- there no expected logs, strange

@CheSema
CheSema enabled auto-merge July 10, 2024 17:01
@CheSema
CheSema disabled auto-merge July 10, 2024 17:01
@CheSema
CheSema added this pull request to the merge queue Jul 10, 2024
Merged via the queue into master with commit be80f4e Jul 10, 2024
@CheSema
CheSema deleted the chesema-faster-drop branch July 10, 2024 17:37
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 10, 2024
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created-cloud deprecated label, NOOP label Jul 15, 2024
@azat

azat commented Mar 8, 2025

Copy link
Copy Markdown
Member

This approach does not allows to scale DROP queries properly, it can only remove tables concurrently if the were lucky and end up in one batch

azat added a commit to azat/ClickHouse that referenced this pull request Mar 8, 2025
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @CheSema @tavplubix — while reviewing this PR I found the following:

Happy to discuss — close anything that's wrong or already addressed.

@clickgapai

Copy link
Copy Markdown
Contributor

Update on the earlier review: CI on the proof PR #104904 confirmed the suspected bug via Stateless tests (arm_binary, sequential). Filed as a separate Issue so it isn't lost when the proof PR closes:

(Automated follow-up. The proof PR has been closed; please track the bug on the Issue.)

azat added a commit to azat/ClickHouse that referenced this pull request May 18, 2026
`getTablesToDrop` returned iterators into `tables_marked_dropped`
under the mutex, but the mutex was released before
`dropTablesParallel` consumed them, so a concurrent `undropTable`
could erase entries and leave the drop jobs holding dangling
iterators — see ClickHouse#66065.

`getTablesToDrop` now splices eligible entries out of
`tables_marked_dropped` under the mutex and returns the private
list by value; in-flight tables are invisible to `undropTable`.
`dropTablesParallel` owns the list, never mutates it (moved-from
entries die with the list), and on failure moves the entry back
into `tables_marked_dropped` via `emplace_back` — splicing back
would race with the main loop iterating `tables_to_drop`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created-cloud deprecated label, NOOP 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.

6 participants