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

Fix loading of partially dropped table #8176

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions dbms/src/Databases/DatabaseOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1
2
3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attach table should_be_dropped (n UInt8) engine = File(CSV)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attach table should_be_restored (n UInt8) engine = File(CSV)
8 changes: 8 additions & 0 deletions dbms/tests/integration/test_server_initialization/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"