Merge pull request #8176 from ClickHouse/fix_tmp_drop_relative_path

Fix loading of partially dropped table
This commit is contained in:
alexey-milovidov 2019-12-13 02:28:13 +03:00 committed by GitHub
commit efb916c556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 2 deletions

View File

@ -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
{

View File

@ -0,0 +1 @@
attach table should_be_dropped (n UInt8) engine = File(CSV)

View File

@ -0,0 +1 @@
attach table should_be_restored (n UInt8) engine = File(CSV)

View File

@ -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"