From 9b8fc9a899ee3a681264d7821054903d4d23d4a5 Mon Sep 17 00:00:00 2001 From: Alexander Burmak Date: Fri, 1 Nov 2019 16:08:56 +0300 Subject: [PATCH] Fixed missing file name escaping in FREEZE command --- dbms/src/Storages/MergeTree/MergeTreeData.cpp | 6 +++- .../test_filesystem_layout/__init__.py | 0 .../test_filesystem_layout/test.py | 28 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/integration/test_filesystem_layout/__init__.py create mode 100644 dbms/tests/integration/test_filesystem_layout/test.py diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index b7408634e3f..610d68d1942 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -3355,7 +3355,11 @@ void MergeTreeData::freezePartitionsByMatcher(MatcherFn matcher, const String & LOG_DEBUG(log, "Freezing part " << part->name << " snapshot will be placed at " + backup_path); String part_absolute_path = Poco::Path(part->getFullPath()).absolute().toString(); - String backup_part_absolute_path = backup_path + "data/" + getDatabaseName() + "/" + getTableName() + "/" + part->relative_path; + String backup_part_absolute_path = backup_path + + "data/" + + escapeForFileName(getDatabaseName()) + "/" + + escapeForFileName(getTableName()) + "/" + + part->relative_path; localBackup(part_absolute_path, backup_part_absolute_path); part->is_frozen.store(true, std::memory_order_relaxed); ++parts_processed; diff --git a/dbms/tests/integration/test_filesystem_layout/__init__.py b/dbms/tests/integration/test_filesystem_layout/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/integration/test_filesystem_layout/test.py b/dbms/tests/integration/test_filesystem_layout/test.py new file mode 100644 index 00000000000..6dc4e5f8763 --- /dev/null +++ b/dbms/tests/integration/test_filesystem_layout/test.py @@ -0,0 +1,28 @@ +import pytest + +from helpers.cluster import ClickHouseCluster + +cluster = ClickHouseCluster(__file__) +node = cluster.add_instance("node") + + +@pytest.fixture(scope="module") +def started_cluster(): + try: + cluster.start() + yield cluster + finally: + cluster.shutdown() + + +def test_file_path_escaping(started_cluster): + node.query(''' + CREATE TABLE test.`T.a_b,l-e!` (`~Id` UInt32) + ENGINE = MergeTree() PARTITION BY `~Id` ORDER BY `~Id`; + ''') + node.query('''INSERT INTO test.`T.a_b,l-e!` VALUES (1);''') + node.query('''ALTER TABLE test.`T.a_b,l-e!` FREEZE;''') + + node.exec_in_container(["bash", "-c", "test -f /var/lib/clickhouse/data/test/T%2Ea_b%2Cl%2De%21/1_1_1_0/%7EId.bin"]) + node.exec_in_container(["bash", "-c", "test -f /var/lib/clickhouse/shadow/1/data/test/T%2Ea_b%2Cl%2De%21/1_1_1_0/%7EId.bin"]) +