Skip to content

Randomization of tests with DETACH/ATTACH table - #42336

Closed
CurtizJ wants to merge 7 commits into
ClickHouse:masterfrom
CurtizJ:randomize-detach-attach
Closed

CurtizJ wants to merge 7 commits into
ClickHouse:masterfrom
CurtizJ:randomize-detach-attach

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Oct 15, 2022

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Randomly execute DETACH/ATTACH queries for all tables that are used in query from test before its execution.

@robot-clickhouse robot-clickhouse added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 15, 2022
@CurtizJ
CurtizJ force-pushed the randomize-detach-attach branch from fd71ed5 to 0db7bb1 Compare October 15, 2022 20:33
@@ -1,3 +1,7 @@
-- Tags: no-random-detach
-- Tag no-random-detach: flag is_frozen is not persisted.

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.

@@ -1,4 +1,5 @@
-- Tags: no-parallel
-- Tags: no-parallel, no-random-detach
-- Tag no-random-detach: it's a bug, will be fixed in https://github.com/ClickHouse/ClickHouse/pull/41145

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.

The bug is that after TRUNCATE or DROP PARTITION a new part with the same name (and path) may appear, but marks/uncompressed cache is not dropped, which leads to reading of wrong data. Most likely will be fixed after #41145.

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.

Is it?

# Tags: replica, no-replicated-database, no-parallel
# Tags: replica, no-replicated-database, no-randon-detach
# Tag no-replicated-database: Fails due to additional replicas or shards
# Tag no-random-detach: it's a bug, will be fixed in https://github.com/ClickHouse/ClickHouse/pull/42509

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.

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.

This one should be fixed in #44628

-- Tags: zookeeper, no-random-detach
-- Tag no-random-detach: "The local set of parts of table
-- doesn't look like the set of parts in ZooKeeper"
-- after DROP PARTITION and restart https://github.com/ClickHouse/ClickHouse/issues/37664

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.

@alexey-milovidov

Copy link
Copy Markdown
Member

What a nice feature!

@alexey-milovidov

Copy link
Copy Markdown
Member

We need this!

@CurtizJ CurtizJ closed this Oct 23, 2023
alexey-milovidov added a commit that referenced this pull request Feb 5, 2026
Add `reattach_tables_before_query_execution` and
`reattach_tables_before_query_execution_probability` settings that
enable randomly detaching and reattaching tables used in a query
before its execution.

This is a testing-only feature designed to find bugs related to
table reattachment. Before executing a query, the system collects
all tables referenced in the AST, and for each eligible table
(stores data on disk, supports detaching, has no action locks or
dependencies), it performs a DETACH followed by ATTACH.

Changes:
- Add `supportsDetachingTables` virtual method to `IDatabase`
  (returns false for `DatabaseDictionary`, `DatabaseReplicated`,
  `DatabaseSQLite`)
- Add `has`/`hasAny` methods to `ActionLocksManager` for checking
  existing locks
- Add table collection visitor and reattach logic in `executeQuery`
- Fix off-by-one in `MergeTreeDeduplicationLog::dropOutdatedLogs`
  and add `sync` call in shutdown
- Add `no-random-detach` tag to tests incompatible with this feature
- Add `--no-random-detach` and `--reattach-tables-probability`
  options to `clickhouse-test`
- Add `02461_reattach_tables` test

Continuation of #42336

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

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants