From 1a6c973055698ac06da5660eede36530809e95f0 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Thu, 12 Dec 2019 17:47:31 +0300 Subject: [PATCH] use absolute path and try to load table --- dbms/src/Databases/DatabaseOnDisk.cpp | 6 ++++-- .../data/default/should_be_restored/data.CSV | 3 +++ .../metadata/default/should_be_dropped.sql.tmp_drop | 1 + .../metadata/default/should_be_restored.sql.tmp_drop | 1 + dbms/tests/integration/test_server_initialization/test.py | 8 ++++++++ 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 dbms/tests/integration/test_server_initialization/clickhouse_path/data/default/should_be_restored/data.CSV create mode 100644 dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_dropped.sql.tmp_drop create mode 100644 dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_restored.sql.tmp_drop diff --git a/dbms/src/Databases/DatabaseOnDisk.cpp b/dbms/src/Databases/DatabaseOnDisk.cpp index 03119743a86..a1c1512cd91 100644 --- a/dbms/src/Databases/DatabaseOnDisk.cpp +++ b/dbms/src/Databases/DatabaseOnDisk.cpp @@ -507,8 +507,10 @@ void DatabaseOnDisk::iterateMetadataFiles(const IDatabase & database, Poco::Logg const std::string object_name = dir_it.name().substr(0, dir_it.name().size() - strlen(tmp_drop_ext)); if (Poco::File(database.getDataPath() + '/' + object_name).exists()) { - Poco::File(dir_it->path()).renameTo(object_name + ".sql"); - LOG_WARNING(log, "Object " << backQuote(object_name) << " was not dropped previously"); + /// TODO maybe complete table drop and remove all table data (including data on other volumes and metadata in ZK) + Poco::File(dir_it->path()).renameTo(database.getMetadataPath() + object_name + ".sql"); + LOG_WARNING(log, "Object " << backQuote(object_name) << " was not dropped previously and will be restored"); + iterating_function(object_name + ".sql"); } else { diff --git a/dbms/tests/integration/test_server_initialization/clickhouse_path/data/default/should_be_restored/data.CSV b/dbms/tests/integration/test_server_initialization/clickhouse_path/data/default/should_be_restored/data.CSV new file mode 100644 index 00000000000..01e79c32a8c --- /dev/null +++ b/dbms/tests/integration/test_server_initialization/clickhouse_path/data/default/should_be_restored/data.CSV @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_dropped.sql.tmp_drop b/dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_dropped.sql.tmp_drop new file mode 100644 index 00000000000..d6e1364dc3e --- /dev/null +++ b/dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_dropped.sql.tmp_drop @@ -0,0 +1 @@ +attach table should_be_dropped (n UInt8) engine = File(CSV) diff --git a/dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_restored.sql.tmp_drop b/dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_restored.sql.tmp_drop new file mode 100644 index 00000000000..0452819cac0 --- /dev/null +++ b/dbms/tests/integration/test_server_initialization/clickhouse_path/metadata/default/should_be_restored.sql.tmp_drop @@ -0,0 +1 @@ +attach table should_be_restored (n UInt8) engine = File(CSV) diff --git a/dbms/tests/integration/test_server_initialization/test.py b/dbms/tests/integration/test_server_initialization/test.py index 212037b0c93..64ed3181118 100644 --- a/dbms/tests/integration/test_server_initialization/test.py +++ b/dbms/tests/integration/test_server_initialization/test.py @@ -26,3 +26,11 @@ def test_sophisticated_default(started_cluster): instance.query("INSERT INTO sophisticated_default (c) VALUES (0)") assert instance.query("SELECT a, b, c FROM sophisticated_default") == "3\t9\t0\n" + +def test_partially_dropped_tables(started_cluster): + instance = started_cluster.instances['dummy'] + assert instance.exec_in_container(['bash', '-c', 'cd / && find -name *.sql* | sort'], privileged=True, user='root') \ + == "./var/lib/clickhouse/metadata/default/should_be_restored.sql\n" \ + "./var/lib/clickhouse/metadata/default/sophisticated_default.sql\n" + assert instance.query("SELECT n FROM should_be_restored") == "1\n2\n3\n" + assert instance.query("SELECT count() FROM system.tables WHERE name='should_be_dropped'") == "0\n"