forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 18
Antalya-26.3: Resolve currentDatabase() in Hybrid segment metadata #1995
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
Open
mkmkme
wants to merge
4
commits into
antalya-26.3
Choose a base branch
from
mkmkme/antalya-26.3/hybrid-restart
base: antalya-26.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7ba1a9d
Resolve currentDatabase() in Hybrid segment metadata
mkmkme 081738e
reduce code duplication, fix the original call instead
mkmkme 03fb9e9
replace integration test with a stateless one
mkmkme 1037c7d
fix 03645_hybrid_watermarks after the changes
mkmkme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import pytest | ||
|
|
||
| from helpers.cluster import ClickHouseCluster | ||
|
|
||
| cluster = ClickHouseCluster(__file__) | ||
| node = cluster.add_instance("node", stay_alive=True) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def start_cluster(): | ||
| try: | ||
| cluster.start() | ||
| yield cluster | ||
| finally: | ||
| cluster.shutdown() | ||
|
|
||
|
|
||
| def test_current_database_survives_restart(start_cluster): | ||
| """A Hybrid table created in a non-default database with currentDatabase() in a | ||
| segment must survive a server restart. | ||
|
|
||
| currentDatabase() has to be resolved to the actual database name and stored in | ||
| the table metadata at CREATE time. Otherwise the unresolved currentDatabase() | ||
| token is replayed during startup ATTACH, where there is no session database, so | ||
| it resolves to `default` and the segment points at the missing default.local_cold, | ||
| failing to attach with UNKNOWN_TABLE. | ||
| """ | ||
| settings = {"allow_experimental_hybrid_table": 1} | ||
|
|
||
| node.query("CREATE DATABASE IF NOT EXISTS test_db") | ||
| node.query( | ||
| "CREATE TABLE test_db.local_hot (ts DateTime, value UInt64) ENGINE = MergeTree ORDER BY ts" | ||
| ) | ||
| node.query( | ||
| "CREATE TABLE test_db.local_cold (ts DateTime, value UInt64) ENGINE = MergeTree ORDER BY ts" | ||
| ) | ||
| node.query( | ||
| "INSERT INTO test_db.local_hot VALUES ('2025-10-15', 1), ('2025-11-01', 2)" | ||
| ) | ||
| node.query( | ||
| "INSERT INTO test_db.local_cold VALUES ('2025-08-01', 3), ('2025-06-15', 4)" | ||
| ) | ||
|
|
||
| # Run with test_db as the session database so currentDatabase() resolves to it. | ||
| node.query( | ||
| """ | ||
| CREATE TABLE test_db.hybrid_t (ts DateTime, value UInt64) | ||
| ENGINE = Hybrid( | ||
| remote('localhost:9000', 'test_db', 'local_hot'), | ||
| ts > hybridParam('hybrid_watermark_hot', 'DateTime'), | ||
| remote('localhost:9000', currentDatabase(), 'local_cold'), | ||
| ts <= hybridParam('hybrid_watermark_hot', 'DateTime') | ||
| ) | ||
| SETTINGS hybrid_watermark_hot = '2025-09-01' | ||
| """, | ||
| database="test_db", | ||
| settings=settings, | ||
| ) | ||
|
|
||
| # Sanity: the table works before the restart, so any post-restart failure is | ||
| # attributable to metadata persistence, not to the table definition itself. | ||
| assert node.query("SELECT count() FROM test_db.hybrid_t", settings=settings).strip() == "4" | ||
|
|
||
| node.restart_clickhouse(kill=True) | ||
|
mkmkme marked this conversation as resolved.
Outdated
|
||
|
|
||
| # On the buggy build the stored metadata still contains currentDatabase(), which | ||
| # resolves to `default` during startup ATTACH, so this query fails with UNKNOWN_TABLE. | ||
| assert node.query("SELECT count() FROM test_db.hybrid_t", settings=settings).strip() == "4" | ||
|
|
||
| # The persisted definition must store the resolved database name, not the | ||
| # unresolved currentDatabase() token. | ||
| show = node.query("SHOW CREATE TABLE test_db.hybrid_t", settings=settings) | ||
| assert "currentDatabase()" not in show | ||
| assert "test_db" in show | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.