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

Bugfix: order parts after backup for ReplacingMergeTree #191

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ch_backup/backup/metadata/table_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from ch_backup.backup.metadata.part_metadata import PartMetadata

REPLACING_MERGE_TREE = "ReplacingMergeTree"


class TableMetadata(SimpleNamespace):
"""
Expand Down Expand Up @@ -53,6 +55,24 @@ def get_parts(self, *, excluded_parts: Set[str] = None) -> List[PartMetadata]:
PartMetadata.load(self.database, self.name, part_name, raw_metadata)
)

if self.engine == REPLACING_MERGE_TREE:
k-morozov marked this conversation as resolved.
Show resolved Hide resolved

def split_part_name(part):
chunks = part.split("_", maxsplit=3)
k-morozov marked this conversation as resolved.
Show resolved Hide resolved
partition = ""
suffix = ""
try:
partition = chunks[0]
start_range = int(chunks[1])
finish_range = int(chunks[2])
suffix = chunks[3]
except (IndexError, ValueError):
start_range = 0
finish_range = 0
return partition, start_range, finish_range, suffix
k-morozov marked this conversation as resolved.
Show resolved Hide resolved

result.sort(key=lambda part: split_part_name(part.name))
k-morozov marked this conversation as resolved.
Show resolved Hide resolved

return result

def add_part(self, part: PartMetadata) -> None:
Expand Down
100 changes: 100 additions & 0 deletions tests/integration/features/backup_restore.feature
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,106 @@ Feature: Backup & Restore
And we restore clickhouse backup #0 to clickhouse02
Then we got same clickhouse data at clickhouse01 clickhouse02

Scenario: Backup & Restore for ReplacingMergeTree
When we drop all databases at clickhouse01
And we drop all databases at clickhouse02
Given we have executed queries on clickhouse01
"""
CREATE DATABASE test_db;
CREATE TABLE test_db.hits (
dt DateTime,
id UInt32,
url String,
visits UInt32
)
ENGINE ReplacingMergeTree
ORDER BY (dt, id)
PARTITION BY toYYYYMM(dt);

INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 100);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 101);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 102);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 103);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 104);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 105);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 106);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 107);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 108);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 109);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 110);
"""
Given we have executed queries on clickhouse01
"""
INSERT INTO test_db.hits VALUES
(now(), 1, '/index', 111);
"""
When we create clickhouse01 clickhouse backup
And we restore clickhouse backup #0 to clickhouse02
When we execute query on clickhouse01
"""
SELECT id, visits FROM test_db.hits FINAL ORDER BY id FORMAT Vertical;
"""
Then we get response
"""
Row 1:
──────
id: 1
visits: 111
"""
When we execute query on clickhouse02
"""
SELECT id, visits FROM test_db.hits FINAL ORDER BY id FORMAT Vertical;
"""
Then we get response
"""
Row 1:
──────
id: 1
visits: 111
"""
Then we got same clickhouse data at clickhouse01 clickhouse02

Scenario: Backup & Restore with long file names
When we drop all databases at clickhouse01
And we drop all databases at clickhouse02
Expand Down